DIGITAL SIGNAL PROCESSING  

FIR Filter Disign and Implementation


Introduction to Discrete-Time Systems and z-Transform

FIR Filter Design

Window Functions

Procedure



I. Introduction to Discrete-Time Systems and z-Transform

A discrete-time system is a computational process for tranforming the input signal to output signal, both of which are of discrete-time signals. Such a system can always be represented using the following block diagram.

The operation in Fig. 1 is given by the notation

If the impulse response of the system is given as h[n], then the output signal y[n] can be expressed by the convolution of the input signal x[n] and the impulse response h[n] as

          (1)

Finite impulse response (FIR) filter is the filter that operates on discrete-time signals, and the relationship between the input and output signals of the FIR filter can be generalized with the same form as Eq. (1), which is

          (2)

where the coefficients bk are not necessarily the same and M is the order of the filter. From Eq. (2) it is evident that the computation of y[n] involves the samples of x[l] for l=n, n-1, n-2, ..., n-M. Eq. (2) shows that an FIR filter can be implemented with the knowledge of the input x[n] at time n and of the delayed inputs x[n-k]. Taking z-transform on both sides of Eq. (2) gives the z-domain representation between the input and output, which is

          


return to top


II. FIR Filter Design

The design of a FIR concentrates on the determination of the coefficients bk in Eq. (2) since the FIR filter can be wholely characterized by its transfer function H(z). Due to the fact that FIR filter can guarantee linear phase, what we need to take care about is the magnitude reponse of the transfter function. Consequently, we will use the magnitude reponse of H(z) to approximate a desired magnitude response.

The desired transfer function is

          (3)

where Cn are the Fourier series coefficients and it is equal to bk in Eq. (2). Eq. (3) can be normalized by setting v=f/FN, where FN is the Nyquist frequency. Thus, Eq. (3) becomes

          (4)

where Cn are defined by

          

In order to obtain a realizable filter, Eq. (4) must be truncated as

          (5)

The truncation of the infinite series with a finite number of terms results in ignoring the contribution of the terms outside a rectangular window function between -Q and +Q.

Let

          

then Eq. (5) becomes

          (6)

Fig. 2 shows the desired transfer functions Hd ideally represented for the frequency-selective filters:


return to top


III. Window Functions

In Eq. (6), we truncated the infinite series in the transfer function equation by applying a rectangular window function with an amplitude of 1 between -Q and +Q, and ignoring the coefficients outside that window. The following window functions are commonly used in the design of FIR filter.


return to top


IV. The Procedure

This laboratory experiment consists of three exercises, each of which is a real-time excercise showing the properties discussed above. All the programs which will be used in this experiment are accessed by C:\DSP\CH4 and C:\DSP\APPB of each station in the lab and the listings of these programs are shown in the chapter 4 of "Digital Signal Processing - Laboratory Experiments Using C and the TMS320C31 DSK". Please read chapter 4, then follow the step-by-step procedure very carefully and complete all the lab exercises. Call the TA for assistance if you have any problems at any time.

  1. Set up the connection.
    1. Connect the output of the function generator to the AIC primary input "IN" on the DSK board;
    2. Connect the AIC output "OUT" on the DSK board to the oscilloscope input CHAN 1;
    3. Turn both the oscilloscope and the function generator on;
    4. Keep a BNC-BNC cable in order to verify the signal generated by the function generator through the oscilloscope.

  2. Exercise I: Gneneric FIR filter run-time program
  3. In this lab exercise, you will use the Example 4.3 FIRNC.ASM of chapter 4 to test different filter characteristics. Follow the steps below to finish this exercise:

    1. Create a batch file. The batch file FIR.BAT can be used to implement different types of filters by simplely changing the coefficient set. Use any text editor (such as NOTEPAD) to create the FIR.BAT file, which should contain the following commands:
    2.             copy %1 FIR.COF
                  DSK3A FIRNC.ASM
                  DSK3LOAD FIRNC.DSK
      
      Save your batch file in the C:\DSP\CH4 directory.
    3. Implement a bandpass filter. Enter C:\DSP\CH4, run DSK3D and then reset the board. Type DOS in the DSK debugger to go to DOS shell and type
                  FIR BP45.COF
      
      to invoke the batch file you just created, where BP45.COF is the coefficient file for the bandpass filter which looks like:
    4. ;BP45.COF - FIR BANDPASS COEFFICIENTS (Fc = fs/10)
             .data                       ;data section
      COEFF  .float  -1.839E-3          ;H44
             .float  -2.657E-3,-1.437E-7, 3.154E-3, 2.595E-3,-4.159E-3,-1.540E-2
             .float  -2.507E-2,-2.547E-2,-1.179E-2, 1.392E-2, 4.206E-2, 5.888E-2
             .float   5.307E-2, 2.225E-2,-2.410E-2,-6.754E-2,-8.831E-2,-7.475E-2
             .float  -2.956E-2, 3.030E-2, 8.050E-2, 1.000E-1, 8.050E-2, 3.030E-2
             .float  -2.956E-2,-7.475E-2,-8.831E-2,-6.754E-2,-2.410E-2, 2.225E-2
             .float   5.307E-2, 5.888E-2, 4.206E-2, 1.392E-2,-1.179E-2,-2.547E-2
             .float  -2.507E-2,-1.540E-2,-4.159E-3, 2.595E-3, 3.154E-3,-1.437E-7
             .float  -2.657E-3          ;H1
      H0     .float  -1.839E-3          ;H0
      LENGTH .set     H0-COEFF+1         ;# of coefficients
      
    5. Find the center frequency of the filter. Input a sine wave with an amplitude less than 3V from the function generator to the board. Observe the output signal from the board on the oscilloscope. Change the frequency of the input sine wave while keep its amplitude to find out the center frequency of the bandpass filter. The center frequency is the frequency at which the output signal obtains its maximum value. For this bandpass filter, the center frequency is between 900 Hz and 1100 Hz. Get the exact value of the center frequency.
    6. Use LP11.COF in the same directory instead of BP45.COF to implement a lowpass filter. Repeat step iii to find out the cutoff frequency of this lowpass filter. The cutoff frequency is the frequency at which the value of the output signal is approximatly 0.707 time of its maximum value. Thus, you should find out the maximum output first.
    7. Use HP55.COF in the same directory instead of BP45.COF to realize a highpass filter. Repeat step iii to find out the cutoff frequency of this highpass filter. The cutoff frequency is the frequency at which the value of the output signal is approximatly 0.707 time of its maximum value. Thus, you should find out the maximum output first.


  4. Exercise II: Bandpass FIR filter design with MATLAB
  5. In this lab exercise, you will use the Example B.4 MAT33.M of APPENDIX B to implement a bandpass filter and use the program of Exercise I to test its characteristics. Follow the steps below to finish the exercise:

    1. Implement the filter. Use the following Matlab program to realize the bandpass filter:
    2. %MAT33.M FIR BANDPASS WITH 33 COEFFICIENTS USING MATLAB fs=10 kHz
      nu=[0 0.1 0.15 0.25 0.3 1];    %normalized frequencies
      mag=[0 0 1 1 0 0];             %magnitude at normalized frequencies 
      c=remez(32,nu,mag);            %invoke remez algorithm for 33 coeff
      bp33=c';                       %coeff values transposed
      save matbp33.cof bp33 -ascii;  %save in ASCII file with coefficients
      [h,w]=freqz(c,1,256);          %frequency response with 256 points
      plot(w/pi,abs(h));             %plot ideal magnitude response
      
      This program will generate a bandpass filter with 33 coefficients. Run the program in the Matlab enviroment.
    3. Print out the frequency response of this filter you just got.
    4. Change the format of the saved coefficient file matbp33.cof. Refer to the coefficient file BP45.COF listed above to change the format of matbp33.cof accordingly and save it in the same directory.
    5. Use matbp33.cof instead of BP45.COF as in Exercise I and follow the steps in Exercise I to test the characteristics of this filter. Also follow the steps there to find out the center frequency of this bandpass filter.


  6. Exercise III: FIR filter design
  7. In this exercise, you are required to design four FIR filters using Matlab to meet the following requirements:

    1. 37-coefficient lowpass filter with cutoff frequency at 0.25 and sampling frequency fs=8000Hz.
    2. 67-coefficient lowpass filter with cutoff frequency at 0.25 and sampling frequency fs=8000Hz.
    3. 37-coefficient highpass filter with cutoff frequency at 0.25 and sampling frequency fs=8000Hz.
    4. 37-coefficient bandpass filter with cutoff frequencies at 0.45 and 0.55, and sampling frequency fs=8000Hz by using Kaiser window function.

    Implement your design, plot the resulting frequency responses and save the generated coefficent files. Choose one of the filter you designed to test its characteristics as in Exercise I. Compare the frequency responses of the first two filters you designed and comment the difference between them.

  8. Exercise IV: FIR filter design and application
  9. In this exercise, you will need first to save a 10-second piece of music from any of your favoriate music CD; then design a lowpass filter which will process the music you recorded by using the filter design technique you learned from previous exercises. Finally, you will need to use an audio player to play the processed music and observe the quality change after running the music signal through a lowpass filter. Following carefully the exercise steps listed below to finish this exercise.

    1. Boot-up a station in the lab.
    2. Bouble click the GoldWave icon on the desktop of the station to run the GoldWave. Press the New button, a New Sound window will show up. Press the Quick settings button to set the properties of the new sound which are shown as Channel: Mono, Sampling rate (Hz): 11,025, Length: 10 sec. Press OK to end the setting of the new sound.
    3. On the Device Controls panel, press the Setup button (the one with a dot and V on it). The Setup window will show up. Press the Record tab, check the Monitor for the Recording option. Press the Graph tab, check the Amplitude for the Graph option. Press OK to end the setting.
    4. Select the Volume control from the Tools menu to start the Volume control. Select Properties from the Volume control Options menu. Check the Recording option from the Properties dialog. Check Line-In for the Show following volume controls option. A Recording Control window will show up. Be sure to check the Select in this window.
    5. Select the CD Player from the Tools menu to start a CD player. Press the Play button to play the CD.
    6. While the music is playing, press the red Record button on the front panel of the Device control to record a piece of music from the CD for about 10 seconds. Press the Stop button to stop both the player and the recorder.
    7. Go to the File menu and choose Save from the pull-down menu list to save the music you just recorded. Make sure you choose the .wav file format to save your music file.
    8. Design and realize a lowpass filter by Matlab. In Matlab enviroment, use WAVREAD function to read you recorded .wav file. Print out a plot of the saved signal. Use CONV function of Matlab to process the signal using the coefficients from the filter you designed. Use WAVWRITE to save the resulting output signal back to a .wav file. Also, print out a plot of the resulting signal.
    9. In GoldWave, open the .wav file you just saved and press the Play button on the Device control to play the processed output signal. Oberve the real-time played back signal and comment on the difference between the orignal signal and processed signal.
    10. Design a highpass filter and a bandpass filter. Repeat the above procedure again for each of these filters. Print out the resulting signal.
    11. Note:


      return to top