Thursday, November 5, 2009

More frequencies in FFT

Hi Transmogrifox, thank you very much for your help. We have this blog to interact and to help ourselves.

The Transmogrifox's code is given following:


//Frequency components of a signal
//----------------------------------
// build a noides signal sampled at 1000hz containing to pure frequencies
// at 50 and 70 Hz
sample_rate=1000;
t = 0:1/sample_rate:0.6;
N=size(t,'*'); //number of samples
s=sin(2*%pi*50*t)+ 0.3*sin(2*%pi*70*t+%pi/4)+ 0.2*grand(1,N,'nor',0,1);

y=fft(s);
//the fft response is symetric we retain only the first N/2 points
f=sample_rate*(0:(N/2))/N; //associated frequency vector
n=size(f,'*')
yy = y*2/N;
clf()
plot2d(f,abs(yy(1:n)))


And the following picture is the result.



So, if anyone has any question, I think I and Transmogrifox are ready for help.