首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MATLAB中快速傅立叶变换的频率响应

MATLAB中快速傅立叶变换的频率响应
EN

Stack Overflow用户
提问于 2010-10-22 08:56:49
回答 2查看 23.3K关注 0票数 4

场景是这样的:使用频谱分析仪,我得到了输入值和输出值。采样数为32000,采样率为2000 samples /s,输入为50 hz的正弦波,输入为电流,输出为压力,单位为psi。

如何使用MATLAB中的FFT函数,使用MATLAB计算这些数据的频率响应。

我能够产生一个正弦波,它给出了幅度和相位角,这是我使用的代码:

代码语言:javascript
复制
%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度相角的相图中得到了频率响应,这是计算频率响应的正确方法吗?

如何将此响应与从分析仪获得的值进行比较?这是一个交叉检查,以查看分析器逻辑是否有意义。

EN

回答 2

Stack Overflow用户

发布于 2010-10-22 17:18:11

乍一看看起来还不错,但是有几件事你没有注意到:

  • 在进行快速傅立叶变换之前,您应该对时域数据应用窗口函数,例如,有关窗口设置的一般信息,请参见http://en.wikipedia.org/wiki/Window_function;对于最常用的窗口函数,请参见http://en.wikipedia.org/wiki/Hann_window (Hann也称为Hanning)。
  • 您可能希望在dB中绘制对数震级,而不仅仅是原始震级
票数 1
EN

Stack Overflow用户

发布于 2013-07-22 17:22:54

您应该考虑使用cpsd()函数来计算频率响应。为您处理各种窗口函数的缩放和归一化。

然后,频率响应将是

代码语言:javascript
复制
G = cpsd (output,input) / cpsd (input,input)

然后取angle()得到输入和输出之间的相位差。

您的代码片段没有提到输入和输出数据集是什么。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3993147

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档