how to get "fft" of sin wave?

2 visualizaciones (últimos 30 días)
ADNAN KIRAL
ADNAN KIRAL el 24 de Jun. de 2019
Comentada: Star Strider el 25 de Jun. de 2019
hi
I have the following code for "fft" but I could not get the exactly frequency-amplitude response. where did I make a mistake ? can u please help me with that?
I want to get this figure; amplitude 2.5 and frequency 4Hz.
Capture.PNG
final_point=3;
time=1:0.01:final_point;
omega=2*pi*4;
y1=2.5*sin(omega*time);
% %FFT
acc_inpt=y1;
n_fft=length(acc_inpt);
ff=fft(acc_inpt,n_fft);
num_points=n_fft;
ff=ff/(num_points/2);
figure;
plot(abs(ff))

Respuesta aceptada

Star Strider
Star Strider el 24 de Jun. de 2019
The amplitude appears to be correct. You need to define the frequency axis to get the frequencies to be correct:
final_point=3;
time=1:0.01:final_point;
omega=2*pi*4;
y1=2.5*sin(omega*time);
% %FFT
Fs = 1/mean(diff(time)); % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
Fv = linspace(0, 1, numel(y1)/2+1)*Fn; % Frequency Vector
Iv = 1:numel(Fv); % Index Vector
acc_inpt=y1;
n_fft=length(acc_inpt);
ff=fft(acc_inpt,n_fft);
num_points=n_fft;
ff=ff/(num_points/2);
figure;
plot(Fv, abs(ff(Iv)))
That plots the peak at 4 cycles/time unit, that appears to be what you want to do.
  8 comentarios
ADNAN KIRAL
ADNAN KIRAL el 25 de Jun. de 2019
many thanks. appriciate that. @ Star Strider
Star Strider
Star Strider el 25 de Jun. de 2019
As always, my pleasure.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Spectral Measurements en Help Center y File Exchange.

Productos


Versión

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by