Академический Документы
Профессиональный Документы
Культура Документы
(EEE/ECE F434)
Prepared by
Faculty & Laboratory Staff
Dept. EE
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:
Page 2
Revision History
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.
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:
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:
d) Find the abs value of xsqr1 and store that in the same variable
Instruction:
Result:
Page 6
d) Obtain 10 random elements using rand function
Instruction:
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?
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:
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:
a) Create a function that counts the number of multiples of 3 in an array. Call it mult3.
Instructions:
Page 8
Experiment 2 : Working with MATLAB
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..
[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.
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
[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
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.
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
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:
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.
9. Plot the group delay and explain what you are concluding from same.
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.
20. To this filter give appropriate input using Simulink and test for the filter
functionality.
http://www.youtube.com/watch?v=VqZ9y2XL4gY
Home assignment:
2] Implement an IIR filter for same specification and follow the same procedure and finally compare
the order required, Hardware required.
For area power analysis you can use the following video:
http://youtu.be/M5rRIDtHVUI
Page 21
Experiment 8: Rectification using TMS 3206713
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
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);
}
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:
Page 25
3. Design a high pass FIR filter for the given specification following the steps used in question 2:
Page 26
Experiment 10: Designing IIR filter with TMS 3206713
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:
Page 28
6K
6.5K
7K
7.5K
8k
8.5K
9K
10K
10.5K
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