MATLAB中的高通滤波 [英] High-pass filtering in MATLAB

查看:510
本文介绍了MATLAB中的高通滤波的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道如何在MATLAB中使用过滤器?
我不是一个爱好者,所以我不关心滚降特性等 - 我有一个100 kHz采样的1维信号矢量x,我想对它执行高通滤波(比如说,拒绝10Hz以下的任何东西),以消除基线漂移。

在帮助中描述了Butterworth,Elliptical和Chebychev滤波器,但没有简单的解释如何实现。

解决方案

有几个过滤器可以使用,而过滤器的实际选择将取决于你想要的实现。既然你提到了Butterworth,Chebyschev和Elliptical过滤器,我假设你一般都在寻找IIR过滤器。

维基百科是一个很好的开始阅读不同的过滤器和他们做的。例如,上的wiki文章,尤其是关于稳定性的部分。



为了进一步说明我的观点,请考虑下面的带通滤波器。

  fpass = [0.05 0.2];%#通带
fstop = [0.045 0.205]; %#频率下降到一半功率
Rpass = 1;%#最大允许波段阻带(dB)
Astop = 40;%#最小40dB衰减
n = cheb2ord(fpass, fstop,Rpass,Astop);%#计算最小滤波器顺序以达到这些设计要求

[b,a] = cheby2(n,Astop,fstop);

现在,如果您使用 zplane(b, a),你会发现在单位圆外有几个极点( x ),这使得这个方法不稳定。 >



,这一点从频率响应全是无用的事实可以看出。使用 freqz(b,a)来获得以下内容: $ b



为了得到一个更稳定的滤波器,你需要精确的设计要求在MATLAB中使用 zpk 方法而不是 ba 来使用二阶滤波器。下面是如何使用与上面相同的过滤器:

pre code> [z,p,k] = cheby2(n,Astop,fstop);
[s,g] = zp2sos(z,p,k);%#创建二阶段
Hd = dfilt.df2sos(s,g);%#创建一个dfilt对象。

现在,如果你看看这个过滤器的特性,你会看到所有的极点在里面单位圆(因此稳定)并符合设计要求。



$ b $ <$> $ butter 和 ellip ,等价于 buttord ellipord 。 MATLAB文档在设计过滤器上也有很好的例子。你可以建立在这些例子和我的设计过滤器根据你想要的。

要使用数据过滤器,您可以做 filter(b,a,data)或者 filter(Hd,data)取决于您最终使用的过滤器。如果您想要零相位失真,请使用 filtfilt 。但是,这不接受 dfilt 对象。因此,对于 Hd 的零相位滤波器,使用 filtfilthd 文件在Mathworks文件交换站点上可用

编辑



这是对@ DarenW的评论。平滑和滤波是两种不同的操作,尽管在某些方面它们是相似的(移动平均是一个低通滤波器),但是除非可以确定它不是关注具体应用。例如,实现达伦关于从0-25kHz的线性啁啾信号的建议,以100kHz采样,这个用高斯滤波器平滑后的频谱是$。 b
$ b



当然,接近10Hz的漂移几乎为零。但是,这种操作彻底改变了原始信号中频率分量的性质。这种差异是因为他们完全忽略了平滑操作的滚降(参见红线),并假设它将是平坦的零。如果那是真的,那么减法就会奏效。但是,可惜的是,情况并非如此,这就是为什么整个设计过滤器领域存在的原因。


Does anyone know how to use filters in MATLAB? I am not an aficionado, so I'm not concerned with roll-off characteristics etc — I have a 1 dimensional signal vector x sampled at 100 kHz, and I want to perform a high pass filtering on it (say, rejecting anything below 10Hz) to remove the baseline drift.

There are Butterworth, Elliptical, and Chebychev filters described in the help, but no simple explanation as to how to implement.

解决方案

There are several filters that can be used, and the actual choice of the filter will depend on what you're trying to achieve. Since you mentioned Butterworth, Chebyschev and Elliptical filters, I'm assuming you're looking for IIR filters in general.

Wikipedia is a good place to start reading up on the different filters and what they do. For example, Butterworth is maximally flat in the passband and the response rolls off in the stop band. In Chebyschev, you have a smooth response in either the passband (type 2) or the stop band (type 1) and larger, irregular ripples in the other and lastly, in Elliptical filters, there's ripples in both the bands. The following image is taken from wikipedia.

So in all three cases, you have to trade something for something else. In Butterworth, you get no ripples, but the frequency response roll off is slower. In the above figure, it takes from 0.4 to about 0.55 to get to half power. In Chebyschev, you get steeper roll off, but you have to allow for irregular and larger ripples in one of the bands, and in Elliptical, you get near-instant cut off, but you have ripples in both bands.

The choice of filter will depend entirely on your application. Are you trying to get a clean signal with little to no losses? Then you need something that gives you a smooth response in the passband (Butterworth/Cheby2). Are you trying to kill frequencies in the stopband, and you won't mind a minor loss in the response in the passband? Then you will need something that's smooth in the stop band (Cheby1). Do you need extremely sharp cut-off corners, i.e., anything a little beyond the passband is detrimental to your analysis? If so, you should use Elliptical filters.

The thing to remember about IIR filters is that they've got poles. Unlike FIR filters where you can increase the order of the filter with the only ramification being the filter delay, increasing the order of IIR filters will make the filter unstable. By unstable, I mean you will have poles that lie outside the unit circle. To see why this is so, you can read the wiki articles on IIR filters, especially the part on stability.

To further illustrate my point, consider the following band pass filter.

fpass=[0.05 0.2];%# passband
fstop=[0.045 0.205]; %# frequency where it rolls off to half power
Rpass=1;%# max permissible ripples in stopband (dB)
Astop=40;%# min 40dB attenuation
n=cheb2ord(fpass,fstop,Rpass,Astop);%# calculate minimum filter order to achieve these design requirements

[b,a]=cheby2(n,Astop,fstop);

Now if you look at the zero-pole diagram using zplane(b,a), you'll see that there are several poles (x) lying outside the unit circle, which makes this approach unstable.

and this is evident from the fact that the frequency response is all haywire. Use freqz(b,a) to get the following

To get a more stable filter with your exact design requirements, you'll need to use second order filters using the z-p-k method instead of b-a, in MATLAB. Here's how for the same filter as above:

[z,p,k]=cheby2(n,Astop,fstop);
[s,g]=zp2sos(z,p,k);%# create second order sections
Hd=dfilt.df2sos(s,g);%# create a dfilt object.

Now if you look at the characteristics of this filter, you'll see that all the poles lie inside the unit circle (hence stable) and matches the design requirements

The approach is similar for butter and ellip, with equivalent buttord and ellipord. The MATLAB documentation also has good examples on designing filters. You can build upon these examples and mine to design a filter according to what you want.

To use the filter on your data, you can either do filter(b,a,data) or filter(Hd,data) depending on what filter you eventually use. If you want zero phase distortion, use filtfilt. However, this does not accept dfilt objects. So to zero-phase filter with Hd, use the filtfilthd file available on the Mathworks file exchange site

EDIT

This is in response to @DarenW's comment. Smoothing and filtering are two different operations, and although they're similar in some regards (moving average is a low pass filter), you can't simply substitute one for the other unless it you can be sure that it won't be of concern in the specific application.

For example, implementing Daren's suggestion on a linear chirp signal from 0-25kHz, sampled at 100kHz, this the frequency spectrum after smoothing with a Gaussian filter

Sure, the drift close to 10Hz is almost nil. However, the operation has completely changed the nature of the frequency components in the original signal. This discrepancy comes about because they completely ignored the roll-off of the smoothing operation (see red line), and assumed that it would be flat zero. If that were true, then the subtraction would've worked. But alas, that is not the case, which is why an entire field on designing filters exists.

这篇关于MATLAB中的高通滤波的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆