主要内容

Design of Peaking and Notching Filters

此示例显示了如何设计峰值和切口过滤器。过滤该峰值或凹痕以一定频率保留或消除信号的特定频率分量。滤波器的设计参数是需要峰值或缺口的频率,以及3-DB带宽或滤波器的Q因子。此外,鉴于这些规格,通过增加过滤器顺序,可以获得更接近理想过滤器的设计。

Second Order Notch Filters

Suppose you need to eliminate a 60 Hz interference in a signal sampled at 3000 Hz. A notch filter can be used for such a purpose. Theiirnotchfunction can be used to compute the coefficients of a second order notch filter.

Here is an example:

F0 = 60;% Interference is at 60 HzFS = 3000;%采样频率为3000 HzBW = 6;% Choose a bandwidth factor of 6Hz[num1,den1] = iirnotch(F0/(Fs/2),BW/(Fs/2)); fvtool(num1,den1,'fs',fs,'颜色','white');

图量响应(DB)包含一个轴对象。The axes object with title Magnitude Response (dB) contains an object of type line.

设计过滤器的一种等效方法是指定质量因子并获得3 dB带宽。质量因子定义为缺口或峰值频率的比率 F 0 和3 dB带宽 BW 。Mathematically, Q factor is given by Q = F 0 / BW 。在上述情况下,质量因子的值为10。指定带宽是一种更方便的方法,可以准确地实现设计过滤器所需的形状。滤波器的Q因子是衡量所需频率与其他频率分离的程度的度量。对于固定的滤波器顺序,通过将极点推向零来实现较高的Q因子。

Visualize the magnitude response of the filter usingfvtool

Q2 = 100;%选择Q系数为100[num2,den2] = iirnotch(F0/(Fs/2),F0/(Q2*Fs/2)); fvt = fvtool(num1,den1,num2,den2,'fs',fs,'颜色','white');legend(fvt,'Q = 10','q = 100');

图量响应(DB)包含一个轴对象。带有标题幅度响应(DB)的轴对象包含2个类型线的对象。这些对象表示q = 10,q = 100。

Second order Peak Filters

Peaking filters are used to retain only a single frequency component (or a small band of frequencies) from a signal. Theiirpeak函数可用于计算二阶峰滤波器的系数。

F0 = 1000;% Interference is at 60 HzFS = 3000;%采样频率为3000 HzQ1 = 10;[num1,den1] = iirpeak(f0/(fs/2),f0/(q1*fs/2));Q2 = 100;[num2,den2] = iirpeak(f0/(fs/2),f0/(q2*fs/2));fvt = fvtool(num1,den1,num2,den2,'fs',fs,'颜色','white');legend(fvt,'Q = 10','q = 100');

图量响应(DB)包含一个轴对象。带有标题幅度响应(DB)的轴对象包含2个类型线的对象。这些对象表示q = 10,q = 100。

Time varying Second Order Notch filter Implementation

Using time-varying filters requires changing the coefficients of the filter while the simulation runs. The DSP System Toolbox™ provides certain features such as theiirnotchfunction and thedsp.notchpeakfilterobject to design time-varying tunable notch filters. These features compute the filter coefficients directly.

使用静态滤波器的动态仿真

为了实现时间变化的过滤器,请创建动态设置以模拟过滤器并使用时变设计参数实现过滤器。

首先创建一个动态(流)模拟,其系数不会更改其系数。创建两个二阶档过滤器,一个使用dsp.SOSFilter对象和第二个使用dsp.NotchFilter对象。In the first filter, set the center frequency to 1 kHz, and the bandwidth at -3 dB to 500 Hz. Calculate the coefficients of this filter directly using theiirnotch功能。在第二个过滤器中,将中心频率设置为3 kHz,带宽为-3 dB至500 Hz。两个过滤器的采样率为8 kHz。

FS = 8E3;%8 kHz采样频率F01 = 1e3;% Notch at 1 kHz for Filter 1BW = 500;两个过滤器的%500 Hz带宽[b,a] = iirnotch(f01/(fs/2),bw/(fs/2))%过滤器1系数
b =1×30.8341 -1.1796 0.8341
a =1×31.0000 -1.1796 0.6682
sosFilter = dsp.SOSFilter (b);F02 = 3e3;滤波器2的3 kHz处的%缺口npFilter = dsp.NotchPeakFilter(“中心频率”,F02,'Bandwidth',BW,。。。'SampleRate',Fs); scope = spectrumAnalyzer(“ plotastwosidedspectrum”, false,。。。'SampleRate', Fs,。。。“平均轨迹”,'exponential',。。。“忘记factor',.95,。。。“频道名称”,{'滤波器1','filter 2'},,。。。'ShowLegend',真的);samplesPerFrame = 256; nFrames = 8192;fork = 1:nframes x = randn(SampleSperFrame,1);y1 = sosfilter(x);y2 = npfilter(x);范围([Y1,Y2]);end

随着时变滤波器的动态仿真

For a time-varying filter, the coefficients of time-varying filters change over time due to runtime changes in the design parameters (for example the center frequency for a notch filter). Create two second order notch filters with time varying design parameters. Similar to the above example, use theiirnotchfunction and thedsp.SOSFilterobject to implement the first filter, and thedsp.NotchFilterobject to implement the second filter. Vary the design parameters of both filters over time.

% Notch filter parameters - how they vary over timeFS = 8E3;%8 kHz采样频率F01 = 1e3 * [0.5, 1, 1.5, 3];滤波器1的%Notch频率F02 = 1E3 * [3.5,3,2.5,2];滤波器2的%Notch频率BW = 500 * ones(1,4);两个过滤器的%500 Hz带宽myChangingParams1 = struct('f0', num2cell(F01/(Fs/2)),'BW',num2cell(bw/(fs/2)));mychangingparams2 = struct('f0',num2cell(f02),'BW',num2cell(bw));paramschangetimes = [0,70,140,210];% 片刻之间%模拟时间管理nsamplesperframe = 256;趋势= 300;nsamples = ceil(趋势 * fs);nframes = floor(nsamples / nsamplesperframe);%对象创建sosfilter = dsp.sosfilter;%Filter 1 objectnpFilter = dsp.NotchPeakFilter('SampleRate',Fs); scope = spectrumAnalyzer(“ plotastwosidedspectrum”, false,。。。'SampleRate', Fs,。。。“平均轨迹”,'exponential',。。。“忘记factor',.75,。。。“频道名称”,{'滤波器1','filter 2'},,。。。'ShowLegend',真的);paramtbl1 = parametertimetable('Time', paramsChangeTimes,。。。“价值”,mychangingparams1,。。。'SampleRate', Fs/nSamplesPerFrame); paramtbl2 = ParameterTimeTable('Time', paramsChangeTimes,。。。“价值”, myChangingParams2,。。。'SampleRate', Fs/nSamplesPerFrame);%实际仿真循环forframeIdx = 1:nFrames%获得当前F0和BW[params1, update1] = paramtbl1(); [params2, update2] = paramtbl2();如果(update1)% Recompute filter coefficients if parameters changed[b, a] = iirnotch(params1.f0, params1.bw);%将过滤系数设置为新值sosfilter.numerator = b;sosfilter.denominator = a;end如果(update2) npFilter.CenterFrequency = params2.F0; npFilter.Bandwidth = params2.BW;end% Generate vector of white noise samplesx = randn(nSamplesPerFrame, 1);%滤镜噪声y1 = sosfilter(x);y2 = npfilter(x);%可视化频谱范围([Y1,Y2]);end

可以使用该调谐峰过滤器使用dsp.notchpeakfilterobject or using theiirpeakfunction anddsp.SOSFilter对象。

Note:这些可调,notchin达到顶峰g filters support code generation.

Higher order Notch Filter

Since it is only possible to push the poles so far and remain stable, in order to improve the brickwall approximation of the filter, it is necessary to increase the filter order. A higher order notch filter can be designed usingfdesign.notchfilter specification object.

notchspec = fdesign.notch('n,f0,q',2,.4,100); notchfilt = design(notchspec,'SystemObject',真的);notchspec.FilterOrder = 6; notchfilt1 = design(notchspec,'SystemObject',真的);fvt= fvtool(notchfilt, notchfilt1,'颜色','white');legend(fvt,'2nd Order Filter',“第六阶过滤器”);

图量响应(DB)包含一个轴对象。带有标题幅度响应(DB)的轴对象包含2个类型线的对象。These objects represent 2nd Order Filter, 6th Order Filter.

对于给定的订单,我们可以通过允许通带和/或停止带纹波获得更尖锐的过渡。

n = 8;F0 = 0.4;BW = 0.1;notchspec = fdesign.notch('N,F0,BW',N,F0,BW); notchfilt = design(notchspec,'SystemObject',真的);notchspec1 = fdesign.notch('N,F0,BW,Ap,Ast',N,F0,BW,0.5,60); notchfilt1 = design(notchspec1,'SystemObject',真的);fvt= fvtool(notchfilt, notchfilt1,'颜色','white');legend(fvt,'Maximally Flat 8th Order Filter',。。。'8th Order Filter With Passband/Stopband Ripples',。。。'Location','东南');

图量响应(DB)包含一个轴对象。带有标题幅度响应(DB)的轴对象包含2个类型线的对象。These objects represent Maximally Flat 8th Order Filter, 8th Order Filter With Passband/Stopband Ripples.

Higher order Peak Filters

可以使用高阶峰值过滤器设计fdesign.peakfilter specification object. All specifications and tradeoffs mentioned so far apply equally to peaking filters.

这是一个高阶峰值过滤器的示例:

n = 6;F0 = 0.7;BW = 0.001;peakspec = fdesign.peak('N,F0,BW',N,F0,BW); peakfilt = design(peakspec,'SystemObject',真的);peakspec1 = fdesign.peak('N,F0,BW,Ast',n,f0,bw,80);peakfilt1 = design(peakspec1,'SystemObject',真的);fvt= fvtool(peakfilt, peakfilt1,'颜色','white');legend(fvt,'Maximally Flat 6th Order Filter',。。。'6th Order Filter With 80 dB Stopband Attenuation','Location','东南');

图量响应(DB)包含一个轴对象。带有标题幅度响应(DB)的轴对象包含2个类型线的对象。These objects represent Maximally Flat 6th Order Filter, 6th Order Filter With 80 dB Stopband Attenuation.

See Also

Functions

Objects

Related Topics