How to Normalize a fft to plot in frequency domain?
110 次查看(过去 30 天)
显示 更早的评论
When I plot the frequency domain the power is not 3 and 5 as I expect. I read the documentation for fft() and cannot figure out how to normalize my fft properly. Can someone explain the procedure to normalize the cosines and a Gaussian wave? Thanks
clear all;
%generate the signal
t = 0:1/2000:.02;
x = 3*cos(2*pi*60*t) + 5*cos(2*pi*200*t);
%sample the signal
fs = 1000;
t1000 = 0:1/fs:.02; % number of sample points
n1000 = 0:length(t1000)-1; % number of intervals
x1000 = 3*cos(2*pi*60*n1000/1000) + 5*cos(2*pi*200*n1000/1000) ; %cos(2*pi*60*n*ts);
%Compute FT
z = fftshift(fft(x1000));
f = -fs/2: fs/(length(n1000)-1): fs/2 ;
%plot time domain
figure
subplot(2,1,1)
plot(t,x)
hold on;
grid on;
stem(t1000, x1000, 'filled', 'r', 'LineWidth', 2);
%plot freq domain
subplot(2,1,2);
plot(f,abs(z)); %normalization??
grid on;
xticks(-500:50:500);
xlim([-300 300]);
0 个评论
采纳的回答
Star Strider
2017-9-14
I am not certain what you intend by ‘normalise’. You need to scale it by dividing the fft result by the length of the time-domain signal:
z = fftshift(fft(x1000)/length(x1000));
This ‘normalises’ the result, correcting for the total energy in the time-domain signal. (You can use the numel function instead of length for a vector. Read about both to understand where each is appropriate.)
Note that you are using the two-sided Fourier transform, so the signal intensity will be equally divided between the negative frequencies and positive frequencies. In a one-sided Fourier transform, correct for this by multiplying the fft output by 2 to reproduce the amplitude of the original signals.
6 个评论
Mustafa Rifat
2021-11-1
Hello, If we perform fft2, should we normalize dividing by length(x)*length(y)?
Star Strider
2021-11-1
@Mustafa Rifat — Apparently not. The discussion in the fft2 secton on 2-D Fourier Transform does not normalise by the lengths or the number of elements in the matrix, however a similar discussion on Discrete Fourier Transform of Vector in the fft documentation, does.
I admit that I have never thought about this before, because I infrequently use fft2.
There is nothing wrong with experimenting to see if dividing by numel(A), where ‘A’ is the matrix, gives the desired result.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Transforms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!