Matlab中的FFT计算

来源:互联网 发布:新网域名证书查询 编辑:程序博客网 时间:2024/06/08 06:35

1. FFT中幅度的计算:

complex amplitude = 实际幅度*N/2

解释如下:

https://www.dsprelated.com/showarticle/607.php

The DFT Magnitude of a Real-valued Cosine Sequence

https://www.mathworks.com/help/signal/ug/discrete-fourier-transform.html
中间有提到
Note  The resulting FFT amplitude is A*n/2, where A is the original amplitude and n is the number of FFT points. This is true only if the number of FFT points is greater than or equal to the number of data samples. If the number of FFT points is less, the FFT amplitude is lower than the original amplitude by the above amount.

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

Fs = 1000;            % Sampling frequency                    
T = 1/Fs;             % Sampling period       
L = 1500;             % Length of signal
t = (0:L-1)*T;        % Time vector
S = 0.7*sin(2*pi*50*t) + sin(2*pi*120*t);

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

f = Fs*(0:(L/2))/L;

计算频率的一半,L点对应到最大频率Fs。写法最好这么写,构成751点长度的序列

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


Y = fft(S);

直接FFT,得到的是复数值的complex amplitude。 里面有幅度和频率信息

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


P2 = abs(Y/L);

% If X is complex, abs(X) returns the complex magnitude.

P1 = P2(1:L/2+1);

P1(2:end-1) = 2*P1(2:end-1);

这一段就是上面说的:Y里面直接计算出来的幅度是spectral amplitude, 它跟原信号中的实际幅度对应关系是

Spectral Amplitude = True Amplitude *L/2

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

plot(f,P1) 

title('Single-Sided Amplitude Spectrum of S(t)')

xlabel('f (Hz)')

ylabel('|P1(f)|')






原创粉丝点击