main content

arbitrary magnitude filter design -凯发k8网页登录

this example shows how to design filters with arbitrary magnitude response. the family of filter design (fdesign) objects allow for the design of filters with various types of responses. among these types, the arbitrary magnitude is the less specialized and most versatile one. the examples below illustrate how arbitrary magnitude designs can solve problems when other response types find limitations.

fir modeling with the frequency sampling method

this section illustrates a case where the amplitude of the filter is defined over the complete nyquist range (there are no relaxed or "don't care" regions). the example that follows uses a single (full) band specification type and the robust frequency sampling algorithm to design a filter whose amplitude is defined over three sections: a sinusoidal section, a piecewise linear section and a quadratic section. it is necessary to select a large filter order because the shape of the filter is quite complicated:

n = 300;
b1 = 0:0.01:0.18;
b2 = [.2 .38 .4 .55 .562 .585 .6 .78];
b3 = 0.79:0.01:1;
a1 = .5 sin(2*pi*7.5*b1)/4;    % sinusoidal section
a2 = [.5 2.3 1 1 -.2 -.2 1 1]; % piecewise linear section
a3 = .2 18*(1-b3).^2;          % quadratic section
f = [b1 b2 b3];
a = [a1 a2 a3];
d = fdesign.arbmag('n,f,a',n,f,a);
hd = design(d,'freqsamp','systemobject',true);
fvtool(hd,'magnitudedisplay','zero-phase');

figure figure 1: zero-phase response contains an axes object. the axes object with title zero-phase response, xlabel normalized frequency ( times pi blank r a d / s a m p l e ), ylabel amplitude contains 2 objects of type line.

close(gcf)

in the previous example, the normalized frequency points were distributed between 0 and pi rad/sample (extrema included). you can also specify negative frequencies and obtain complex filters. the following example models a complex rf bandpass filter and uses a kaiser window to mitigate the effects of the gibbs phenomenon that occurs due to the 70 db magnitude gap between the -pi and pi rad/sample frequencies:

load cfir.mat; % load a predefined set of frequency and amplitude vectors
n = 200;
d = fdesign.arbmag('n,f,a',n,f,a);
hd = design(d,'freqsamp', 'window' ,{@kaiser,20},'systemobject',true);
fvtool(hd,'frequencyrange','[-pi, pi)');

figure figure 2: magnitude response (db) contains an axes object. the axes object with title magnitude response (db), xlabel normalized frequency ( times pi blank r a d / s a m p l e ), ylabel magnitude (db) contains 2 objects of type line.

modeling smooth functions with an equiripple fir filter

the equiripple algorithm is well suited for modeling smooth functions as shown in the following example that models an exponential with a minimum order fir filter. the example specifies a small ripple value across all frequencies and defines weights that increase proportionally to the desired amplitude to improve the performance at high frequencies:

f = linspace(0,1,100);
a = exp(-2*pi*f); 
r = 0.045; % ripple
w = .1-20*log10(abs(a)); % weights
d = fdesign.arbmag('f,a,r',f,a,r);
hd = design(d,'equiripple','weights',w,'systemobject',true);
fvtool(hd,'magnitudedisplay','zero-phase', 'frequencyrange','[0, pi)');

figure figure 3: zero-phase response contains an axes object. the axes object with title zero-phase response, xlabel normalized frequency ( times pi blank r a d / s a m p l e ), ylabel amplitude contains 2 objects of type line.

single-band vs. multi-band equiripple fir designs

in certain applications, it might be of interest to shape the stopband of the filter to, for example, minimize the integrated side-lobe levels, or to improve the quantization robustness. the following example designs a lowpass filter with a staircase stopband. to achieve the design, it uses a distribution of weights that increase the attenuation of each step by 5 db in the stopband:

n = 150;
f = [0 .25 .3 .4 .401 .5 .501 .6 .601 .7 .701 .8 .801 .9 .901 1]; 
a = [1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0];
w = 10.^([0 0 5 5 10 10 15 15 20 20 25 25 30 30 35 35]/20);
d = fdesign.arbmag('n,f,a',n,f,a);
hd1 = design(d,'equiripple','weights',w,'systemobject',true);

the following example presents an alternative design based on the use of a multi-band approach that defines two bands (passband and stopband) separated by a "don't care" region (or transition band):

b = 2;            % number of bands
f1 = f(1:2);      % passband
f2 = f(3:end);    % stopband
% f(2:3)=[.25 .3] % transition band
a1 = a(1:2);
a2 = a(3:end);
w1 = w(1:2);
w2 = w(3:end);
d = fdesign.arbmag('n,b,f,a',n,b,f1,a1,f2,a2);
hd2 = design(d,'equiripple','b1weights',w1,'b2weights',w2,...
    'systemobject',true);
hfvt = fvtool(hd1,hd2,'magnitudedisplay','magnitude (db)','legend','on');
legend(hfvt, 'single-band design', 'multi-band design');

figure figure 4: magnitude response (db) contains an axes object. the axes object with title magnitude response (db), xlabel normalized frequency ( times pi blank r a d / s a m p l e ), ylabel magnitude (db) contains 2 objects of type line. these objects represent single-band design, multi-band design.

notice the clear advantage of the multi-band approach. by relaxing constraints in the transition region, the equiripple algorithm converges to a solution with lower passband ripples and greater stopband attenuation. in other words, the frequency characteristics of the first filter could be matched with a lower order. the following example illustrates this last comment by obtaining equivalent filters using minimum order designs.

minimum order designs require the specification of one ripple value per band. for this example, set the ripple to 0.0195 in all bands.

r = 0.0195;
% single-band minimum order design
d = fdesign.arbmag('f,a,r',f,a,r);
hd1 = design(d,'equiripple','weights',w,'systemobject',true);
% multi-band minimum order design
d = fdesign.arbmag('b,f,a,r',b,f1,a1,r,f2,a2,r);
hd2 = design(d,'equiripple','b1weights',w1,'b2weights',w2,...
    'systemobject',true);
hfvt = fvtool(hd1,hd2);
legend(hfvt, 'single-band minimum order design', ...
  'multi-band minimum order design');

figure figure 5: magnitude response (db) contains an axes object. the axes object with title magnitude response (db), xlabel normalized frequency ( times pi blank r a d / s a m p l e ), ylabel magnitude (db) contains 2 objects of type line. these objects represent single-band minimum order design, multi-band minimum order design.

the passband ripple and stopband attenuation of both designs match. however, the single-band design has an order of 152 while the multi-band design has an order of 72.

order(hd)
ans = 32

constrained multi-band equiripple designs

multi-band equiripple designs allow you to specify ripple constraints for different bands, specify single-frequency bands, and force specified frequency points to specified values.

constrained band designs

the following example designs an 80th order passband filter with an attenuation of 60 db in the first stopband and of 40 db in the second stopband. by relaxing the attenuation of the second stopband, the ripple in the passband is reduced while maintaining the same filter order.

n = 80; % filter order
b = 3;  % number of bands
d = fdesign.arbmag('n,b,f,a,c',n,b,[0 0.25],[0 0],true,...
  [0.3 0.6],[1 1],false,[0.65 1],[0 0],true)
d = 
  arbmag with properties:
               response: 'arbitrary magnitude'
          specification: 'n,b,f,a,c'
            description: {4x1 cell}
    normalizedfrequency: 1
            filterorder: 80
                 nbands: 3
          b1frequencies: [0 0.2500]
           b1amplitudes: [0 0]
          b1constrained: 1
               b1ripple: 0.2000
          b2frequencies: [0.3000 0.6000]
           b2amplitudes: [1 1]
          b2constrained: 0
          b3frequencies: [0.6500 1]
           b3amplitudes: [0 0]
          b3constrained: 1
               b3ripple: 0.2000

the b1constrained and b3constrained properties have been set to true to specify that the first and third bands are constrained bands. specify the ripple value for the ith constrained band using the biripple property:

d.b1ripple = 10^(-60/20); % attenuation for the first stopband
d.b3ripple = 10^(-40/20); % attenuation for the second stopband
hd = design(d,'equiripple','systemobject',true)
hd = 
  dsp.firfilter with properties:
            structure: 'direct form'
      numeratorsource: 'property'
            numerator: [-0.0036 0.0049 0.0052 -0.0022 -0.0097 -0.0044 0.0093 0.0100 -0.0031 -0.0062 -8.4302e-04 -0.0055 -0.0040 0.0120 0.0100 -0.0056 -0.0026 -0.0032 -0.0157 8.1567e-04 0.0218 0.0050 -0.0029 0.0057 -0.0200 -0.0274 0.0182 0.0235 ... ]
    initialconditions: 0
  show all properties
fvtool(hd,'legend','off');

figure figure 6: magnitude response (db) contains an axes object. the axes object with title magnitude response (db), xlabel normalized frequency ( times pi blank r a d / s a m p l e ), ylabel magnitude (db) contains 2 objects of type line.

single-frequency bands

the following example designs a minimum order equiripple filter with two notches at exactly 0.25*pi and 0.55*pi rad/sample, and with a ripple of 0.15 in the passbands.

b = 5; % number of bands
d = fdesign.arbmag('b,f,a,r',b);
d.b1frequencies = [0 0.2];  
d.b1amplitudes = [1 1];
d.b1ripple = 0.15;
d.b2frequencies = 0.25; % single-frequency band
d.b2amplitudes = 0; 
d.b3frequencies = [0.3 0.5]; 
d.b3amplitudes = [1 1]; 
d.b3ripple = 0.15;
d.b4frequencies = 0.55; % single-frequency band
d.b4amplitudes = 0; 
d.b5frequencies = [0.6 1];  
d.b5amplitudes = [1 1];
d.b5ripple = 0.15;
hd = design(d,'equiripple','systemobject',true);
fvtool(hd);

figure figure 7: magnitude response (db) contains an axes object. the axes object with title magnitude response (db), xlabel normalized frequency ( times pi blank r a d / s a m p l e ), ylabel magnitude (db) contains 2 objects of type line.

forced frequency points

the following example designs a highpass filter with a stopband edge at 100 hz, and a passband edge at 150 hz. suppose that you want to reject a strong 60 hz interference without having to add an extra filter or without having to increase the filter order by a large amount. you can do this by forcing the magnitude response of the highpass filter to be 0 at 60 hz:

b = 2;    % number of bands
n = 92;   % filter order
fs = 2e3; % sampling frequency
d = fdesign.arbmag('n,b,f,a',n,b,[0 60 100],[0 0 0],[150 1000],[1 1],fs);

use the b1forcedfrequencypoints design option to force the 60 hz point to its specified amplitude value.

hd = design(d,'equiripple','b1forcedfrequencypoints',60,...
    'systemobject',true);
hfvt = fvtool(hd,'fs', fs);

figure figure 8: magnitude response (db) contains an axes object. the axes object with title magnitude response (db), xlabel frequency (hz), ylabel magnitude (db) contains 2 objects of type line.

zoom into the stopband of the highpass filter to observe that the amplitude is zero at the specified 60 hz frequency point:

hfvt.magnitudedisplay = 'magnitude';

figure figure 8: magnitude response contains an axes object. the axes object with title magnitude response, xlabel frequency (hz), ylabel magnitude contains 2 objects of type line.

single-band vs. multi-band iir designs

as in the fir case, iir design problems where a transition band cannot be easily identified are best resolved with a single (full) band specification approach. as an example, model the optical absorption of a gas (atomic rubidium87 vapor):

nb = 12; 
na = 10;
f = linspace(0,1,100);
as = ones(1,100)-f*0.2;
absorb = [ones(1,30),(1-0.6*bohmanwin(10))',...
    ones(1,5), (1-0.5*bohmanwin(8))',ones(1,47)];
a = as.*absorb;
d = fdesign.arbmag('nb,na,f,a',nb,na,f,a);
w = [ones(1,30) ones(1,10)*.2 ones(1,60)];
hd = design(d, 'iirlpnorm', 'weights', w, 'norm', 2, 'densityfactor',30,...
    'systemobject',true);
fvtool(hd, 'magnitudedisplay','magnitude (db)', ...
    'normalizedfrequency','on');

figure figure 9: magnitude response (db) contains an axes object. the axes object with title magnitude response (db), xlabel normalized frequency ( times pi blank r a d / s a m p l e ), ylabel magnitude (db) contains 2 objects of type line.

in other cases where constraints can be relaxed in one or more transition bands, the multi-band approach provides the same benefits as in the fir case (namely better passband and stopband characteristics). the following example illustrates these differences by modeling a rayleigh fading wireless communications channel:

nb = 4;
na = 6;
f = [0:0.01:0.4 .45 1];
a = [1.0./(1-(f(1:end-2)./0.42).^2).^0.25 0 0];
d = fdesign.arbmag('nb,na,f,a',nb,na,f,a); % single-band design
hd1 = design(d,'iirlpnorm','systemobject',true);
b = 2;
f1 = f(1:end-2);          % passband
f2 = f(end-1:end);        % stopband
% f(end-2:end-1)=[.4 .45] % transition band
a1 = a(1:end-2);  
a2 = a(end-1:end);
d = fdesign.arbmag('nb,na,b,f,a',nb,na,b,f1,a1,f2,a2); % multi-band design
hd2 = design(d,'iirlpnorm','systemobject',true);
hfvt = fvtool(hd1,hd2);
legend(hfvt, 'single-band design', 'multi-band design');

figure figure 10: magnitude response (db) contains an axes object. the axes object with title magnitude response (db), xlabel normalized frequency ( times pi blank r a d / s a m p l e ), ylabel magnitude (db) contains 2 objects of type line. these objects represent single-band design, multi-band design.

网站地图