discretizing a notch filter -凯发k8网页登录
this example shows the comparison of several techniques for discretizing a notch filter. while control system components are often designed in continuous time, they must generally be discretized for implementation on digital computers and embedded processors.
continuous-time notch filter
notch filters are designed to reject signal content at a specific frequency by sharply attenuating the gain at that frequency. for this example we consider the following notch filter:
you can plot the frequency response of this filter with the bode
command:
h = tf([1 0.5 100],[1 5 100]); bode(h), grid
this notch filter provides a 20db attenuation at the frequency w = 10 rad/s.
choosing the discretization method
you can discretize a continuous-time system with the c2d
command. several discretization algorithms are supported by control system toolbox™, including:
zero-order hold
first-order hold
impulse invariant
tustin (bilinear approximation)
tustin with frequency prewarping
matched poles and zeros
which method to choose depends on the application and requirements.
the zero- and first-order hold methods and the impulse-invariant method are well-suited for discrete approximations in the time domain. for example, the step response of the zoh discretization matches the continuous-time step response at each time step (independently of the sampling rate):
ts = 0.1; hdz = c2d(h,ts,'zoh'); step(h,'b',hdz,'r'), legend('continuous','discretized at 10 hz')
similarly, the impulse-invariant discretization has the same impulse response as the original system:
g = tf([1 -3],[1 2 10]); gd = c2d(g,ts,'imp'); impulse(g,'b',gd,'r') legend('continuous','discretized at 10 hz')
by contrast, the tustin and matched methods tend to perform better in the frequency domain because they introduce less gain and phase distortion near the nyquist frequency. for example, compare the bode responses of the continuous-time notch filter and its discretizations using the zoh, tustin, and matched algorithms:
hdt = c2d(h,ts,'tustin'); hdm = c2d(h,ts,'match'); bode(h,'b',hdz,'r',hdt,'m',hdm,'g',{1 100}), grid legend('continuous','zoh','tustin','matched')
this comparison indicates that the matched method provides the most accurate frequency-domain approximation of the notch filter. however, you can further improve the accuracy of the tustin algorithm by specifying a prewarping frequency equal to the notch frequency. this ensures accurate match near w = 10 rad/s:
hdp = c2d(h,ts,'prewarp',10); bode(h,'b',hdt,'m',hdp,'g',{1 100}), grid legend('continuous','tustin','tustin with prewarping')
choosing the sampling rate
the higher the sampling rate, the closer the match between the continuous and discretized responses. but how small can the sampling rate be, or equivalently, how large can the sampling interval be? as a rule of thumb, if you want the continuous and discretized models to match closely up to some frequency wm
, make sure that the nyquist frequency (sampling rate times pi) is at least twice wm
. for the notch filter, you need to preserve the shape near 10 rad/s, so the nyquist frequency should be beyond 20 rad/s, which gives a sampling period of at most pi/20 = 0.16 s.
to confirm this choice, compare the matched discretizations with sampling period 0.1, 0.15, and 0.3:
hd1 = c2d(h,0.1,'m'); hd2 = c2d(h,0.15,'m'); hd3 = c2d(h,0.3,'m'); bode(h,'b',hd1,'r',hd2,'m',hd3,'g',{1 100}), grid legend('continuous','ts = 0.1','ts = 0.15','ts = 0.3')
as predicted, the discretization remains fairly accurate for ts < 0.16
but starts breaking down for larger sampling intervals.
interactive gui
click on the link below to launch an interactive gui that further shows how the discretized notch filter is affected by the choice of discretization algorithm and sampling rate.
notch_gui