problem in Hanning window with FFT

where is the error in my program, why I don't get the amplitude is not 4 .
fs=300;
N=3000;
t = (1:N)/fs; % Time vector
x = 4*cos(2*pi*100*t);
% FFT
fn=hanning(N); %fenetre de hanning
ft=abs(fft(x'.*fn));%fft
plot(ft);

 Accepted Answer

Here are few things: Your plot shows the amplitude of Fourier transform, not the original signal. So, the amplitude may not be 4 (amplitude of the signal). Indeed, the amplitude of fft is determined so that the power of the signal remains same before and after the transform. Lets say, Y = x'.*fn
Y = x'.*fn;
Power_Y = sum(Y.^2) % power in time domain
fftY = fft(Y);
Power_fftY = sum(fftY.*conj(fftY))/length(fftY) % power in frequency domain
The amplitude after transformation is set so that Power_Y = Power_fftY
To get the amplitude back, use ifft that is shown in subplot(313) below. Compare these three plots:
subplot(311), plot(Y); % original signal
subplot(312), plot(abs(fftY)); % fft
subplot(313), plot(ifft(fftY)); % ifft

13 Comments

thank you a lot for the answer; so we can't see the amplitude of the signal in the FFT?; in normal FFT without hannig ;I used this amplitude=abs(fft(x)/length(fft(x))*2;But in this case it not work
I would use:
amplitude=max(ifft(fft(x)))
This will give the amplitude of x.
thank you a lot again ; yes I get amplitude =4; please tell me how to use this in the FFT ; I want to do a correct code for FFT with hanning window
Could you please see the doc for fft? You can use this function in various ways, and purposes. So, please read the doc first, and lets discuss the specific question on it, if you may have.
It will also be very helpful if you do have a decent knowledge about Fourier series and transform, if not, at least the basics.
yes I have read the FFT doc and a have a knowledge about Fourier series and transform
this is the program for simple FFT
fs=300;
N=3000;
t = (1:N)/fs; % Time vector
x = 4*cos(2*pi*100*t);
%========================== FFT ================================
fs=300;
X=fft(x); %FFT
df=fs/length(X) %frequency resolution
f=(0:1:length(X)/2)*df; %frequency axis
M=abs(X)/length(x)*2; %amplitude spectrum
plot(f,M(1:length(f)));
xlabel({'Frequancy (Hz)'}); ylabel({'Amplitude '});
the problem is when I use the hannig window
Where do you want to use hanning window in this code? I guess it's after x = 4*cos(2*pi*100*t); right? I yes, use a couple lines before you perform the fft.
x = 4*cos(2*pi*100*t);
h = hann(N);
x = x'.*h;
Then use the code you have written for computing fft.
thank you a lot again; yes ; like I do in my first question; the problem is in the amplitude ; if I do this code the amplitude is 2;
fs=300;
N=3000;
t = (1:N)/fs; % Time vector
x = 4*cos(2*pi*100*t);
h = hann(N);
x = x'.*h;
%========================== FFT ================================
fs=300;
X=fft(x); %FFT
df=fs/length(X) %frequency resolution
f=(0:1:length(X)/2)*df; %frequency axis
M=abs(X)/length(x)*2; %amplitude spectrum
plot(f,M(1:length(f)));
xlabel({'Frequancy (Hz)'}); ylabel({'Amplitude '});
Right, the amplitude off fft(x) is 2. It does not mean that x has an amplitude of 2 anyway. To get the amplitude of x, use:
X=fft(x);
max(ifft(X))
This gives 4, which makes sense.
thank you a lot again for all your helps; but I want to see the right amplitude in the FFT because may be I will have a 1000 sinus for exemple ; I want the right code for FFT with hanning widow
Rewrite M=(abs(X)/max(abs(X)))*max(ifft(X));
Please note, it is not the actual fft amplitude, but we are manipulating to make it equal to our original signal.
mouh nyquist
mouh nyquist on 2 Jan 2015
Edited: mouh nyquist on 2 Jan 2015
thank you a lot;
when I use your code with x = 4*cos(2*pi*100*t)+8*cos(2*pi*10*t); I get amplitude = 12 I think we must multiplied by 2 for hanning window like this (M=(abs(X)/length(x)*2)*2) that always give a correct amplitude
x = 4*cos(2*pi*100*t)+8*cos(2*pi*10*t);
Its amplitude is 12, range is 12*2 = 24
Now lets include the hanning window, say:
h = hann(N); % as you defined N in your code
Now, x.*h' will have a minimum value of -9.8 and a maximum of 12. You can also plot to see this. So, do you want to show amplitude equal to 21.8? If yes, then instead of multiplying by 2, use:
M=(abs(X)/max(abs(X)))*range(ifft(X));
thank you for all your helps ; now I understand very well the FFT with hanning window ;thank you again

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!