Need help for averaging FFT of segment

Status
Not open for further replies.

agus_nugroho01

Newbie level 3
Joined
Jun 3, 2010
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Malaysia
Activity points
1,326
Dear All,

I would like to ask you in such problem that i am facing now, since i am still beginner in the Matlab programming. Currently, I have signal with length of 1000 sample and I would like to devide it to be 10 segments so each of them will have 100 sample. For each segment I would like to implement FFT and windowed function. And finally, I want to calculate the average FFT for these 10 segments.

I have FFT program but it i is used for calculating for FFT of 1000 samples. I have tried to use "for" function but it seems useless for me. Would you help me by correcting my sample signal below to fulfill my objective? Thank you in advance

----------------------------------------------------------------------------------------
Fs=100;
Ts=1/Fs;
t=0:Ts:1000-Ts;
n=length(t);
y=2*sin(2*pi*0.5*t)+5*sin(2*pi*0.2*t)+10*sin(2*pi*0.1*t)+20*sin(2*pi*0.05*t);
figure(1)
plot(t,y)

windowHann=window(@hann,n).';
hannWindowFigure=figure;
plot(windowHann);

windowedSignal=windowHann.*y;
windowedSignalPlot=figure;
plot(t,windowedSignal)

[Yk,k]=positiveFFT(windowedSignal,Fs);
Yk=Yk*2;
fftWindowedSignalLinear=figure;
stem(k,2*abs(Yk));

xlabel('Spatial frequency (m-1)')
ylabel('|Y(k)|')

------------------------------------------------------------

Positive FFT is function with
function[YfreqD,freqRng]=positiveFFT(y,Fs)
N=length;
k=0:N-1;
T=N/Fs;
freqRng=k/T;
YfreqD=fft/N;
cutOff=ceil(N/2);
YfreqD=YfreqD(1:cutOff);
freqRng=freqRng(1:cutOff);
 

I do not know what your "positiveFFT" is and a few other variables. At any rate, here is a simple code that calculates the average FFT. I do not have matlab with me, so you might have to tweak it a little bit:
Code:
Y_average=zeros(1,n);
w=sum(windowHann);
for m=0:9
    Y=fft(x(1+m*n:n+m*n).*windowHann)*(2/w);
    Y_average=Y_average+Y.*conj(Y);
end
fftWindowedSignalLinear=figure;
stem(abs(Y_average));
 

Hello Joannes,

Many thanks for your reply. I have tried to input your code such as below :
-----------------------------------

Fs=100;
Ts=1/Fs;
t=0:Ts:1000-Ts;
n=length(t);
y=2*sin(2*pi*0.5*t)+5*sin(2*pi*0.2*t)+10*sin(2*pi*0.1*t)+20*sin(2*pi*0.05*t);
figure(1)
plot(t,y)

windowHann=window(@hann,n).';
hannWindowFigure=figure;
plot(windowHann);

Y_average=zeros(1,n);
w=sum(windowHann);
for m=0:9
Y=fft(y(1+m*n:n+m*n).*windowHann)*(2/w);
Y_average=Y_average+Y.*conj(Y);
end
fftWindowedSignalLinear=figure;
stem(abs(Y_average));
------------------------------------------------

However there is an eror notified :

"??? Index exceeds matrix dimensions.

Error in ==> FFT10segment at 17
Y=fft(y(1+m*n:n+m*n).*windowHann)*(2/w);

I also had correct the meaning of Postive FFT. And actually i am intended to windowing my signal for each segment before i am performed FFT. Any further help will be highly appreciated . Thank you so much.
 

mmm... if you read the code you will notice that n should be divided by the number of averages you want to take, in this case n=n/10;
 

Dear Dr Joannes,
I am sorry, I tried to configure the new logarithms ,,but it seems not working. If you dont mind, May you see it what was the mistake that I have done..
--------------
fo=5;
Fs=100;
Ts=1/Fs;
t=0:Ts:0.9-Ts;
N=length(t);
y=2*sin(2*pi*fo*t);

Nseg= 10; %Number of segments
n=floor(N/Nseg); %Nu. of samples per segment

Y_average=zeros(1,n);
for I=1:Nseg %number of segment
w=hann;
y1=y(1:n,I); %signal from segment 1 until segment 10
windowedSignal=(w(1:n,I).*y1; %windowoded signal for each segment

Y=fft(windowedSignal,n); %fft for each signal segment
end
%averages FFT
Y_average=Y_average+Y.*conj(Y);
stem(abs(Y_average));
------------------------

thnak you very much
 

What a mess... here is the code. Again I did not test it...
Code:
Fs=100; 
Ts=1/Fs; 
M=10;
t=0:Ts:1000-Ts; 
n=length(t); 
n=floor(n/M);
y=2*sin(2*pi*0.5*t)+5*sin(2*pi*0.2*t)+10*sin(2*pi*0.1*t)+20*sin(2*pi*0.05*t); 
figure(1) 
plot(t,y) 

windowHann=window(@hann,n).'; 
hannWindowFigure=figure; 
plot(windowHann); 

Y_average=zeros(1,n); 
w=sum(windowHann); 
for m=0:M-1 
Y=fft(y(1+m*n:n+m*n).*windowHann)*(2/w); 
Y_average=Y_average+Y.*conj(Y); 
end 
Y_average=fftshift(Y_average);
fftWindowedSignalLinear=figure; 
stem(abs(Y_average)/M);
Please look up the fftshift function to understand what it does...
 

Dear Dr Joannes.

Yes I have modify and it is fit with my calculation right now. You are so much helpful.

Thank you so much for your kindness.

Best regards,

Agus
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…