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.
2 comments:
Hi, it has been really useful, thanks. But there' s a line I don't understand:
yy = y*2/N;
Would you explain it please?
Hi Mc008, how are you?
The line:
yy = y*2/N;
makes a normalization of 'y' and attributes the result to 'yy'.
If you use the value of 'y' directly, the FFT's amplitude would be N/2 times greater than the normal, but if you see the picture, the result showed has the picks exactly to 1 in frequency of 50 and 0,3 in frequency of 70.
I hope to have helped.
Post a Comment