-->rand('normal')
-->rand('seed',0)
-->xnoised = x + 2*rand(x);
We can represent both signals (original and noised) at the same scale with the next code
-->xsetech([0,0,1,1/2],[0,-10,1,10]); -->plot2d([0:99]*inct, x(1:100),1,'001'); -->xsetech([0,1/2,1,1/2],[0,-10,1,10]); -->plot2d([0:99]*inct, xnoised(1:100),1,'001');Notice that we represent the first 100 values (one second) Now we are going to calculate the Fourier Transform of three periods of 100 values
-->x1 = xnoised(1:100); -->ffx1 = fft(x1,-1); -->x2 = xnoised(101:200); -->ffx2 = fft(x2,-1); -->x3 = xnoised(201:300); -->ffx3 = fft(x3,-1);At this moment we have three different arrays and we could average them. The result is shown in the upper trace of the next figure but we have a command that calculates the average of the power of several windows on the signal
-->Pxx = pspect(50,100,'re',xnoised);With this command, we are saying that `xnoise' was divided in windows of 100 values and that the power spectrum be calculated. Finally the different spectra are averaged. We can apply different windows (rectangular, hamming...).
Notice that we can overlap the different windows by using the first parameter. The result can be seen with the next code
-->xbasc() -->xsetech([0,0,1,1/2]) -->fr = [0:99]*(1/ (100*inct)); -->plot2d(fr,(abs(ffx1)^2 /100),1); -->plot2d(fr,(abs(ffx2)^2 /100),1,'001'); -->plot2d(fr,(abs(ffx3)^2 /100),1,'001'); -->xsetech([0,1/2,1,1/2]) -->plot2d(fr,Pxx)The result can be seen in the next figure
![]() |