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);

 채택된 답변

Shoaibur Rahman
Shoaibur Rahman 2015년 1월 1일

1 개 추천

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

mouh nyquist
mouh nyquist 2015년 1월 1일
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.
mouh nyquist
mouh nyquist 2015년 1월 1일
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
Shoaibur Rahman
Shoaibur Rahman 2015년 1월 1일
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.
mouh nyquist
mouh nyquist 2015년 1월 2일
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
Shoaibur Rahman
Shoaibur Rahman 2015년 1월 2일
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 2015년 1월 2일
편집: mouh nyquist 2015년 1월 2일
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
Shoaibur Rahman
Shoaibur Rahman 2015년 1월 2일
편집: Shoaibur Rahman 2015년 1월 2일
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));
mouh nyquist
mouh nyquist 2015년 1월 2일
thank you for all your helps ; now I understand very well the FFT with hanning window ;thank you again

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

질문:

2015년 1월 1일

댓글:

2015년 1월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by