77
Linear phase Linear phase is a property of a filter , where the phase response of the filter is a linear function of frequency . The result is that all frequency components of the input signal are shifted in time (usually delayed) by the same constant amount (the slope of the linear function), which is referred to as the group delay . And consequently, there is no phase distortion due to the time delay of frequencies relative to one another. For discrete-time signals, perfect linear phase is easily achieved with a finite impulse response (FIR) filter. Approximations can be achieved with infinite impulse response (IIR) designs, which are more computationally efficient. Several techniques are: a Bessel transfer function which has a maximally flat group delay approximation function a phase equalizer A linear-phase filter is typically used when a causal filter is needed to modify a signal 's magnitude-spectrum while preserving the signal's time-domain waveform as much as possible. Linear-phase filters have a symmetric impulse response, e.g., The symmetric-impulse-response constraint means that linear- phase filters must be FIR filters , because a causal recursive filter cannot have a symmetric impulse response. We will show that every real symmetric impulse response corresponds to a real frequency response times a linear phase term , where is the slope of the linear phase. Linear phase is often ideal because a filter phase of the form corresponds to phase delay

PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

  • Upload
    vudang

  • View
    222

  • Download
    0

Embed Size (px)

Citation preview

Page 1: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

Linear phaseLinear phase is a property of a filter, where the phase response of the filter is a linear function of frequency. The result is that all frequency components of the input signal are shifted in time (usually delayed) by the same constant amount (the slope of the linear function), which is referred to as the group delay. And consequently, there is no phase distortion due to the time delay of frequencies relative to one another.

For discrete-time signals, perfect linear phase is easily achieved with a finite impulse response (FIR) filter.  Approximations can be achieved with infinite impulse response (IIR) designs, which are more computationally efficient.  Several techniques are:

a Bessel transfer function which has a maximally flat group delay approximation function a phase equalizer

A linear-phase filter is typically used when a causal filter is needed to modify a signal's magnitude-spectrum while preserving the signal's time-domain waveform as much as possible. Linear-phase filters have a symmetric  impulse response, e.g.,

The symmetric-impulse-response constraint means that linear-phase filters must be FIR filters, because a causal recursive filter cannot have a symmetric impulse response.

We will show that every real symmetric impulse response corresponds to a real frequency response times a linear phase term  ,

where   is the slope of the linear phase. Linear phase is often ideal

because a filter phase of the form  corresponds to phase delay

and group delay

That is, both the phase and group delay of a linear-phase filter are equal

to   samples of plain delay at every frequency. Since a length   FIR

filter implements   samples of delay, the value   is exactly half the

Page 2: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

total filter delay. Delaying all frequency components by the same amount preserves the waveshape as much as possible for a given amplitude response.PHASE AND GROUP DELAY

In the previous sections we looked at the two most important frequency-

domainrepresentations for LTI digital filters, the transfer function   and the frequency response:

We looked further at the polar form of the frequency

response  , thereby breaking it down into the amplitude

response   times the phase-response term  .

In the next two sections we look at two alternative forms of the phase response: phase delayand group delay. After considering some examples and special cases, poles and zeros of the transfer function are discussed in the next chapter.

PHASE DELAY

The phase response   of an LTI filter gives the radian phase shift added to the phase of each sinusoidal component of the input signal. It is often more intuitive to consider instead the phase delay, defined as

The phase delay gives the time delay in seconds experienced by each sinusoidal component of the input signal. For example, in the simplest lowpass filter of

Chapter 1, we found that the phase response was  , which

corresponds to a phase delay  , or one-half sample. Thus, we can say

precisely that the filter   exhibits half a sample of time delay

Page 3: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

at every frequency. (Regarding the discussion in §1.3.2, it is now obvious how we

should define the filter phase response at frequencies 0 and  .)

From a sinewave-analysis point of view, if the input to a filter with frequency

response   is

then the output is

 

and it can be clearly seen in this form that the phase delay expresses the phase response as a time delay in seconds.

PHASE UNWRAPPING

In working with phase delay, it is often necessary to ``unwrap'' the phase

response  . Phase unwrapping ensures that all appropriate multiples of   

have been included in  . We defined   simply as the complex angle of

the frequency response  , and this is not sufficient for obtaining a phase response which can be converted to true time delay. If multiples of   are discarded, as is done in the definition of complex angle, the phase delay is modified by multiples of the sinusoidal period. Since LTI filter analysis is based on sinusoidswithout beginning or end, one cannot in principle distinguish between ``true'' phase delay and a phase delay with discarded sinusoidal periods when looking at a sinusoidal output at any given frequency. Nevertheless, it is often useful to define the filter phase response as a continuous function of frequency

with the property that   or   (for real filters). This specifies how to unwrap the phase response at all frequencies where the amplitude responseis finite and nonzero. When the amplitude response goes to zero or infinity at some frequency, we can try to take a limit from below and above that frequency.

Page 4: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

Matlab and Octave have a function called unwrap() which implements a numerical algorithm for phase unwrapping. Figures 7.6.2 and 7.6.2 show the effect of the unwrap function on the phase response of the example elliptic lowpass filter of §7.5.2, modified to contract the zeros from the unit circle to a circle of radius   in the   plane:

[B,A] = ellip(4,1,20,0.5); % design lowpass filter

B = B .* (0.95).^[1:length(B)]; % contract zeros by 0.95

[H,w] = freqz(B,A); % frequency response

theta = angle(H); % phase response

thetauw = unwrap(theta); % unwrapped phase response

In Fig.7.6.2, the phase-response minimum has ``wrapped around'' to the top of the plot. In Fig.7.6.2, the phase response is continuous. We have contracted the zeros away from the unit circle in this example, because the phase response really does switch discontinuously by  radians when frequency passes through a point where the phases crosses zero along the unit circle (see Fig.7.3(b)). The unwrap function need not modify these discontinuities, but it is free to add or subtract any integer multiple of   in order to obtain the ``best looking'' discontinuity. Typically, for best results, such discontinuities

should alternate between  and  , making the phase response resemble a distorted ``square wave'', as in Fig.7.3(b). A more precise example appears in Fig.10.2.

Page 5: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

 

Phase Response

Page 6: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

 

Unwrapped Response

Figure 7.4: Phase response of a modified order 4 elliptic function lowpass filter cutting off at  .

GROUP DELAY

A more commonly encountered representation of filter phase response is called the group delay, defined by

For linear phase responses, i.e.,   for some constant  , the group delay and the phase delay are identical, and each may be interpreted as time delay

(equal to   samples when  ). If the phase response is nonlinear, then the relative phases of the sinusoidal signal components are generally altered by the filter. A nonlinear phase response normally causes a ``smearing'' of

Page 7: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

attack transients such as in percussive sounds. Another term for this type of phase distortion is phase dispersion. This can be seen below in §7.6.5.

An example of a linear phase response is that of the simplest lowpass

filter,  . Thus, both the phase delay and the group delay of the simplest lowpass filter are equal to half a sample at every frequency.

For any reasonably smooth phase function, the group delay   may be interpreted as the time delay of the amplitude envelope of a sinusoid at frequency   [63]. The bandwidth of the amplitude envelope in this interpretation must be restricted to a frequency interval over which the phase response is approximately linear. We derive this result in the next subsection.

Thus, the name ``group delay'' for   refers to the fact that it specifies the delay experienced by a narrow-band ``group'' of sinusoidal components which have frequencies within a narrow frequency interval about  . The width of this

interval is limited to that over which   is approximately constant.

DERIVATION OF GROUP DELAY AS MODULATION DELAY

Suppose we write a narrowband signal centered at frequency   as

(8.6)

where   is defined as the carrier frequency (in radians per sample), and   

is some ``lowpass'' amplitude modulation signal. The modulation   can be complex-valued to represent either phase or amplitude modulation or both. By

``lowpass,'' we mean that the spectrum of   is concentrated near dc, i.e.,

Page 8: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

for some  . The modulation bandwidth is thus bounded by  .

Using the above frequency-domain expansion of  ,   can be written as

which we may view as a scaled superposition of sinusoidal components of the form

with   near 0. Let us now pass the frequency component   through an LTI

filter  having frequency response

to get

(8.7)

Assuming the phase response   is approximately linear over the narrow

frequency interval  , we can write

where   is the filter group delay at  . Making this substitution in Eq. (7.7) gives

Page 9: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

 

where we also used the definition of phase delay,  , in the last step. In this expression we can already see that the carrier sinusoid is delayed by the phase delay, while the amplitude-envelope frequency-component is delayed by the group delay. Integrating over   to recombine the sinusoidal components

(i.e., using a Fourier superposition integral for  ) gives

 

where   denotes a zero-phase filtering of the amplitude envelope   

by  . We see that the amplitude modulation is delayed by   while

the carrier wave is delayed by  .

We have shown that, for narrowband signals expressed as in Eq. (7.6) as a modulation envelope times a sinusoidal carrier, the carrier wave is delayed by the filter phase delay, while the modulation is delayed by the filter group delay, provided that the filter phase response is approximately linear over the narrowband frequency interval.

GROUP DELAY EXAMPLES IN MATLAB

Figure 7.6 compares the group delay responses for a number of classic lowpass filters, including the example of Fig.7.2. The matlab code is listed in Fig.7.5. See, e.g., Parks and Burrus [64] for a discussion of Butterworth, Chebyshev, and Elliptic Function digital filterdesign. See also §I.2 for details on the Butterworth case. The various types may be summarized as follows:

Butterworth filters  are maximally flat in middle of the passband.

Page 10: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

Chebyshev Type I filters are ``equiripple'' in the passband and ``Butterworth'' in the stopband.

Chebyshev Type II filters are ``Butterworth'' in the passband and equiripple in the stopband.

Elliptic function filters are equiripple in both the passband and stopband.

Here, ``equiripple'' means ``equal ripple''; that is, the error oscillates with equal peak magnitudes across the band. An equiripple error characterizes optimality in the Chebyshev sense [64,78].

As Fig.7.6.4 indicates, and as is well known, the Butterworth filter has the flattest group delay curve (and most gentle transition from passband to stopband) for the four types compared. The elliptic function filter has the largest amount of ``delay distortion'' near the cut-off frequency (passband edge frequency). Fundamentally, the more abrupt the transition from passband to stopband, the greater the delay-distortion across that transition, for any minimum-phase filter. (Minimum-phase filters are introduced in Chapter 11.) The delay-distortion can be compensated by delay equalization, i.e., adding delay at other frequencies in order approach an overall constant group delay versus frequency. Delay equalization is typically carried out using an allpass filter (defined in §B.2) in series with the filter to be delay-equalized [1].

  

[Bb,Ab] = butter(4,0.5); % order 4, cutoff at 0.5 * pi

Hb=freqz(Bb,Ab);

Db=grpdelay(Bb,Ab);

[Bc1,Ac1] = cheby1(4,1,0.5); % 1 dB passband ripple

Hc1=freqz(Bc1,Ac1);

Dc1=grpdelay(Bc1,Ac1);

[Bc2,Ac2] = cheby2(4,20,0.5); % 20 dB stopband attenuation

Hc2=freqz(Bc2,Ac2);

Dc2=grpdelay(Bc2,Ac2);

[Be,Ae] = ellip(4,1,20,0.5); % like cheby1 + cheby2

He=freqz(Be,Ae);

Page 11: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

[De,w]=grpdelay(Be,Ae);

figure(1); plot(w,abs([Hb,Hc1,Hc2,He])); grid('on');

xlabel('Frequency (rad/sample)'); ylabel('Gain');

legend('butter','cheby1','cheby2','ellip');

saveplot('../eps/grpdelaydemo1.eps');

figure(2); plot(w,[Db,Dc1,Dc2,De]); grid('on');

xlabel('Frequency (rad/sample)'); ylabel('Delay (samples)');

legend('butter','cheby1','cheby2','ellip');

saveplot('../eps/grpdelaydemo2.eps');

Figure 7.5: Program (matlab) for comparing the amplitude and group-delay responses of four classic lowpass filter types: Butterworth, Chebyshev Type I, Chebyshev Type II, and Elliptic Function.

 

Amplitude Responses

Page 12: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

 

Group Delays

Figure 7.6: Comparison of amplitude and group-delay responses for classic lowpass-filter types Butterworth, Chebyshev Type I, Chebyshev Type II, and Elliptic Function. Plots generated by Octave 2.9.7 

and octave-forge 2006-07-09.

VOCODER ANALYSIS

The definitions of phase delay and group delay apply quite naturally to the analysis of the vocoder (``voice coder'') [21,26,54,76]. The vocoder provides a bank of bandpass filters which decompose the input signal into narrow spectral ``slices.'' This is the analysis step. For synthesis (often called additive synthesis), a bank of sinusoidal oscillators is provided, having amplitude and frequency control inputs. The oscillator frequencies are tuned to the filter center frequencies, and the amplitude controls are driven by the amplitude envelopesmeasured in the filter-bank analysis. (Typically, some data reduction or envelope modification has taken place in the amplitude envelope set.) With these oscillators, the band slices are independently regenerated and summed together to resynthesize the signal.

Suppose we excite only channel   of the vocoder with the input signal

Page 13: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

where   is the center frequency of the channel in radians per second,   is

the sampling interval in seconds, and the bandwidth of   is smaller than the channel bandwidth. We may regard this input signal as an amplitude

modulated sinusoid. The component  can be called the carrier wave,

while   is the amplitude envelope.

If the phase of each channel filter is linear in frequency within the passband (or at

least across the width of the spectrum   of  ), and if each channel filter has a flat amplitude response in its passband, then the filter output will be, by the analysis of the previous section,

(8.8)

where   is the phase delay of the channel filter at frequency  , and   is the group delay at that frequency. Thus, in vocoder analysis for additive synthesis, the phase delay of the analysis filter bank gives the time delay experienced by the oscillator carrier waves, while the group delay of the analysis filter bank gives the time delay imposed on the estimated oscillator amplitude-envelope functions.

Note that a nonlinear phase response generally results in  ,

and  for  . As a result, the dispersive nature of additive synthesis reconstruction in this case can be seen in Eq. (7.8).

NUMERICAL COMPUTATION OF GROUP DELAY

The definition of group delay,

Page 14: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

does not give an immediately useful recipe for computing group delay numerically. In this section, we describe the theory of operation behind the matlab function for group-delay computation given in §J.8.

A more useful form of the group delay arises from the logarithmic derivative of

the frequency response. Expressing the frequency response   in polar form as

yields the following logarithmic decomposition of magnitude and phase:

Thus, the real part of the logarithm of the frequency response equals the log amplitude response, while the imaginary part equals the phase response.

Since differentiation is linear, the logarithmic derivative becomes

where   and   denote the derivatives of   and  , respectively, with respect to  . We may therefore express the group delay as

im im

Consider first the FIR case in which  , with

(8.9)

Page 15: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

In this case, the derivative is simply

 

where   denotes ``  ramped'', i.e., the  th coefficient of the polynomial   

is  , for  . In matlab, we may compute Br from B via the following statement:

Br = B .* [0:M]; % Compute ramped B polynomial

The group delay of an FIR filter   can now be written as

im im re

In matlab, the group delay, in samples, can be computed simply as

D = real(fft(Br) ./ fft(B))

where the fft, of course, approximates the Discrete Time Fourier Transform (DTFT). Such sampling of the frequency axis by this approximation is information-preserving whenever the number of samples (FFT length) exceeds the polynomial order  . The ratio of sampled DTFTs, however, is undersampled, in

general. In fact, we may have   at some frequencies (``zeros on the unit circle''). The grpdelay matlab utility in §J.8 watches out for division by zero, and simply sets the group delay to zero at such frequencies. Note that the true group delay approaches infinite magnitude as either a zero or pole approaches the unit circle.

Finally, when there are both poles and zeros, we have

Page 16: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

where   is given in Eq. (7.9), and

(8.10)

Straightforward differentiation yields

(8.11)

and this can be implemented analogous to the FIR case discussed above. However, a faster algorithm (usually) results from converting the IIR case to the FIR case:

(8.12)

where

may be called the ``flip-conjugate'' or ``Hermitian conjugate'' of the

polynomial  .8.4In matlab, the C polynomial is given by

C = conv(B,fliplr(conj(A)));

It is straightforward to show (Problem 11) that

Page 17: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

The phase of the IIR filter   is therefore

 

and the group delay computation thus reduces to the FIR case:

re

This method is implemented in §J.8.

Finite impulse response (FIR) filter design methodsMost FIR filter design methods are based on ideal filter approximation. The resulting filter approximates the ideal characteristic as the filter order increases, thus making the filter and its implementation more complex.The filter design process starts with specifications and requirements of the desirable FIR filter. Which method is to be used in the filter design process depends on the filter specifications and implementation. This chapter discusses the FIR filter design method using window functions.Each of the given methods has its advantages and disadvantages. Thus, it is very important to carefully choose the right method for FIR filter design. Due to its simplicity and efficiency, the window method is most commonly used method for designing filters. The sampling frequency method is easy to use, but filters designed this way have small attenuation in the stopband.As we have mentioned above, the design process starts with the specification of desirable FIR filter.

2.2.1 Basic concepts and FIR filter specificationFirst of all, it is necessay to learn the basic concepts that will be used further in this book. You should be aware that without being familiar with these concepts, it is not

Page 18: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

possible to understand analyses and synthesis of digital filters.Figure 2-2-1 illustrates a low-pass digital filter specification. The word specification actually refers to the frequency response specification.

Figure 2-2-1a. Low-pass digital filter specification

Page 19: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

Figure2-2-1b. Low-pass digital filter specification

ωp – normalized cut-off frequency in the passband;

ωs – normalized cut-off frequency in the stopband;

δ1 – maximum ripples in the passband;

δ2 – minimum attenuation in the stopband [dB];

ap – maximum ripples in the passband; and

as – minimum attenuation in the stopband [dB].

Page 20: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

Frequency normalization can be expressed as follows:

where:

fs is a sampling frequency;

f is a frequency to normalize; and

ω is normalized frequency.Specifications for high-pass, band-pass and band-stop filters are defined almost the same way as those for low-pass filters. Figure 2-2-2 illustrates a high-pass filter specification.

Page 21: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

Figure 2-2-2a. High-pass digital filter specification

Page 22: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

Figure 2-2-2b. High-pass digital filter specification

Comparing these two figures 2-2-1 and 2-2-2, it is obvious that low-pass and high-pass filters have similar specifications. The same values are defined in both cases with the difference that in the later case the passband is substituded by the stopband and vice versa.Figure 2-2-3 illustrates a band-pass filter specification.

Page 23: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

Figure 2-2-3a. Band-pass digital filter specification

Page 24: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

Figure 2-2-3b. Band-pass digital filter specification

Figure 2-2-4 illustrates a band-stop digital filter specification.

Page 25: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

Figure 2-2-4a. Band-stop digital filter specification

Page 26: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

Figure 2-2-4b. Band-stop digital filter specification

2.2.2 Z-transformThe Z-transform is performed upon discrete-time signals. It converts a discrete time-domain signal into a complex frequency-domain representation. It is very suitable for analysing discrete time-domain signals and systems. The z-transform is derived from the Fourier discrete time-domain transformation and is considered the basic operation in digital filter design process.The Z-transform is defined as:

where z is the complex number.Example:Assume that samples of a discrete-time signal x(n) are known. It is necessary to transform this signal through the ztransform and Fourier fransform.

x(n)={1,2,3,4,5,4,3,2,1} ; 0 ≤ n ≤ 8z-transform is defined as follows:

Page 27: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

It becomes:

The last expression represents the z-transform of the given signal.The Fourier transform can be found by rewriting the previous expression in terms of z as z=ejω. It further becomes:

Figure 2-2-5 illustrates the frequency spectrum of the given signal.

Page 28: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

Figure 2-2-5. Frequency spectrum of the given signal

Comparing Z and Fourier transforms, it is easy to notice some similarities between them:

In polar coordinate system, the complex number z may be expressed as:

The two last expressions lead us to the conclusion that the Fourier transform is just a special form of the z-transform for r=1.In the z plane, the Fourier transform is represented as a unit circle, which can be seen in Figure 2-2-6 below.

Page 29: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

Figure 2-2-6. Fourier transform in the z plane

2.2.2.1 Transform function of discrete-time systemsThe Z-transform is primarily used for finding the transfer function of linear discrete-time systems. When the transfer function is found, it is necessary to consider its zeros and poles in the z plane. The transfer function of discrete-time systems is defined as:

Page 30: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

where:

bi are the feedforward filter coefficients (non-recursive part);

aj are the feedback filter coefficients (recursive part);

H0 is a constant;

qi are the zeros of the transfer function; and

pj are the poles of the transfer function.The recursive part of the transfer function is actually a feedback of discrete-time system. As we previously mentioned, FIR filters do not have this recursive part of the transfer function, so the expression above can be simplified in the following way:

The impulse response of discrete-time system is obtained from inverse z-transform of the transfer function i.e. the transfer function of discrete-time system is actually the Z-transform of impulse response:

where h(n) is the impulse response of discrete-time system.

Page 31: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

Figure 2-2-7. Block diagram of a linear discrete-time system

In the time domain, the discrete-time system, shown in Figure 2-2-7, can also be expressed as the convolution of the input signal x(n) and the impulse response h(n) of the system:

In the frequency domain, the discrete-time system, shown in Figure 2-2-7, can be expressed as the multiplication of the Z-transform input signal X(z) and the transfer function H(z) of the system:

which further gives:

The first way of representing discrete-time systems is more suitable for software implementation itself, whereas the later is more suitable for analyse, hardware implementation (described later) and synthesis, i.e. discrete-time system design.Example:The impulse response of a 10-th order FIR filter designed using the Hamming window (discussed in the next chapter) is:

Page 32: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

h(n) = {0, - 0.0127, - 0.0248, 0.0638, 0.2761, 0.4, 0.2761, 0.0638, - 0.0248, - 0.0127, 0}The transfer function of this filter is found via the ztransform of impulse response:

Using the following expression:

it is possible to yield the transfer function of the fixed normalized frequency. If for example ω = 0.2π then:

Page 33: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

One example of hardware realization of this filter is illustrated in Figure 2-2-8.

Figure 2-2-8. FIR filter realization

Software realization requires a buffer of minimum length 9. Buffers are usually circular and their length can be expressed as 2^n, which in this case means that the circular buffer is of length 16=2^4.

Page 34: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

2.2.2.2 Effect of the poles and zeros of the transfer functionThe location of zeros and poles of the transfer function is very important for discretetime system analyses and synthesis. According to their position it is possible to test stability of a discrete-time system, detect round-off errors made due to software implementation of a filter as well as errors in the coefficients encountered during hardware implementation of a filter.In order that a discrete-time system is stable, all poles of the discrete-time system transfer function must be located inside the unit circle, as shown in Figure 2-2-6. If this requirement is not satisfied, the system becomes unstable, which is very dangerous. The location of zeros doesn’t affect the stabilty of discrete-time systems. Recalling that FIR flters do not have a feedback, which further means that the transfer function has no poles. This causes a FIR filter to be always stable. Filter stability will be discussed in more details along with IIR filters which have potential to become unstable because of the feedback they have. This property of FIR filters actually represents their essential adventage. From now on, only the zeros of the transfer function will be discussed in this chapter.An error in coefficient representation is always produced due to software and hardware implementation. In software implementation, an error is triggered by the finite word-length effect, whereas in hardware implementation, it ocurrs due to impossibility of representing the coefficients with absolute accuracy. The result in both cases is that the value of coefficients differs from their value obtained in design process. Such errors cause frequency deviation of discrete-time system designed.Frequency deviation depends on the spacing between the zeros of the FIR filter transfer function. FIR filter coefficient error affects more the frequency characteristic as the spacing between the zeros of the transfer function narrows. This property is particularly typical of highorder filters because their zeros are very close each other. However, slight errors in coefficient representation may cause large frequency deviations.Figure 2-2-9 illustrates the required and obtained frequency characteristic of a FIR filter. The finite word-length effect on the transform function of a FIR filter is clearly marked. Assume that a 50-th order low-pass FIR filter with normalized cut-off frequency of 0.25 Hz is designed using the Hann window.

Page 35: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

Figure 2-2-9. Deviation from required frequency characteristic

The frequency deviation shown in Figure 2-2-9 is basically slight deviation, even though it is very large at certain points. The minimum attenuation and the width of transition region of the resulting IIR filter remain unchanged, so that such deviation is acceptable. However, as this is not a common case, it is necessary to be very careful when designing high order filters because the transfer function zeros get closer, while more affecting the resulting frequency characteristic.

2.2.3 Ideal filter approximationThe ideal filter frequency response is used when designing FIR filters using window functions. The objective is to compute the ideal filter samples. FIR filters have finite impulse response, which means the ideal filter frequency sampling must be performed in a finite number of points. As the ideal filter frequency response is infinite, it is easy to produce sampling errors. The error is less as the filter order increases.Figure 2-2-10 illustrates the transfer functions of four standard ideal filters.

Page 36: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

Figure 2-2-10. Transfer functions of four standard ideal filters

The ideal filter frequency response can be computed via inverse Fourier transform. The four standard ideal filters frequency responses are contained in the table 2-2-1 below.

Page 37: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

Table 2-2-1. The frequency responses of four standard ideal filters

The value of variable n ranges between 0 and N, where N is the filter order. A constant M can be expressed as M = N / 2. Equivalently, N can be expressed as N = 2M.The constant M is an integer if the filter order N is even, which is not the case with odd order filters. If M is an integer (even filter order), the ideal filter frequency response is symmetric about its Mth sample which is found via expression shown in the table 2-2-1 above. If M is not an integer, the ideal filter frequency response is still symmetric, but not about some frequency response sample.Since the variable n ranges between 0 and N, the ideal filter frequency response has N+1 sample.If it is needed to find frequency response of a non-standard ideal filter, the expression for inverse Fourier transform must be used:

Page 38: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

Non-standard filters are rarely used. However, if there is a need to use some of them, the integral above must be computed via various numerical methodes.

2.2.4 FIR filter design using window functionsThe FIR filter design process via window functions can be split into several steps:

1.1. Defining filter specifications;1.1. Specifying a window function according to the filter specifications;1.1. Computing the filter order required for a given set of specifications;1.1. Computing the window function coefficients;1.1. Computing the ideal filter coefficients according to the filter order;1.1. Computing FIR filter coefficients according to the obtained window function and

ideal filter coefficients;1.1. If the resulting filter has too wide or too narrow transition region, it is necessary to

change the filter order by increasing or decreasing it according to needs, and after that steps 4, 5 and 6 are iterated as many times as needed.The final objective of defining filter specifications is to find the desired normalized frequencies (ωc, ωc1, ωc2), transition width and stopband attenuation. The window function and filter order are both specified according to these parameters.Accordingly, the selected window function must satisfy the given specifications. This point will be discussed im more detail in the next chapter (2.3).After this step, that is, when the window function is known, we can compute the filter order required for a given set of specifications. One of the techniques for

Page 39: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

computing is provided in chapter 2.3.When both the window function and filter order are known, it is possible to calculate the window function coefficients w[n] using the formula for the specified window function. This issue is also covered in the next chapter.After estimating the window function coefficients, it is necessary to find the ideal filter frequency samples. The expressions used for computing these samples are discussed in section 2.2.3 under Ideal filter approximation. The final objective of this step is to obtain the coefficients hd[n]. Two sequencies w[n] and hd[n] have the same number of elements.The next step is to compute the frequency response of designed filter h[n] using the following expression:

Lastly, the transfer function of designed filter will be found by transforming impulse response via Fourier transform:

or via Z-transform:

If the transition region of designed filter is wider than needed, it is necessary to increase the filter order, reestimate the window function coefficients and ideal filter frequency samples, multiply them in order to obtain the frequency response of designed filter and reestimate the transfer function as well. If the transition region is narrower than needed, the filter order can be decreased for the purpose of optimizing hardware and/or software resources. It is also necessary to reestimate the filter frequency coefficients after that. For the sake of precise estimates, the filter order should be decreased or increased by 1.

Page 40: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

2.2.5 FIR filter realizationFIR filter transfer function can be expressed as:

The frequency response realized in the time domain is of more interest for FIR filter realization (both hardware and software). The transfer function can be found via the z-transform of a FIR filter frequency response. FIR filter output samples can be computed using the following expression:

where:

x[k] are FIR filter input samples;

h[k] are the coefficients of FIR filter frequency response; and

y[n] are FIR filter output samples.A good property of FIR filters is that they are less sensitive to the accuracy of constants than IIR filters of the same order.There are several types of FIR filter realization. This chapter covers direct, direct transpose and cascade realizations which are very convenient for the hardware implementation of a filter. As for the software implementation, direct and optimized realizations will be discussed in this book.

2.2.5.1 Direct realizationDirect realization of FIR filter is based on the direct implementation of this expression:

Page 41: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

Direct realization is also known as a transversal filter.Figure 2-2-11 illustrates the block diagram describing the hardware direct realization of a FIR filter.

Page 42: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

Figure 2-2-11. FIR filter direct realization

For direct realization structure, the multiplication constants are the same as the transfer function coefficients, i.e. the FIR filter frequency response coefficients.As for software direct realization of the FIR filter, it is necessary to provide a buffer for minimum N samples, where N is the number of FIR filter coefficients. For its simplicity and speed, most commonly used buffer is so called circular buffer the length of which can be expressed as 2^k. The value of the constant k is a minimum value for which the expression N ≤ 2^k is valid. Accordingly:

where the operator represents rounding down to a less value.

Figure 2-2-12. Circular buffer of length 16 = 2^4

The algorithm used for software direct realization of FIR filter consists of:

1.1. Reading the samples of a signal being filtered;1.1. Storing a new sample on the first available location; and1.1. Performing a convolution operation upon filter coefficients (frequency response

coefficients), resulting in a FIR filter output sample.Since the buffer is 16 bits wide, circular buffer addressing is performed using addressing mode 16:

Page 43: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

Example: Assuming that a filter used in this example is a 5th order FIR filter. Design this filter using direct realization with circular buffer. The buffer length needs to be 2^k.The buffer length is obtained in the following way:

This means that the minimum length of circular buffer is 2^3 = 8.The contents of the buffer after receiving the first 10 samples is shown in the table 2-2-2. Input samples are denoted by x[n], whereas the shaded cells denote buffer locations that have been changed. 

STEP ADDR. 7

ADDR. 6

ADDR. 5

ADDR. 4

ADDR. 3

ADDR. 2

ADDR. 1

ADDR. 0

0

1 x[0]

2 x[1] x[0]

3 x[2] x[1] x[0]

4 x[3] x[2] x[1] x[0]

5 x[4] x[3] x[2] x[1] x[0]

6 x[5] x[4] x[3] x[2] x[1] x[0]

Page 44: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

7 x[6] x[5] x[4] x[3] x[2] x[1] x[0]

8 x[7] x[6] x[5] x[4] x[3] x[2] x[1] x[0]

9 x[7] x[6] x[5] x[4] x[3] x[2] x[1] x[8]

10 x[7] x[6] x[5] x[4] x[3] x[2] x[9] x[8]

Table 2-2-2. Input circular buffer after receiving 10 samplesFor software realization, filtering of input samples is performed as per formula below:

2.2.5.2 Direct transpose realizationDirect transpose realization is similar to direct realization in many ways. Speaking about software implementation, the direct transpose realization must also have a buffer of minimum length N, where N is the number of FIR filter coefficients.Figure 2-2-13 illustrates the block diagram describing hardware direct transpose realization of a FIR filter.

Page 45: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of
Page 46: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

Figure 2-2-13. Direct transpose realization of a FIR filter

There are no significant differences between direct and direct transpose realizations. Both structures have the same number of delay elements, the same number of multipliers and the same coefficients to perform multiplication upon.

2.2.5.3 Cascade realizationCascade realization, very convenient for its modular structure, is commonly used for FIR filter hardware realization. When using this realization, a filter is divided into several low-order sections. The second-order sections are most commonly used. Individual sections are mostly in direct form realization, although they can also be in direct transpose form realization. The cascade realization is normally used for higher order filter realization.The transfer function of the cascade realization looks as follows:

where:

M is the number of sections; and

ak1, ak2 are the multiplication coefficients of section k.Figure 2-2-14 illustrates the block diagram describing the hardware cascade realization of a FIR filter.

Figure 2-2-14. FIR filter cascade realization

The number of multipliers, adders and delays is the same as for direct realization. The main advantage of the cascade realization is its modularity, otherwise very

Page 47: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

convenient for hardware implementation. The cascade of second order sections is important for the realization of the filters of arbitrary order.

2.2.5.4 Optimized realizationOptimized realization has less, but more demanding multipliers for realization. This realization is most commonly used for software implementation of FIR filters, because a reduction in the number of multipliers enhances the process of convolution (samples filtering process).Optimized realization utilizes the symmetry of frequency response coefficients. There are also anti-symmetric FIR filters that are beyond the scope of this book. Anyway, the optimized realization may be used for these filters as well.The symmetry of the coefficients of FIR filter frequency response can be expressed by equation below:

This symmetry makes it possible for the transfer function to be expressed as follows:

Figure 2-2-15 illustrates the block diagram of optimized realization for even N, whereas Figure 2-2-16 illustrates that for odd N.

Page 48: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

Figure 2-2-15. Optimized realization for odd frequency response

Figure 2-2-16. Optimized realization for even frequency response

FIR Filters by Windowing

Page 49: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

The design of FIR filters using windowing is a simple and quick technique. There are many pages on the web that describe the process, but many fall short on providing real implementation details. Hopefully, this page contains all the required information to put together your own algorithm for creating low pass, high pass, band pass and band stop filters based on a number of different windows. A complete set of C functions is also provided which can be easily translated to other languages if required.

If you just want to see it all working, jump straight to the code section. All the data for the graphs on this page was generated using this code, then plotted using gnuplot.

Ideal Low Pass Filter Impulse Response Windowing High Pass, Band Pass and Band Stop Filters The Kaiser Window C Code Implementation Useful Links

Ideal Low Pass Filter Impulse ResponseThe frequency response of an ideal low pass filter is shown in the image below. The frequency axis is normalised with respect to the sampling frequency. The cut-off, or transition frequency (ft) is always between 0 and 0.5, as 0.5 represents the Nyquist frequency. As you would expect from a low pass filter, all frequencies below ft are passed, where-as all those above are stopped.

The impulse response of this ideal low pass filter is shown below, it is a sinc function. The equation is shown next to the plot. If we could create a filter with this impulse response we would have an ideal low pass filter like that shown above. A set of Gnuplot commands are also given for recreating this graph.

Impulse response of ideal LPF (ft=0.25)

Gnuplot commands for Impulse Response (ft=0.25)

> h(x)=sin(2*pi*0.25*x)/(pi*x)> set xrange[-50:50]> set yrange[-0.15:0.5]> set samples 1000> set grid> unset key> plot h(x)

Below is a plot of impulse responses for different values of ft.

Page 50: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

Sinc function for different values of normalised transition frequency

Gnuplot commands

> h(x)=sin(2*pi*ft*x)/(pi*x)> set xrange[-20:20]> set samples 1000> set grid lt rgbcolor "#BBBBBB"> plot ft=0.1, h(x) t "ft=0.1", \> ft=0.25, h(x) t "ft=0.25", \> ft=0.4, h(x) t "ft=0.4"

Unfortunately it is not as easy as that. Given the non-recursive filter structure like that shown below, there are two problems with creating this ideal impulse response.

First, the sinc function is infinite in the x direction, the ripples keep on going in both directions. However, the FIR filter only allows us to create finite impulse responses, the number of filter taps must be finite.

Second, the impulse response is non-casual, this means an implementation would require samples from the future.

Non-Recursive, Finite Impulse Response FilterLuckily, the solutions to these issues are quite simple. First, a window is applied to the sinc function such that only a portion of the impulse response is actually used. Secondly, the impulse response is shifted such that the filter only operates on available samples (those from the past). These techniques are demonstrated in the the following example.

Page 51: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

Low Pass Filter Example

Filter weights M=20, ft=0.23Consider the filter with the properties given below.

Filter Type: Low Pass Sampling Frequency: 2000 Hz Cut off Frequency: 460 Hz Filter Length (# weights): 21

The plot to the right shows the filter weights that have been calculated using the equations below.

M - This is the filter order, it is always equal to the number of taps minus 1 ft - This is the normalised transition frequency.

There are 21 weights that fit on the ideal impulse response curve. It can be seen how the impulse response is effectively cropped by only using 21 weights.

Note: When calculating weight values with an odd number of weights, a divide by zero will occur at n=M/2. Therefore, based on l'Hôpital's rule, the value of 2ft is used.

Page 52: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

The actual weight values are:

Weight #,

n0, 20 1, 19 2, 18 3, 17 4, 16 5, 15 6, 14 7, 13 8, 12 9, 11 10

Weight

Value

w(n)

0.030273

0.015059

-0.0335

95

-0.0289

85

0.036316

0.051504

-0.0383

37

-0.0986

52

0.039580

0.315800

0.460000

The frequency response for the filter is shown below. It can clearly be seen that the transition frequency occurs at the correct point, 460 Hz.

The large amount of ripple visible on the non-dB plot is due to the rather crude approach of truncating the infinite ideal impulse response. The approach that has just been used is called applying a Rectangular Window. The next section describes different window types that can decrease the ripple and improve the attenuation of the stop band.

Page 53: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

WindowingApplying a window to the sinc function weights provides extra control over the characteristics of the filter. The image to the right illustrates the process.

First, the normal sinc weights are calculated as described above. Then the window weights are calculated, in this case a Hamming Window has been used, the equation is below. The two sets of weights are multiplied together to create the final set of filter weights.

Hamming Windowing Equation

Once again, M is the order of the filter, which is equal to the filter length - 1.

Page 54: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

The plots below show the effect on the filter's frequency response before applying the Hamming Window (green) and after (red). The trick is to select the window type and filter length that will give a filter with the correct rate of roll-off and level of attenuation in the stop band.

Different Windows

The table below gives the equations for different window types.

Window Type Weight Equation

Rectangular

Bartlett

Hanning

Hamming

Page 55: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

Blackman

The image below shows the effect of different windows on the frequency response of a 28th Order (29 weights) low pass filter, with a cut-off frequency of 5000Hz and sampling frequency of 44100Hz.

Frequency Response and Weight Values of different windows types

High Pass, Band Pass and Band Stop Filters

Page 56: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

The high pass filter is made up from a low pass and an all pass filter. The image to the right demonstrates how this works. If you take an all pass filter and subtract the output of the low pass, you are left with a high pass filter.

The all pass filter is of the same order as the low pass filter. All the weight values are 0.0 apart from the centre weight which has a value 1.0. Note: This places the constraint that when creating a high pass filter in this way, the order must be even (an odd number of taps).

The equation for calculating the weights (before windowing) is shown below. Comparing this equation with the low pass filter it is easy to see the subtraction and the all pass filter's single 1.0 weight applied in the case of n=M/2. Windows are applied in exactly the same way as with the low pass filter.

Below is a Low Pass and High Pass filter frequency response with the same transition frequency.

The band stop and band pass are achieved in a similar way. The equations for calculating the weights are shown below. For both band pass and band stop, the filter order needs to be even (an odd filter length). Once again, windows are applied across the weights as before.

Page 57: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

The Kaiser WindowThe Kaiser Window is specified differently to the previous windows. Rather than specifying the filter order, the amount of ripple and the transition band width are specified. The image below shows the meaning of these two parameters.

Once you have decided on the amount of ripple and transition width, using the equations below you can calculate the values for A and tw. These values can be used to calculate the filter order, M and a further parameter, β. In these equations the transition width and sampling frequency are in Hz.

Page 58: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

Once you have values for M and β, you can finally calculate the actual window weights. The Kaiser window equation makes use of another function I0, this is a Zeroth Order Modified Bessel Function. Although it expands to infinity, the denominator quickly becomes very large, therefore you only really need to calculate I0(x) up to around i=20.

Below are some examples weights for the following Kaiser Window based low pass filter:

Ripple: 0.01 Cut-off Frequency: 250Hz Transition Window: 100Hz Sampling Frequency: 1000Hz Filter Order, M: 23 Beta: 3.395321

Weight #, n

0, 23 1, 22 2, 21 3, 20 4, 19 5, 18 6, 17 7, 16 8, 15 9, 14 10, 13 11, 12

Weight

Value

w(n)

-0.002896

-0.004885

0.007528

0.010980

-0.015463

-0.021317

0.029123

0.039980

-0.056254

-0.084142

0.146464

0.448952

The filter's frequency response is show below, for comparison a Blackman window based filter with the same number of weights is also shown. It can be seen that the transition frequency of 250Hz is correct, as is the transition width of 100Hz.

Page 59: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

Alternate Kaiser Window Equation

Below is a rearrangement of the Kaiser Window equation.

Page 60: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

fir1Window-based FIR filter design

collapse all in page

Syntax

b = fir1(n,Wn)

b = fir1(n,Wn,ftype)

b = fir1(___,window)

b = fir1(___,scaleopt)

Page 61: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

Descriptionexample

b = fir1(n,Wn) uses a Hamming window to design an nth-order lowpass, bandpass, or multiband FIR filter with linear phase. The filter type depends on the number of elements of Wn.

example

b = fir1(n,Wn,ftype) designs a lowpass, highpass, bandpass, bandstop, or multiband filter, depending on the value of ftype and the number of elements of Wn.

example

b = fir1(___,window) designs the filter using the vector specified in window and any of the arguments from previous syntaxes.b = fir1(___,scaleopt) additionally specifies whether or not the magnitude response of the filter is normalized.Note:   Use fir2 for windowed filters with arbitrary frequency response.

Examplescollapse all

FIR Bandpass FilterTry This Example

Design a 48th-order FIR bandpass filter with passband   rad/sample. Visualize its magnitude and phase responses.

b = fir1(48,[0.35 0.65]);freqz(b,1,512)

Page 62: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

FIR Highpass FilterTry it in MATLAB

Load chirp.mat. The file contains a signal, y, that has most of its power above Fs/4, or half the Nyquist frequency. The sample rate is 8192 Hz.

Design a 34th-order FIR highpass filter to attenuate the components of the signal below Fs/4. Use a cutoff frequency of 0.48 and a Chebyshev window with 30 dB of ripple.

load chirp

t = (0:length(y)-1)/Fs;

bhi = fir1(34,0.48,'high',chebwin(35,30));freqz(bhi,1)

Filter the signal. Display the original and highpass-filtered signals. Use the same y-axis scale for both plots.

outhi = filter(bhi,1,y);

subplot(2,1,1)plot(t,y)title('Original Signal')ys = ylim;

subplot(2,1,2)plot(t,outhi)title('Highpass Filtered Signal')

Page 63: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

xlabel('Time (s)')ylim(ys)

Design a lowpass filter with the same specifications. Filter the signal and compare the result to the original. Use the same y-axis scale for both plots.

blo = fir1(34,0.48,chebwin(35,30));

outlo = filter(blo,1,y);

subplot(2,1,1)plot(t,y)title('Original Signal')ys = ylim;

subplot(2,1,2)plot(t,outlo)title('Lowpass Filtered Signal')xlabel('Time (s)')ylim(ys)

Page 64: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

Multiband FIR FilterTry This Example

Design a 46th-order FIR filter that attenuates normalized frequencies below   rad/sample and between  and   rad/sample. Call it bM.

ord = 46;

low = 0.4;bnd = [0.6 0.9];

bM = fir1(ord,[low bnd]);Redesign bM so that it passes the bands it was attenuating and stops the other frequencies. Call the new filter bW. Use fvtool to display the frequency responses of the filters.

bW = fir1(ord,[low bnd],'DC-1');

hfvt = fvtool(bM,1,bW,1);legend(hfvt,'bM','bW')

Page 65: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

Redesign bM using a Hann window. (The 'DC-0' is optional.) Compare the magnitude responses of the Hamming and Hann designs.

hM = fir1(ord,[low bnd],'DC-0',hann(ord+1));

hfvt = fvtool(bM,1,hM,1);legend(hfvt,'Hamming','Hann')

Page 66: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

Redesign bW using a Tukey window. Compare the magnitude responses of the Hamming and Tukey designs.

tW = fir1(ord,[low bnd],'DC-1',tukeywin(ord+1));

hfvt = fvtool(bW,1,tW,1);legend(hfvt,'Hamming','Tukey')

Page 67: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

Input Argumentscollapse all

n — Filter orderinteger scalarFilter order, specified as an integer scalar.

For highpass and bandstop configurations, fir1 always uses an even filter order. The order must be even because odd-order symmetric FIR filters must have zero gain at the Nyquist frequency. If you specify an odd n for a highpass or bandstop filter, then fir1 increments n by 1.

Data Types: doubleWn — Frequency constraintsscalar | two-element vector | multi-element vectorFrequency constraints, specified as a scalar, a two-element vector, or a multi-element vector. All elements of Wn must be strictly greater than 0 and strictly smaller than 1, where 1 corresponds to the Nyquist frequency: 0 < Wn < 1. The Nyquist frequency is half the sample rate or π rad/sample.

If Wn is a scalar, then fir1 designs a lowpass or highpass filter with cutoff frequency Wn. The cutoff frequency is the frequency at which the normalized gain of the filter is –6 dB.

If Wn is the two-element vector [w1 w2], where w1 < w2, then fir1 designs a bandpass or bandstop filter with lower cutoff frequency w1 and higher cutoff frequency w2.

If Wn is the multi-element vector [w1 w2 ... wn], where w1 < w2 < … < wn, then fir1 returns an nth-order multiband filter with bands 0 < ω < w1, w1 < ω < w2,  …, wn < ω < 1.Data Types: double

Page 68: PHASE AND GROUP DELAY - wingsofaero.inwingsofaero.in/wp-content/uploads/2018/12/Linear-Phase-FIR-filter.docx  · Web viewThe finite word-length effect on the transform function of

ftype — Filter type'low' | 'bandpass' | 'high' | 'stop' | 'DC-0' | 'DC-1'Filter type, specified as one of the following:

'low' specifies a lowpass filter with cutoff frequency Wn. 'low' is the default for scalar Wn. 'high' specifies a highpass filter with cutoff frequency Wn. 'bandpass' specifies a bandpass filter if Wn is a two-element vector. 'bandpass' is the default

when Wn has two elements. 'stop' specifies a bandstop filter if Wn is a two-element vector. 'DC-0' specifies that the first band of a multiband filter is a stopband. 'DC-0' is the default

when Wn has more than two elements. 'DC-1' specifies that the first band of a multiband filter is a passband.

window — WindowvectorWindow, specified as a vector. The window vector must have n + 1 elements. If you do not specify window, then fir1 uses a Hamming window. For a list of available windows, see Windows.

fir1 does not automatically increase the length of window if you attempt to design a highpass or bandstop filter of odd order.

Example: kaiser(n+1,0.5) specifies a Kaiser window with shape parameter 0.5 to use with a filter of order n.

Example: hamming(n+1) is equivalent to leaving the window unspecified.

Data Types: doublescaleopt — Normalization option'scale' (default) | 'noscale'Normalization option, specified as either 'scale' or 'noscale'.

'scale' normalizes the coefficients so that the magnitude response of the filter at the center of the passband is 1 (0 dB).

'noscale' does not normalize the coefficients.

Output Argumentscollapse all

b — Filter coefficientsrow vectorFilter coefficients, returned as a row vector of length n + 1. The coefficients are sorted in descending powers of the Z-transform variable z:

B(z) = b(1) + b(2)z + … + b(n+1)z–n.