Real Time FIR filter design using DSK TMS3206713 | Sampling (Signal Processing) | Telecommunications Engineering

Expt. No.

10 REAL TIME FIR FILTER DESIGN USING DSK Objective: To realize FIR low pass, high pass and band pass filters using DSK Equipments required: 1. DSK for TMS320C6713 2. PC installed Software- CCS and MATLAB (To generate filter coefficients) 3. USB cable 4. Audio stereo cable (3.5mm banana connector at one end and crocodile pin at other end) 5. DSO and connecting probe 6. Function generator with connecting probe Theory: The non-recursive equation for Nth order FIR filter is

The transfer function is

There is different form for realizing FIR filter. A simple structure is direct form and is show below:

Page 1

Flow chart for real time FIR filters

Flow chart for FIR filter

Page 2

MATLAB CODE FOR FILTER COEFFICIENTS: 1. LP and HP filter using rectangular window: %Specifications: %Cut-off frequency: 3 KHz %Sampling rate: 32000 samples/sec %Filter order: 20 % LPF N=20; M=N+1; fc=1000; Fs=8000; wc=2*fc/Fs; win=rectwin(M); b=fir1(N,wc,win); a=1; freqz(b,a); title(‘FIR LPF using rectangular window’); grid on; % HPF N=20; M=N+1; fc=1000; Fs=8000; wc=2*fc/Fs; win=rectwin(M); b=fir1(N,wc,’high’,win) a=1; freqz(b,a); title(‘FIR HPF using rectangular window’); grid on; 2. BP filters using Kaiser window: %Specifications: %Cut-off frequencies: 3 KHz and 18kHz %Sampling rate: 32000 samples/sec %Filter order: 10 %Beta: 4 N=20; M=N+1; fc=[5000 10000]; Fs=32000; beta=4; wc=2*fc/Fs; win=kaiser(M,beta); b=fir1(N,wc,win) a=1;
Page 3

freqz(b,a); title(‘FIR BPF using Kaiser window’); grid on; Program: //File name fir.c #include "fircfg.h" #include "c:\ccstudio_v3.1\c6000\dsk6713\include\dsk6713.h" #include "c:\ccstudio_v3.1\c6000\dsk6713\include\dsk6713_aic23.h" #define N 20 //Order of the filter extern signed long FIR_FILTER(signed int ); //Subprogram for FIR filter //Filter coefficients // Uncomment the required coefficients const float h[] = { //LPF, fc=1kHz, Fs=8kHz, N=20, Rectangular window /* 0.0312,0.0245,-0.0000,-0.0315,-0.0519,-0.0441,0.0000, 0.0734,0.1558,0.2203,0.2447,0.2203,0.1558,0.0734,0.0000, -0.0441,-0.0519,-0.0315,-0.0000,0.0245,0.0312 */ //HPF, fc=1kHz, Fs=8kHz, N=20, Rectangular window /*-0.0328,-0.0258,-0.0000,0.0331,0.0547,0.0464,-0.0000, -0.0773,-0.1641,-0.2320,0.7732,-0.2320,-0.1641,-0.0773, -0.0000,0.0464,0.0547,0.0331,-0.0000,-0.0258,-0.0328 */ //BPF, fc1=5kHz, fc2=10kHz, Fs=32kHz, N=20, Kaiser window, Beta =4 /* 0.0353,-0.0533,-0.0405,0.0171,-0.0175,0.0388,0.1384,-0.0625, -0.2644,0.0300,0.3184,0.0300,-0.2644,-0.0625,0.1384,0.0388, -0.0175,0.0171,-0.0405,-0.0533,0.0353 */ }; static short in_buffer[N]; //Buffer variable DSK6713_AIC23_Config config = { \ 0x0017, /* 0 DSK6713_AIC23_LEFTINVOL Left line input channel volume */ \ 0x0017, /* 1 DSK6713_AIC23_RIGHTINVOL Right line input channel volume */\ 0x00d8, /* 2 DSK6713_AIC23_LEFTHPVOL Left channel headphone volume */ \ 0x00d8, /* 3 DSK6713_AIC23_RIGHTHPVOL Right channel headphone volume */ \ 0x0011, /* 4 DSK6713_AIC23_ANAPATH Analog audio path control */ \ 0x0000, /* 5 DSK6713_AIC23_DIGPATH Digital audio path control */ \ 0x0000, /* 6 DSK6713_AIC23_POWERDOWN Power down control */ \ 0x0043, /* 7 DSK6713_AIC23_DIGIF Digital audio interface format */ \ 0x0081, /* 8 DSK6713_AIC23_SAMPLERATE Sample rate control */ \ 0x0001 /* 9 DSK6713_AIC23_DIGACT Digital interface activation */ \ };
Page 4

//Main program void main() { DSK6713_AIC23_CodecHandle hCodec; Uint32 l_input, r_input,l_output, r_output; /* Initialize the board support library, must be called first */ DSK6713_init(); /* Start the codec */ hCodec = DSK6713_AIC23_openCodec(0, &config); /* Set sampling rate*/ DSK6713_AIC23_setFreq(hCodec, 4); while(1) { /* Read a sample to the left channel */ while (!DSK6713_AIC23_read(hCodec, &l_input)); /* Read a sample to the right channel */ while (!DSK6713_AIC23_read(hCodec, &r_input)); l_output=(Int16)FIR_FILTER(l_input); r_output=l_output; /* Send a sample to the left channel */ while (!DSK6713_AIC23_write(hCodec, l_output)); /* Send a sample to the right channel */ while (!DSK6713_AIC23_write(hCodec, r_output)); } } //Subprogram body signed long FIR_FILTER(signed int x) { int i,M; signed long y=0; //output variable M=N+1; in_buffer[0] = x; // new input at buffer[0] for(i=M;i>0;i--) in_buffer[i] = in_buffer[i-1]; // shuffle the buffer for(i=0;i<M;i++) y += h[i] * in_buffer[i]; //filter return(y); }

Page 5

Results: 1. FIR LPF using rectangular window Specifications: Cut-off frequency: 1 kHz Sampling rate: 32000 samples/sec Filter order: 20 Desired Response: (Plot the response by running MATLAB code) Observation Table: Vin = 500mVpp f (in Hz) Vo (in Vpp) Normalized f (in pi rad/sample) Gain in dB

Observed response: (Plot the frequency response from the observations) 2. FIR HPF using rectangular window Specifications: Cut-off frequency: 6 kHz Sampling rate: 32000 samples/sec Filter order: 20 Desired Response: (Plot the response by running MATLAB code) Observation Table: f (in Normalized f (in Vo (in V) Hz) pi rad/sample)

Gain in dB

Observed response: (Plot the frequency response from the observations)

Page 6

2. FIR BPF using Kaiser Window Specifications: Cut-off frequencies: 5 kHz and 10 kHz Sampling rate: 32000 samples/sec Filter order: 20 Beta: 2 Desired Response: (Plot the response by running MATLAB code) Observations: f (in Hz) Vo (in V) Normalized f (in pi rad/sample) Gain in dB

Page 7

Sign up to vote on this title
UsefulNot useful