[英]Frequency response using FFT in MATLAB
以下是場景:使用頻譜分析儀,我有輸入值和輸出值。 樣本數為32000
,采樣率為2000
樣本/秒,輸入為50 hz
的正弦波,輸入為電流,輸出為壓力,單位為psi。
如何使用MATLAB使用MATLAB中的FFT函數計算此數據的頻率響應。
我能夠生成一個正弦波,它給出了幅度和相位角,這里是我使用的代碼:
%FFT Analysis to calculate the frequency response for the raw data
%The FFT allows you to efficiently estimate component frequencies in data from a discrete set of values sampled at a fixed rate
% Sampling frequency(Hz)
Fs = 2000;
% Time vector of 16 second
t = 0:1/Fs:16-1;
% Create a sine wave of 50 Hz.
x = sin(2*pi*t*50);
% Use next highest power of 2 greater than or equal to length(x) to calculate FFT.
nfft = pow2(nextpow2(length(x)))
% Take fft, padding with zeros so that length(fftx) is equal to nfft
fftx = fft(x,nfft);
% Calculate the number of unique points
NumUniquePts = ceil((nfft+1)/2);
% FFT is symmetric, throw away second half
fftx = fftx(1:NumUniquePts);
% Take the magnitude of fft of x and scale the fft so that it is not a function of the length of x
mx = abs(fftx)/length(x);
% Take the square of the magnitude of fft of x.
mx = mx.^2;
% Since we dropped half the FFT, we multiply mx by 2 to keep the same energy.
% The DC component and Nyquist component, if it exists, are unique and should not be multiplied by 2.
if rem(nfft, 2) % odd nfft excludes Nyquist point
mx(2:end) = mx(2:end)*2;
else
mx(2:end -1) = mx(2:end -1)*2;
end
% This is an evenly spaced frequency vector with NumUniquePts points.
f = (0:NumUniquePts-1)*Fs/nfft;
% Generate the plot, title and labels.
subplot(211),plot(f,mx);
title('Power Spectrum of a 50Hz Sine Wave');
xlabel('Frequency (Hz)');
ylabel('Power');
% returns the phase angles, in radians, for each element of complex array fftx
phase = unwrap(angle(fftx));
PHA = phase*180/pi;
subplot(212),plot(f,PHA),title('frequency response');
xlabel('Frequency (Hz)')
ylabel('Phase (Degrees)')
grid on
我從90
度相位角的相位圖中獲取了頻率響應,這是計算頻率響應的正確方法嗎?
如何將此響應與從分析儀獲得的值進行比較? 這是一個交叉檢查,以查看分析器邏輯是否有意義。
乍一看看起來不錯,但是你遺漏了幾件事:
你應該在FFT之前對時域數據應用窗口函數,例如http://wind.wikipedia.org/wiki/Window_function用於窗口化, http://en.wikipedia.org/wiki/Hann_window用於最常用的窗口功能(Hann aka Hanning)。
您可能希望以dB為單位繪制對數幅度,而不僅僅是原始幅度
您應該考慮查看cpsd()函數來計算頻率響應。 為您處理各種窗口函數的縮放和規范化。
然后是頻率響應
G = cpsd (output,input) / cpsd (input,input)
然后取angle()
來獲得輸入和輸出之間的相位差。
您的代碼段未提及輸入和輸出數據集。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.