Low pass filter, high pass filter, band pass filter and band stop filter using FIR filter.

Filters are essential components in many communication systems. Filters can be used in samplers and down samplers as an anti-alias filters. Also filters can be used in modulators and demodulators, reconstruction filters in in receivers. Also filters can be used in some control systems and in almost every signal processing components.
Filters can be classified as either an analogue or digital filters. In this experiment we will be interested in digital filters only.
Digital filters can also be classified as either a Finite Impulse Response (FIR) or an Infinite Impulse Response (IIR) filters.
A finite impulse response (FIR) filter is a type of a signal processing filter whose impulse response (or response to any finite length input) is of finite duration, because it settles to zero in finite time. However the response time for an IIR filter will extends to an infinite.
A comparison between FIR and IIR filters show that IIR requires less coefficient; hence faster computation of the filtered signal; compared with FIR filters. However IIR filters have a non-linear phase distortion whereas FIR filters has a linear phase response.
In this experiment only FIR filters will be considered while IIR filters will be discussed in more details in the next experiment.
To design an FIR filter, it is necessary to compute the filter coefficients by either windowing or using one the various algorithms presented by digital signal processing course. However the calculation of the filter coefficients is greatly simplified by using commercial software such as MATLAB and digifilter.
FIR filters can be implemented in hardware by using the structure shown in Figure 1.


Figure 1 Structure for FIR filter.
Note that filters are considered linear time invariant system. This means that if an input signal is passed through the input terminal of a given filter then the output of that filter is given by the convolution sum described by .
Experimental procedures
In this experiment we will implement and test low pass filter, high pass filter, bandpass filter and band stop (notch) filter as illustrated by the following exercises.
Low pass filter
In this experiment you will design a low pass filter whose cutoff frequency is . In order to design this filter do the following steps
1.     In MATLAB open the filter design tool by typing the fdatool in the MATLAB command window. Aa design window such as the one shown in Figure 2 will appear on the screen.


Figure 2 Filter design tool in Matlab.
1.     Set the response type to Low pass filter, the design method to FIR window, filter order 50, window Hamming, sampling frequency to  and the carrier frequency
2.     Press on the design button to design the filter.
3.     In order to obtain the filter coefficients go the file menu then select export. A small dialog box such as the one shown in Figure 3 will appear. Select export to coefficient File (ASCII) and press on the export button. Name your file as “lpf.cof” and save it under your project directory. The file contains the filter coefficient that is needed by project.
1.     Modify the filter coefficient file by adding the following two statements
#define N 89 //number of coefficients
float h[N]={ add the coeffients of the filter here}
2.     To implement the filter on the DSK6713 kit open the existing project that you worked on last time and add the following c code to it.
#include "lpf.cof"                                                         //coefficient file
#include "dsk6713_aic23.h"                                     //codec-dsk support file
Uint32 fs=DSK6713_AIC23_FREQ_8KHZ;               //set sampling rate
signed intyn = 0;                                                                    //initialize filter's output
short dly[N];                                                              //delay samples
interrupt void c_int11()                                          //ISR
short i;
dly[0]=input_sample();                                         //input newest sample
yn = 0;                                                                     //initialize filter's output
for (i = 0; i< N; i++)
yn += (h[i] * dly[i]);                                              //y(n) += h(i)* x(n-i)
for (i = N-1; i > 0; i--)                                            //starting @ end of buffer
dly[i] = dly[i-1];                                                    //update delays with data move
output_sample(yn);                                          //output filter sample
void main()
comm_intr();                                                  //init DSK, codec, McBSP
while(1);                                                          //infinite loop
3.     After you build the project, load it on the DSK6713 kit, then run the program.
4.     To test the designed LPF filter, connect a sine wave from the function generator to the LINE IN terminal of the DSK6713 kit.
Set the amplitude of the sign wave to  and vary the frequency of the sine wave from 50 Hz to 3.4 kHz in steps of 200 Hz. Measure the amplitude of the output wave at every frequency point

Plot the amplitude versus frequency and comment on the results
Low pass, high pass, band pass and pass band filter
In this exercise we will design four filters using the same procedure used in the previous section. The student is supposed to design the four filter types in MATLAB then export the filters coefficients to a different file depending on the filter type.
A slider can be used to select which filter to use as illustrated by the following c source file. Select the cutoff frequency of the low pass filter as , the cut off frequency of the High pass filter as , the center frequency of the bandpass filter as , and the band stop of the band stop filter as

* Description :This Program tells about the Finite Impulse Response.
                             FIR filter:
                                                          lowpass 1500 Hz,
                                                          High pass,2200hz,
                                                          bandpass 1750 hz,
                                                          bandstop 790 hz.
                                      we can select desires filter by varying slider in gel file

#include "DSK6713_AIC23.h"                  //this file is added to initialize the DSK6713
#include "lowp1500.cof"                            // coefficient of low-pass filter file calculated from MATLAB          
#include "highp2200.cof"                 // coefficient of high-pass filter file calculated from MATLAB
#include "bpass1750.cof"                 // coefficient of band-pass filter file calculated from MATLAB
#include "bstop790.cof"                             // coefficient of band-stop filter file calculated from MATLAB
Uint32 fs=DSK6713_AIC23_FREQ_8KHZ;       // set the sampling frequency, Different sampling frequencies supported by AIC23 codec are 8, 16, 24, 32, 44.1, 48, and 96 kHz.

short FIR_number = 0;  //filter number                         
signed intyn = 0;                               //variable declaration                                                              
short dly[N];                            //declare delay buffer of n values                         
float h[4][N];                           //co-efficients of 4 different filters                                 

interrupt void c_int11() // ISR call, At each Interrupt, program execution goes to the interrupt service routine                          
          short i;                                                                  //variable declaration
          dly[0] = input_sample();                   //newest input @ top of buffer
          yn = 0;                          //initialize filter output
          for (i = 0; i< N; i++)                                    //for loop takes in the value of i from 0 to N
          yn +=(h[FIR_number][i]*dly[i]);       //y(n) += h(LP#,i)*x(n-i)
          for (i = N-1; i > 0; i--)              //starting @ bottom of buffer
          dly[i] = dly[i-1];                       //update delays with data move
          output_sample(yn>> 15);                           //output filter,the value in the buffer yn indexed by the variable loop is written on to the codec.
          return;                                                                            // program execution goes back to while(1) and then again starts listening for next interrupt and this process goes on
void main()
          short i;                                                                  //variable declaration
          for (i=0; i<N; i++)                                                //for loop which takes in the value of i from 0 to N=4 and switches to corresponding filter co-efficients
                   dly[i] = 0;                                //init buffer
                   h[0][i] = hlp[i];                                  //start addr of lp1500 coeff
                   h[1][i] = hhp[i];                                 //start addr of hp2200 coeff
                   h[2][i] = hbp[i];                                 //start addr of bp1750 coeff
                   h[3][i] = hbs[i];                                  //start addr of bs790 coeff
          comm_intr();                           // ISR function is called, using the given command
          while(1);                                                     //program execution halts and it starts listening for the interrupt which occur at every sampling period Ts.
You need also to add the following GEL file to your project.
Effects on Voice Using Three FIR Low pass Filters (FIR3LP)
In this exercise you will implement three FIR low pass filters with cutoff frequencies at 600, 1500, and 3000Hz, respectively. The three low pass filters were designed with MATLAB’s fdatool to yield the corresponding three sets of coefficients.
If for example LP_number is set to 0, h[0][i] is equal to hlp600[i] (within the “for” loop in the function main), which is the address of the first set of coefficients. The coefficients file LP600.cof represents an 81-coefficient FIR low pass filter with a 600-Hz cutoff frequency, using the Kaiser window function. your program may appear as the one shown below. LP_number can be changed to 1 or 2 to implement the 1500- or 3000-Hz low pass filter, respectively.
//Fir3LP.c FIR using 3 low pass coefficients with three different BW
#include "lp600.cof" //coeff file LP @ 600 Hz
#include "lp1500.cof" //coeff file LP @ 1500 Hz
#include "lp3000.cof" //coeff file LP @ 3000 Hz
#include "dsk6713_aic23.h" //codec-dsk support file
Uint32 fs=DSK6713_AIC23_FREQ_8KHZ; //set sampling rate
short LP_number = 0; //start with 1st LP filter
signed intyn = 0; //initialize filter's output
short dly[N]; //delay samples
float h[3][N]; //filter characteristics 3xN
interrupt void c_int11() //ISR
short i;
dly[0] = input_sample(); //newest input @ top of buffer
yn = 0; //initialize filter output
for (i = 0; i< N; i++)
yn +=(h[LP_number][i]*dly[i]); //y(n) += h(LP#,i)*x(n-i)
for (i = N-1; i > 0; i--) //starting @ bottom of buffer
dly[i] = dly[i-1]; //update delays with data move
output_sample(yn>> 15); //output filter
return; //return from interrupt
void main()
short i;
for (i=0; i<N; i++)
dly[i] = 0; //init buffer
h[0][i] = hlp600[i]; //start addr of LP600 coeff
h[1][i] = hlp1500[i]; //start addr of LP1500 coeff
h[2][i] = hlp3000[i]; //start addr of LP3000 coeff
comm_intr(); //init DSK, codec, McBSP
while(1); //infinite loop
With the GEL file FIR3LP.gel, one can vary LP_number from 0 to 2 and slide through the three different filters. Build this project as FIR3LP. Use a .wav file from your PC as input and observe the effects of the three low pass filters on the input voice. Connect the LINE OUT of the DSK6713 to a speaker and observe what happens when the different filters are used
Your GEL file may appear as shown below
/*FIR3LP.gel Gel file to step through three different LP filters*/
menuitem "Filter Characteristics"
slider Filter(0,2,1,1,filterparameter) /*from 0 to 2,incr by 1*/
LP_number = filterparameter; /*for 3 LP filters*/

Voice Scrambling Using Filtering and Modulation (Scrambler)
This exercise illustrates a voice scrambling/descrambling scheme. The approach makes use of basic algorithms for filtering and modulation. With voice as input, the resulting output is scrambled voice. The original unscrambled voice is recovered when the output of the DSK is used as the input to a second DSK running the same program.
The scrambling method used is commonly referred to as frequency inversion. It takes an audio range, represented by the band 0.3 to 3 kHz, and “folds” it about a carrier signal. The frequency inversion is achieved by multiplying (modulating) the audio input by a carrier signal, causing a shift in the frequency spectrum with upper and lower sidebands. On the lower sideband that represents the audible speech range, the low tones are high tones, and vice versa.
Figure 4 is a block diagram of the scrambling scheme. At point A we have a band-limited signal 0 to 3 kHz. At point B we have a double-sideband signal with suppressed carrier. At point C the upper sideband is filtered out. Its attractiveness comes from its simplicity, since only simple DSP algorithms are utilized: filtering, and sine generation and modulation.
Figure 4 Block diagram of scrambler/scrambler scheme


·        The FIR filter can be used to implement a LPF, HPF, BBF and BSF.

·        These filters are used to process the signals according to requirements.

·        An inverse filter can be used to recover the original signal from the filters used.

·        We can use the filter to filter the voice  and make difrent cut off frequances.  


Popular Posts

Short Speech on Independence Day in Malayalam

Eye Directive Wheelchair