Pregunta

I have a function and i want to plot FFT base on frequency Domain.

t=0:0.01:60;

y = sin(2*pi*0.33*t)+sin(2*pi*0.23*t)+sin(2*pi*0.1*t);

As you can see, the peak should be on 0.1,0.2,0.33 frequencies, but when i try to plot it the peaks aren't at these point.

I tried FFT,DFT, but none of them worked as I wanted. Also, I want their FFT peaks be equal to 1 at these frequencies.

Any thoughts?

¿Fue útil?

Solución

If Fs is sample rate (hear 100 Hz) then the frequency bins are at length(t)/Fs Hz. Since you want your bins spaced 100 Hz apart, you need a longer signal. Try this

Fs=100; %sample rate
t=0:1/Fs:(100-1/Fs);  %10,000 samples long
F=[0:length(t)-1]/length(t)*Fs; %where the bins are
y = sin(2*pi*0.33*t)+sin(2*pi*0.23*t)+sin(2*pi*0.1*t); 
Y=abs(fft(y))/(length(y)/2);  %normalize by the signal length
figure(1);
plot(F,Y)
xlim([0 1]); %zoom in to the part of interest
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top