简体   繁体   English

如何使用 MATLAB 正确进行频率带通滤波器?

[英]How to correctly bandpass filter in frequency with MATLAB?

i'm pretty new to matlab and signal processing, but I am working on a project and I am stuck.我对 matlab 和信号处理很陌生,但我正在做一个项目,但我被卡住了。 My goal is to do a band-pass fast Fourier transform (FFT) filter with cut-off frequencies of 0.5 Hz and 3 Hz from a real signal.我的目标是做一个带通快速傅里叶变换 (FFT) 滤波器,其截止频率为真实信号的 0.5 Hz 和 3 Hz。 My input signal is a signal sampled ad 405Hz and of around 35000 samples.我的输入信号是一个 405Hz 采样的信号,大约有 35000 个样本。 My implementation looks like this:我的实现如下所示:

%ZFiltered = My signal 
filtered = bandpass(fft(zFiltered), [0.5 3], sampling_frequency);
res = ifft(filtered);

subplot(2,1,1)
plot(zFiltered)

subplot(2,1,2)
plot(abs(res))

My questions are: Why do I get a signal which contains also imaginary part?我的问题是:为什么我会得到一个包含虚部的信号? Why does it look like this ?为什么会这样

Your goal is unclear to me;我不清楚你的目标; here are three different approaches that your question hints at这是您的问题暗示的三种不同方法

  1. filter your raw signal with a band-pass filter as your code attempts to do当您的代码尝试执行此操作时,使用带通滤波器过滤您的原始信号
  2. use the fft and ifft functions to filter your raw signal使用fftifft函数过滤原始信号
  3. calculate the coefficients of a digital filter that would act as a band-pass filter when used with the filter function计算与filter function 一起使用时充当带通滤波器的数字滤波器的系数

Approach 1 : filtering with bandpass function方法1 :带bandpass滤波function

Referring to the bandpass documentation , you would use your original signal and specify the filter band and sampling frequency as in:参考bandpass文档,您将使用原始信号并指定滤波器频带和采样频率,如下所示:

filtered_signal = bandpass(zFiltered,[freq_low freq_high],sample_freq);
plot(zFiltered); hold on;
plot(filtered_signal);

where the inputs are the其中输入是

  • zFiltered : original (unfiltered signal) zFiltered :原始(未过滤的信号)
  • freq_low=0.5 : lowest frequency in Hz of the band pass range` freq_low=0.5 :带通范围的最低频率(Hz)
  • freq_high=3 : highest frequency in Hz of the band pass range freq_high=3 : 带通范围的最高频率(Hz)
  • sample_freq=405 : the sampling frequency in Hz sample_freq=405 : 以Hz为单位的采样频率

Your approach using digital fast Fourier transform function fft produces complex results because you are looking at the actual components computed by the transform (which by definition are complex having both real and imaginary parts).您使用数字快速傅里叶变换 function fft的方法会产生复杂的结果,因为您正在查看由变换计算的实际分量(根据定义,它具有实部和虚部的复数)。 You can compute the power of the signal with:您可以使用以下方法计算信号的功率:

P = abs(res/n).^2;

which gives you the power of the signal for each frequency represented in the Fourier transform (see the fft function docs here for more information).它为您提供了傅里叶变换中表示的每个频率的信号功率(有关更多信息,请参见此处fft function 文档)。


Approach 2 : Filtering with fft ifft functions方法 2 :使用fft ifft函数进行过滤

Use the Fourier transform and inverse Fourier transform functions to filter the signal.使用傅里叶变换和傅里叶逆变换功能对信号进行滤波。 The steps here are to use fft to get the signal into the frequency domain.这里的步骤是使用fft让信号进入频域。 Set the elements you want filtered to zero and then apply the inverse Fourier transform ( ifft ) to get the filtered signal.将要过滤的元素设置为零,然后应用傅里叶逆变换 ( ifft ) 以获得过滤后的信号。 Each component represents a given discrete frequencies in the range between 0Hz and F_s/2 that contributes to the signal.每个分量代表对信号有贡献的 0Hz 和F_s/2范围内的给定离散频率。 Set components of the FFT you want to suppress to zoro and apply ifft to get back a filter signal.将要抑制的 FFT 组件设置为 zoro 并应用ifft以获取滤波器信号。 Please see the fft docs and ifft docs for information on these functions and some of the intricacies of working with signals in the frequency domain.请参阅fft文档ifft文档以获取有关这些函数的信息以及在频域中处理信号的一些复杂性。


Approach 3 : Filtering with the coefficeints of the standard difference equation方法 3 :使用标准差分方程的系数进行过滤

Computing the coefficients of a digital band pass filter.计算数字带通滤波器的系数。 This approach calculates the coefficients (vectors A and B ) of the standard difference equation (see filter docs for details).这种方法计算标准差分方程的系数(向量AB )(有关详细信息,请参阅filter文档)。 An example of a function that does this is butter which gives the coefficients that represent a Butterworth filter of a given frequency.执行此操作的 function 的一个示例是butter ,它给出了表示给定频率的巴特沃斯滤波器的系数。 You could also look at the designfilt function for more options.您还可以查看designfilt function 以获得更多选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM