Вы находитесь на странице: 1из 31

Manual for Digital Signal Processing Laboratory

(EEE/ECE F434)

Prepared by
Faculty & Laboratory Staff
Dept. EE

Date: August 2017

Page 1
Purpose of the document
This document is intended to be used by the students for enhancing their learning while performing the

experiments. The document starts with review of MATLAB and then used for simple signal processing.

The Code composer studio, used with Texas DSP TMS320C is introduced followed by use of DSP kit

for simple signal processing. Then Simulink is introduced for designinf filters. The MATLAB FDA tool

is used for filter designing. Finally FIR and IIR filer are designed using TMS320C. The document is

designed such that students can go through and work out the experiments.

References:

1. S. J. Orfanidis, “Introduction to Signal Processing”, online book, 2010, available from:


http://www.ece.rutgers.edu/~orfanidi/intro2sp/
2. MATLAB documentation, available from:
http://www.mathworks.in/help/pdf_doc/matlab/getstart.pdf
3. TMS320C6713 DSK documentation.

Page 2
Revision History

Version Revision date Initial creation/Main Changes from Changed by


Number Previous Version
V0.1 Aug-Nov, Initial Document for 11 experiments are Dr. S. K. sahoo and
2013 created. Apurva Kumari
V0.2 Aug-Nov, Modification to few experiments and BVVSN Prabhakar
2015 converting to a single Lab manual Rao, Venkateswaran,
Sampat

Page 3
Contents
Purpose of the document ........................................................................................................................... 2
Revision History ....................................................................................................................................... 3
Contents .................................................................................................................................................... 4
Experiment1: Getting started with MATLAB ........................................................................................... 5
Experiment 2 :Working with MATLAB ................................................................................................... 9
Experiment 3: Getting started with Code Composer Studio ....................................................................11
Experiment 4: Linear and circular convolution ...................................................................................... 12
Experiment 5 Working with TMS 3206713 DSP processor .................................................................. 13
Experiment 6: Getting started with Simulink. ........................................................................................ 16
Experiment 7: Designing filter with Simulink ..................................................................................... 20
Experiment 8: Rectification using TMS 3206713 ............................................................................... 22
Experiment 9: Designing FIR filter with TMS 3206713 ..................................................................... 23
Experiment 10: Designing IIR filter with TMS 3206713 .................................................................... 27

Page 4
Experiment1: Getting started with MATLAB

MATLAB:
MATLAB is the most popular tool used for Digital Signal Processing. It is a high-level language and
interactive environment for numerical computation, visualization, and programming.

The MATLAB consists of


1) The MATLAB language.
2) The MATLAB working environment.
3) Handle Graphics.
4) The MATLAB mathematical function library.
5) The MATLAB Application Program Interface (API).

I Generating Array elements

a) Create an array of 3 elements having values 100 200 and 300. Name the array x.
Instruction:
b) Append the same array with 3 other elements all having values 1.
Instruction:
c) Pad the array with 4 zeros.
Instruction:
d) Limit the number of elements in the array to 5 elements.
Instruction:
e) Display the 2nd and the 3rd element of the array at the command prompt.
Instruction:

f) Make a two dimensional array of size 3*3. Call it x3d.


Instruction:
g) Display the 2nd row 3rd column element of the array at the command prompt
Instruction:
Page 5
h) Find the transpose of this matrix and display both the 3*3 matrices. Call it x3dc.
Instruction:
i) Find the sum of the array elements in x (the one -dimensional array created before).
Instruction:
What happens when I use the same command to the 3d array x3d.

j) Make an array containing 100 elements from 1 to 100 in steps of 1


Instruction:
k) Make an array containing 100 elements from 1 to 500 in steps of 5
Instruction:
l) Find the lengths of both the recently created arrays.
Instruction:

II Getting used to functions to abs, sqrt and exp

a) Find the square root of a positive number and store it in a variable called xsqrt. Obtain the positive
number from the user.
Instruction:

b) Find the square root of a negative number and store it in a variable called xsqrt1. Obtain the number
again from the user.
Instruction:

c) Note the difference in the values stored in xsqrt and xsqrt1.

d) Find the abs value of xsqr1 and store that in the same variable
Instruction:
Result:

c) Store the velocity of light in a variable called c. (Using exp or e)


Instruction:

Page 6
d) Obtain 10 random elements using rand function
Instruction:

III Create a simple sine function and Plot it

a) Create a sine wave and assign it to a variable and plot it. Obtain the frequency of the sine wave for
this question from the user.
Instructions:

b) Label your plot and label the axes. Sketch the result obtained on screen here.
Instructions:
c) Obtain grids on your plot.
Instructions:
d) Obtain multiple sine plots of different frequency on the same plot.
Instruction:
e) Obtain these multiple plots on different subplots in the same figure.
Instruction:
f) What is the maximum frequency of the sine wave that you can plot for a given number of
sample/period?

IV To get used to control functions

a) Generate a random array of 100 elements. Call it x. Also generate another 100-element array
containing values from 1 to 100 in steps of 1 and call it x1.
Instructions:

b) If the 50th or the 100th element of x is odd, then make parity=1


Instructions:
c) Set a counter that counts the number of odd elements in x and x1.

Page 7
Instructions:
d) Check how many elements in x and x1 are multiples of 6
Instructions:

e) Generate a random sequence of binary digits using rand function and applying 0.5 as threshold
value.
Instructions:

V To Create functions and call and execute them

a) Create a function that counts the number of multiples of 3 in an array. Call it mult3.
Instructions:

b) Call this function from a main function


Instructions:

Page 8
Experiment 2 : Working with MATLAB

[A] A sinusoidal signal s(t) is of frequency 1 Hz and peak amplitude of 1.


1. (i) Assume s(t) is sampled with sampling frequency of 10 Hz. Sub plot the samples of sinusoid
for 4 sec .
(ii) Now plot the continuous signals connecting these samples as the second sub plot.

2. (i) Assume s(t) is sampled with sampling frequency of 2 Hz. Plot the samples of sinusoid for 4
sec.
(ii) Now plot the continuous signals connecting these samples as the second sub plot..

3. Note down your observations and explorations

[B] Plot a sound file, amplified and attenuated sound file in one plot using sub plot. Use the available
audio file from the folder.
1. Use the auread command to load the file speech.au into Matlab.

2. Plot the signal on the screen as if it is a continuous-time signal (in top plot using sub plot).

3. Amplify the sound wave by a factor of 5 and plot below the first plot.

4. Attenuate the original sound wave by a factor of 5 and plot below the second plot.

5. Play the three signals via the digital-to-analog converter in your workstation with the Matlab

sound function.

6. Note down your observations and explorations

[C] Follow the instructions given below:


1. Read the lena image in Tiff format from the folder given.

2. Display this image in gray scale as top plot in subplot of three.

3. Add some DC value of 100 and then display the image in gray scale as second plot in subplot of

three.

Page 9
4. Subtract some DC value of 100 from original image and then display the image in gray scale as

third plot in subplot of three.

5. Note down your observations and explorations.

[D] The following matlab program is given. Find the mathematical expression for y in terms of x.
n = 0:100;
s1 = cos(2*pi*0.05*n); % A low frequency sinusoid
s2 = cos(2*pi*0.47*n); % A high frequency sinusoid
x = s1+s2;
% Implementation of the moving average filter
M = input('Desired length of the filter = ');
num = ones(1,M);
y = filter(num,1,x)/M;
% Display the input and output signals
clf;
subplot(2,2,1);
plot(n,s1);
axis([0, 100, -2, 2]);
xlabel('Time index n'); ylabel('Amplitude');
title('Signal # 1');
subplot(2,2,2);
plot(n,s2);
axis([0, 100, -2, 2]);
xlabel('Time index n'); ylabel('Amplitude');
title('Signal # 2');
subplot(2,2,3);
plot(n,x);
axis([0, 100, -2, 2]);
xlabel('Time index n'); ylabel('Amplitude');
title('Input Signal');
subplot(2,2,4);
plot(n,y);
axis([0, 100, -2, 2]);
xlabel('Time index n'); ylabel('Amplitude');
title('Output Signal');
axis;

1. Now change the program so that it will find y3, y10, y50 and y100 corresponding to M = 3, 10,
50 and 100. Plot the inputs s1, x and four outputs corresponding to different values of M.

2. Explain the function of the above program and comments/remarks based on different outputs
obtained for M = 3, 10, 50 and 100.

Page 10
Experiment 3: Getting started with Code Composer Studio

Code Composer Studio:


Code Composer Studio is an integrated development environment (IDE) that supports Texas
Instrumentation's Microcontroller and Embedded Processors portfolio. Code Composer Studio
comprises a suite of tools used to develop and debug embedded applications. It includes an optimizing
C/C++ compiler, source code editor, project build environment, debugger, profiler, and many other
features.

1.
1. Generate a sine wave for 10 time periods using CCS.
2. View and sketch the time domain and frequency domain of the sine wave.
3. Perform half wave rectification to the generated sine wave view and sketch.
4. Perform full f wave rectification to the generated sine wave view and sketch.
5. Perform amplification by factor 5 to the sine wav, view and sketch.

2. Generate a ramp signal, view and sketch.

3. Write a C code to convolve two sequences x[n] with h[n]. Assume X[n] is of length 6 and h[n]
is of length 4.

Page 11
Experiment 4: Linear and circular convolution

4. Write a C code to do linear convolution of two user given sequences x[n] and h[n] as indicated
below:
A. It should ask the length of x[n] and h[n] from user.
B. Then it should ask to enter the two sequences.
C. Then it should the convolution results
D. Cross check your answer using Matlab.

5. Write a C code to do circular convolution of two user given sequences x[n] and h[n] as
indicated below:
A. It should ask the length of x[n] and h[n] from user.
B. Then it should ask to enter the two sequences.
C. Then it should the convolution results.
D. Cross check your answer using Matlab.

6. Explain the use of linear convolution and circular convolution. Is it possible to get one
convolution using the other? How?

Page 12
Experiment 5 Working with TMS 3206713 DSP processor
1. The TMS 3206713 DSP processor can work as a signal generator. Use CCS and dsp
processor to generate the following signals:
A. Sine wave of frequency 6.5 KHz and amplitude 750 mV peak to peak.
B. Sine wave of frequency 15 KHz and amplitude 750 mV peak to peak.
C. Square wave of frequency 6.5 KHz and 50% duty cycle and amplitude 750 mV peak
to peak.
2. The TMS 3206713 DSP processor can receive an external signal and process it. Perform
some signal processing operation as instructed below:
A. Generate a signal of 4 KHz sine wave and 200mv peak to peak using the function
generator.
B. Write a code using CCS to receive the generated signal through line in of the DSP
processor and send out through line out of DSP processor. Observe and note the
input and output voltage(peak to peak) and frequency using CRO. Use the sampling
rate of 16 KHz for the DSP processor.
C. Amplify the signal by an amplification factor of 10 and observe the input and output
voltage and frequency using CRO.
D. Amplify the signal by an amplification factor of 100 and observe the input and
output voltage and frequency using CRO.
E. Compare the output obtained in C and D. Are you getting any distortion? If so
explain the cause of this distortion.

3. The TMS 3206713 DSP processor can receive an external signal and process it. Perform
some signal processing operation as instructed below:
A. Generate a signal of 4 KHz sine wave and 200mv peak to peak using the function
generator.
B. Write a code using CCS to receive the generated signal through line in of the DSP
processor and send out through line out of DSP processor. Observe and note the
input and output voltage (peak to peak) and frequency using CRO. Use the sampling
rate of 16 KHz for the DSP processor.
C. Increase the frequency of the input signal to 5KHz, 6KHz, 7KHz, 8 KHz, 12 KHz
and 15 KHz. Observe the input and output voltage and frequency using CRO. Give
your remark on the output obtained.
D. Now change the sampling rate of the DSP processor to 43.1 KHz and observe the
input and output voltage and frequency using CRO for all the frequencies (5 KHz, 6
KHz, 7 KHz, 8 KHz, 12 KHz and 15 KHz).
E. Compare the observations obtained in C, D and comment on the cause of
observation difference obtained.

Page 13
Video: http://youtu.be/Tou-FEGdz-I
CODE for sine wave generation using DSK kit
/*Initialize the board support library first*/
/* BSL call */
#include "xyzcfg.h"
#include "dsk6713.h"
#include "dsk6713_aic23.h"
#include <stdio.h>
#include <math.h>
float a[100],b;
/* Parameter for the DSK6713 AIC23 Codec */
DSK6713_AIC23_Config config= DSK6713_AIC23_DEFAULTCONFIG;
void main()
{
int i=0;
int f=4000;
/* Codec Handle */
DSK6713_AIC23_CodecHandle hCodec;
DSK6713_init();
/* Start the codec */
hCodec=DSK6713_AIC23_openCodec(0,&config);
/* Frequency Definitions */
DSK6713_AIC23_setFreq(hCodec, DSK6713_AIC23_FREQ_48KHZ);
for(i=0;i<100;i++)
{
a[i]=sin(2*3.14*f*i/48000);
}
while(1)
{
for(i=0;i<100;i++)
{
b=5000*a[i];
/* Write a 32-bit value to the codec */
while(!DSK6713_AIC23_write(hCodec,b));
while(!DSK6713_AIC23_write(hCodec,b));
}
}
/* Close the codec */
DSK6713_AIC23_closeCodec(hCodec);
}

Page 14
CODE for receiving external signal and processing using DSK kit

#include"xyzcfg.h"
#include"dsk6713.h"
#include"dsk6713_aic23.h"
DSK6713_AIC23_Config config= DSK6713_AIC23_DEFAULTCONFIG;
void main()
{
DSK6713_AIC23_CodecHandle hCodec;
int l_input,r_input,l_output,r_output;
DSK6713_init();
hCodec=DSK6713_AIC23_openCodec(0,&config);
DSK6713_AIC23_setFreq(hCodec, DSK6713_AIC23_FREQ_44KHZ);
while(1)
{
while(!DSK6713_AIC23_read(hCodec,&l_input));
while(!DSK6713_AIC23_read(hCodec,&r_input));
l_output=5*(l_input);
while(!DSK6713_AIC23_write(hCodec,l_output));
while(!DSK6713_AIC23_write(hCodec,r_output));
}
DSK6713_AIC23_closeCodec(hCodec);
}

Page 15
Experiment 6: Getting started with Simulink.

Simulink:
Simulink provides built in library blocks for filters and spectrum analyzers. You can also use user
defined blocks through functions defined as matlab files. This lab exercise is essentially to familiarize
you with their use in the design of systems for simulation. You should be able to tune the different
parameters of the blocks for proper simulation.

[1]
Draw the following model in Simulink using source, scope and user defined spectrum analyzer model
(given to you).

Generate sinusoidal signal of frequency 2 Hz, amplitude 3 changing the appropriate parameters.
Run the simulation for 5 sec and view the time domain and frequency domain of the signal.
Use time base and sample time as 0.01.

[2]
Set up the following circuit and set the sine wave frequencies as 2 Hz and 10 Hz with amplitude as 5 and 3.

Run the simulation for 10 sec and view the time domain and frequency domain of the signal.
Page 16
[3] (i) Obtain the transfer function of a 2nd order Butterworth LP-filter with a cutoff frequency at 5Hz.
Use the matlab command butter for same.
(ii) Design a filter using the Simulink block Transfer Fcn. Now set the coefficients of transfer function
so that it will work as a low pass filter as cutoff frequency of 5 Hz. Now give input signal combination
of 2Hz and 10Hz to this filter and check the output through a scope and power spectral density.
Observe the input and out put of filter.

(iii) Change the filter parameters in above so that it will work as a high pass filter with cutoff frequency
of 5Hz.

[4] (a) By using Simulink model generate Fourier series coefficient of the signal. Suppose that the goal
is to design and simulate a system which gets a periodic signal (e.g. a square wave signal) and returns

the corresponding a0 Fourier series coefficient.

So first define function generator for f (t), an integrator, and a divider (to divide by T). Suppose that f
(t) is a square wave signal. The Pulse Generator block provides a square wave signal. T=2

Page 17
Similarly calculate b1,b2,b3 by using simulink model here

Page 18
(b) Reconstruct the original square wave signal by using simulink model. a0 and bk can be used to
reconstruct the original square wave signal using the following equation:

Page 19
Experiment 7: Designing filter with Simulink
Follow the steps indicated below:

1. Design an Equiripple FIR filter with the specification given below:


PB = 1500Hz, SB = 2500Hz, Order =30, Weights as Wpass = 1 and Wstop=1.
Plot the frequency response and find pass band and stop band attenuation.

2. Change the weightage Wpass = 1 and Wstop=10


Give order as 30 and find the pass band (PB) and stop band (SB) attenuation in dB.

3. Give order as minimum and pass band and stop band attenuation as Apass= 2dB and Astop =
50dB. Find the Filter order and the PB and SB attenuation. Is it matching to the required
specification?

4. Find the minimum order of the filer that will satisfy the required specification by varying Wpass

and Wstop.

5. Plot the magnitude response in dB.

6. Plot the magnitude response (not in dB).

7. Plot the phase response.

8. Plot the combined mag and phase response:

9. Plot the group delay and explain what you are concluding from same.

10. Find the impulse response and step response.

11. Find all the coefficients. These coefficients can be used to design actual filter using DSK kit.

12. Find the hardware that will be used in terms of multiplier and adder. How frequently they will

be used?

13. Change the analysis parameter from 0 to Fs and view the response. What you are observing?

14. Change the analysis parameter number of points to 10. What you are observing?

15. Change back the analysis parameter number of points to 1024. What you are observing?

16. Observe the poles zeroes locations of the filter. Comment on stability.

Page 20
17. Transform this LPF to HPF with same specification and plot the magnitude response.

18. Convert back the filter to LPF.

19. Now import this filter as a Simulink block as my LPF.

20. To this filter give appropriate input using Simulink and test for the filter

functionality.

Use the video if required:

http://www.youtube.com/watch?v=VqZ9y2XL4gY

Home assignment:

1] Generate the Verilog code for this above filter.

Synthesize the filer using ISE.

Find the resources used in implementation of this FIR filter.

2] Implement an IIR filter for same specification and follow the same procedure and finally compare
the order required, Hardware required.

Generate the Verilog code for this filter.

Synthesize the filer using ISE.

Find the resources used in implementation of this FIR filter.

For area power analysis you can use the following video:
http://youtu.be/M5rRIDtHVUI

Page 21
Experiment 8: Rectification using TMS 3206713

Q1] Do the following steps to do rectification using DSK kit.


A. Generate a Sine wave signal of frequency 4 KHz and 600mv peak to peak using
CCS and DSP processor. Observe and note the output voltage (peak to peak) and
frequency using CRO. Use the sampling rate of 16 KHz for the DSP processor.
B. Amplify the signal by an amplification factor of 5 and observe the input and output
voltage and frequency using CRO.
C. Now in place of amplification (as in C) do half wave rectification and observe the
input and output voltage.
D. Now in place of amplification (as in C) do full wave rectification and observe the
input and output voltage.

Q2] Do the following steps to do amplitude modulation using DSK kit.

A. The TMS 3206713 DSP processor can work as a signal generator. Use CCS and DSP
processor to generate a Sine wave of frequency 10 KHz and amplitude 750 mV peak
to peak.
B. Generate a signal of 1 KHz sine wave and 600mv peak to peak using the CCS and
DSP processor.
C. Modify the code written in A so that, it will multiply the 1 KHz sine wave signal
with the 10KHz sinusoid generated by CCS (internally in A) and send out through
line out of DSP processor. Observe and note the input and output voltage in time
domain as well as in frequency domain.

Page 22
Experiment 9: Designing FIR filter with TMS 3206713

1. The following is given a code for a FIR low pass filter


Use the code to make your DSK system to work as a low pass filter. Check the functionality as a
low pass filter following the given steps below:
A. Generate a sine wave using function generator of Vpp = 600mv.
B. Give this signal as input to the line in of the DSK kit.
C. Check the line in voltage and line out voltage for different frequencies (keeping the input
voltage fixed at 600mv) as given in the table below.
D. Plot the frequency response of the filter from your observation.

Input frequency in Hz Input Output voltage (PP) Attenuation in dB= 20 log


voltage(PP) (output/maximum output)
5000
6000
6500
7000
7400
7800
8200
8600
9000
9400
9800
10200
10600
11000

Code:
#include "filtercfg.h"
#include "dsk6713.h"
#include "dsk6713_aic23.h"
#include "stdio.h"
#define N 26 // order= no.of coeffs-1
float filter_coeff[]= {
0,-0.0003853313925529,0.0006341126442423, 0.002829773146229,
-0.007055676781791, 7.86074542275e-18, 0.01847065202726, -0.0210139173218,
-0.01649793105045, 0.0623808358558, -0.03549228024622, -0.1060763589495,
0.2897586034668, 0.624895037204, 0.2897586034668, -0.1060763589495,
-0.03549228024622, 0.0623808358558, -0.01649793105045, -0.0210139173218,
0.01847065202726, 7.86074542275e-18,-0.007055676781791, 0.002829773146229,
0.0006341126442423,-0.0003853313925529, 0
}; // coeffs for fp=7k, fs=9k, hanning window, fs=24k

Page 23
DSK6713_AIC23_Config
config={0x0017,0x0017,0x00d8,0x00d8,0x0011,0x0000,0x0000,0x0043,0x0081,0x0001};

void main()
{
DSK6713_AIC23_CodecHandle hCodec;
Uint32 l_input, r_input,l_output, r_output;
DSK6713_init();
hCodec = DSK6713_AIC23_openCodec(0, &config);
DSK6713_AIC23_setFreq(hCodec,DSK6713_AIC23_FREQ_24KHZ);
//DSK6713_AIC23_setFreq(hCodec, 1);

while(1)
{
while(!DSK6713_AIC23_read(hCodec, &l_input));

while(!DSK6713_AIC23_read(hCodec, &r_input));

l_output=(Int16)FIR_FILTER(&filter_coeff ,l_input);
r_output=l_output;

while(!DSK6713_AIC23_write(hCodec, l_output));

while(!DSK6713_AIC23_write(hCodec, r_output));
}

DSK6713_AIC23_closeCodec(hCodec);
}

signed int FIR_FILTER(float * h, signed int x)


{
int i=0;
signed long output=0;
static short int in_buffer[100];

for(i=N;i>0;i--)
in_buffer[i] = in_buffer[i-1];
in_buffer[0] = x;

for(i=0;i<N+1;i++)
output = output + h[i] * in_buffer[i];
//output = x;
return(output);
}

Page 24
2. Design a low pass FIR filter for the given specification following the instructed steps:

Pass band frequency = 5Khz


Stop band frequency = 7KHz
Pass band ripple = 2dB
Stop band ripple = 50dB
a) Find the minimum order and then the coefficients of the FIR filter to match the filter
specification. Use Blackman window for this. Use sampling rate as 16 KHz.
b) Write (modifye that in Q1) a C code using CCS which will use the obtained coefficients and
take external signal through line in of DSK kit and do the filtering. Give the filtered output at
line out.
c) To test the designed filter, generate signals of peak to peak of 600mv using signal generator.
Give this signal as input to the DSK kit through line in and get the filtered output through the
line out of DSK kit. Apply the line in and line out voltage of the DSK kit in two channels of
CRO and note down same in the table given below:
d) Plot the frequency response of the filter from your observation.

Input frequency in Hz Input Output voltage (PP) Attenuation in dB= 20 log


voltage(PP) (output/maximum output)
2000
2500
3000
3500
4000
4500
5000
5500
6000
6500
7000
7500
8000
8500
9000
9500
10000
10500
11000

Page 25
3. Design a high pass FIR filter for the given specification following the steps used in question 2:

Pass band frequency = 7KHz


Stop band frequency = 5KHz
Pass band ripple = 2dB
Stop band ripple = 50dB
Use Hamming window in the design. Take sampling frequency as 24 KHz.
A. To test the designed filter, generate signals of peak to peak of 600mv using signal generator.
Give this signal as input to the DSK kit through line in and get the filtered output through the
line out of DSK kit. Apply the line in and line out voltage of the DSK kit in two channels of
CRO and note down same in the table given below:
B. Plot the frequency response of the filter from your observation.

Input frequency in Hz Input Output voltage (PP) Attenuation in dB


voltage(PP)
3000
3500
4000
4500
5000
5500
6000
6400
6800
7200
7600
8000
8400
8800
9200
9500
10000
10500
11000

Page 26
Experiment 10: Designing IIR filter with TMS 3206713

1. [a] Write the generalized transfer function (TF) of an IIR filter.


[b] The following is a code given for IIR filter. Write the TF of the IIR filter and draw its Direct
form –II structure.
Code:
#include "configurationcfg.h"
#include "dsk6713.h"
#include "dsk6713_aic23.h"
#include "stdio.h"

float den[] = {1,1.4054,1.3279,0.6297,0.1768,0.0201};


float num[] = {0.1425,0.7125,1.4250,1.4250,0.7125,0.1425};

DSK6713_AIC23_Config
config={0x0017,0x0017,0x00d8,0x00d8,0x0011,0x0000,0x0000,0x0043,0x0081,0x0001};

void main()
{

DSK6713_AIC23_CodecHandle hCodec;
Uint32 l_input, r_input,l_output, r_output;
DSK6713_init();
hCodec = DSK6713_AIC23_openCodec(0, &config);
DSK6713_AIC23_setFreq(hCodec, DSK6713_AIC23_FREQ_16KHZ); // sampling frequency
while(1)
{
while(!DSK6713_AIC23_read(hCodec, &l_input));
while(!DSK6713_AIC23_read(hCodec, &r_input));
l_output=2.25* IIR_FILTER(&den, &num ,l_input);
r_output=l_output;
while(!DSK6713_AIC23_write(hCodec, l_output));
while(!DSK6713_AIC23_write(hCodec, r_output));
}
DSK6713_AIC23_closeCodec(hCodec);
}
signed int IIR_FILTER(float * a, float * b, signed int x)
{
signed long output=0;
static short int reg[6]; //order+1 registers
reg[0] = x - (a[1] * reg[1]) - (a[2] * reg[2]) - (a[3] * reg[3]) - (a[4] * reg[4]) - (a[5] * reg[5]);
Page 27
output = (b[0] * reg[0]) + (b[1] * reg[1]) + (b[2] * reg[2]) + (b[3] * reg[3]) + (b[4] * reg[4]) +
(b[5] * reg[5]);
reg[5] = reg[4];
reg[4] = reg[3];
reg[3] = reg[2];
reg[2] = reg[1];
reg[1] = reg[0];
return(output);
}

[C] Test the functionality of this IIR filter using DSK kit. To test the filter, generate signals of peak to
peak of 600mv using signal generator. Give this signal as input to the DSK kit through line in and get
the filtered output through the line out of DSK kit. Apply the line in and line out voltage of the DSK kit
in two channels of CRO and note down same in the table given below:

Input frequency Input voltage(PP) Output voltage (PP) Attenuation in dB= 20


log (output/maximum
output)
500
600
1K
2K
3K
3.5K
4K
4.3K
4.5K
4.7K
4.9K
5K
5.1
5.2
5.3
5.5K

Page 28
6K
6.5K
7K
7.5K
8k
8.5K
9K
10K
10.5K

[D] Plot the frequency response of the filter.

2. Design a low pass IIR filter for the given specification following the instructed steps:
Pass band frequency = 7Khz
Stop band frequency = 10KHz
Pass band ripple = 2dB
Stop band ripple = 50dB
e) Use sampling frequency as 24 KHz. Find normalized frequency and use this to find minimum
order and 3dB frequency using buttord.(Normalized frequency = f/(fs/2))
f) Find the coefficients of the IIR filter to match the filter specification.
g) Write a C code using CCS which will use the obtained coefficients and take external signal
through line in of DSK kit and do the filtering. Give the filtered output at line out.
h) To test the designed filter, generate signals of peak to peak of 600mv using signal generator.
Give this signal as input to the DSK kit through line in and get the filtered output through the
line out of DSK kit. Apply the line in and line out voltage of the DSK kit in two channels of
CRO and note down same in the table given below:

Input frequency Input voltage(PP) Output voltage (PP) Attenuation in dB= 20 log
(output/maximum output)
4K
4.5K
5K
5.5K

Page 29
6K
6.5K
6.7K
7K
7.2k
7.4
7.6K
7.8K
8K
8.5k
9K
9.5k
9.8k
10K
10.3K
10.6K
10.9K
11.4K
12K
12.5K

3. Design a band pass IIR filter for the given specification following the instructed steps:
3db Cutoff frequency at 4KHz and 8 KHz. Order of filter is 2.
a) Use sampling frequency as 48 KHz. Find minimum order the coefficients of the IIR filter to
match the filter specification.
b) Write a C code using CCS which will use the obtained coefficients and take external signal
through line in of DSK kit and do the filtering. Give the filtered output at line out.
c) To test the designed filter, generate signals of peak to peak of 600mv using signal generator. Give
this signal as input to the DSK kit through line in and get the filtered output through the line out of
DSK kit. Apply the line in and line out voltage of the DSK kit in two channels of CRO and note
down same in the table given below:

Page 30
Input frequency Input voltage(PP) Output voltage (PP) Attenuation in dB= 20 log
(output/maximum output)
2K
2.5K
3K
3.5K
4K
4.5K
5K
5.5K
6K
6.5K
7K
7.5k
7.8K
8K
8.5k
9K
9.5k
10K
10.9K
11.4K
12K
12.5K

End

Page 31

Вам также может понравиться