Documente Academic
Documente Profesional
Documente Cultură
V SEMESTER B.E
LABORATORY MANUAL
SEMESTER :
BATCH :
There are several toolboxes available from mat lab. These tool boxes are
collections of functions written for special application such as symbolic computation,
image processing, statistics, and control system design.
COMMAND WINDOW
This is the main window .it is characterized by the Matlab command prompt’>>’.
when you launch an application program, MATLAB puts you in this window, all
commands including those for running user written programs are typed in this window at
the MATLAB prompt.
EDITOR WINDOW
This is where you write, edit, create, and save your own programs in files called
‘m-files’. MATLAB provides its own built in editor.
M-files
They are standard ASCII text files with an .m extension to the file name. They are
two types of m-files namely script file function file.
MAT-files
These are binary data files, with a .m extension to the file name. MAT files are
created by MATLAB when you save the data with the save command. The data is written
in a special format that only MATLAB can read.
MEX-files
These are MATLAB callable FORTRAN and C programs with an . mex
extension to the file name.
BUILT IN FUNCTIONS
Procedure: -
Fs = 2*max(f1,f2);
w2 = max(f1,f2)/(4*max(f1,f2));
N = 2;
t = 0:0.01:N*2*pi;
x = 2*sin(f1*t)+2*sin(f2*t);
x = x/6;
figure;
subplot(2,1,1)
plot(t,x);
title('Original Signal');
xlabel('Time -->');
ylabel('Amplitude');
h = fir1(10,w2);
resp = figure;
freqz(h);
figure;
Ts = 0:1/Fs:N*2*pi;
subplot(2,1,1);
xn = sin(f1*Ts)+sin(f2*Ts);
xn = xn/3;
stem(xn);
xl='Samples -->';
yl='Amplitude-->';
title(Title_signal);
xlabel(xl);
ylabel(yl);
% filter
y = conv(xn,h);
subplot(2,1,2);
plot(y);
title(Title_Reconstruct);
xlabel(xl);
ylabel(yl);
Procedure:-
1. Rewrite the difference equation so that y[n] and its delayed samples are on the
LHS
2. Create a matrix a for the coefficients of y[n] and its delayed versions
3. Create a matrix b for the coefficients of x[n] and its delayed versions
4. Generate impulse excitation signal delta [n]
5. Find the response h[n] of the filter defined by a & b coefficients , so the input
impulse excitation , using filter command
6. Display the impulse response h[n].
MATLAB CODE
clear
close all
clc
% SOLVE THE GIVEN DIFFERENCE EQUATION Y(N) - y(N-1) + 0.9Y(N-2) = X(N)
% FIND THE TRANSFER FUNCTION OF THE GIVEN DIFFERENCE EQUATION
H(Z) = Y(Z)/X(Z)
% NUMERATOR POLYNOMIAL IS 'A' AND DENOMINATOR POLYNOMIAL IS
'B'
% FOR THE ABOVE EXAMPLE B = [1] AND A = [ 1 -1 0.9 ]
b = [1];
a = [1 -1 0.9];
% H(N) IS REQUIRED FOR N = -20,-19,...,100
% SO GENERATE IMPULSE SEQUENCE OF THE ABOVE LENGTH
% N - TIME INDEX
n = [-20:100];
% X IS THE IMPULSE SEQUENCE
x = [(n == 0)];
% FIND THE OUTPUT OF THE SYSTEM FOR THE IMPULSE SEQUENCE WHICH
IS THE
% IMPULSE RESPONSE
h = impz(b,a);
h = filter(b,a,x);
% PLOT THE INPUT AND THE OUTPUT
figure(1);
subplot(2,1,1);
stem(n,x);
xlabel('Time index n');
ylabel('Amplitude');
title('Impulse Sequence');
grid on;
subplot(2,1,2);
stem(n,h);
%stem(h);
xlabel('Time Index n');
Ylabel('Amplitude');
title('Impulse Response');
grid on;
grid on;
subplot(2,1,2);
stem(n,s);
xlabel('Time index n');
ylabel('Amplitude');
title('Step Response');
grid on;
Procedure:-
1. Read the input sequence, x[n] and plot
2. Read the impulse response of the system, h[n] and plot
3. Convolve the two results and plot them
Description:-
Linear Convolution involves the following operations.
1. Folding
2. Multiplication
3. Addition
4. Shifting
y[n] = ∑ x[k]h[n-k]
NOTE: At the end of input sequences pad ‘n’ and ‘k’ no. of zero’s
%Another Program:
clc;
close all;
x=input('Enter the input sequence x[n]: ');
h=input('Enter the system function h[m]: ');
n=length(x);
m=length(h);
l=n+m-1;
y=zeros(1,l);
x=[x,zeros(1,l-n)];
h=[h,zeros(1,l-m)];
for i=1:l,
for j=1:i,
y(i)=y(i)+x(j)*h(i-j+1);
end
end
disp(y)
Description:-
Steps for Cyclic Convolution
Steps for cyclic convolution are the same as the usual convolution, except all index
calculations are done "mod N" = "on the wheel"
Steps for Cyclic Convolution
Step 2: "Spin" h[−m] n times Anti Clock Wise (counter-clockwise) to get h[n-m]
(i.e. Simply rotate the sequence, h[n], clockwise by n steps)
Figure 2: Step 2
Step 3: Point wise multiply the f[m] wheel and the h[n−m] wheel. Sum=y[n]
Example 1: Convolve (n = 4)
• h[−m] =
Figure 4
Multiply f[m] and sum to yield: y[0] =3
• h[1−m]
Figure 5
Multiply f[m] and sum to yield: y[1] =5
• h[2−m]
Figure 6
Multiply f[m] and sum to yield: y[2] =3
• h[3−m]
Figure 7
Multiply f[m] and sum to yield: y[3] =1
MATLAB CODE
x=input('Enter the input sequence x[n]: ');
h=input('Enter the system function h[m]: ');
n=length(x);
m=length(h);
l=max(n,m);
y=zeros(1,l);
x=[x,zeros(1,l-n)];
h=[h,zeros(1,l-m)];
for i= 1:l,
j=i;
for k=1:l,
if(j<1)
j=l;
else j=j;
end
y(i)=y(i)+x(k)*h(j);
j=j-1;
end
end
display(x);
display(h);
display(y);
5. AUTOCORRELATION
Procedure:-
1. Read the input sequence
2. Autocorrelate the signal using xcorr(x,x)
3. Display the Autocorrelation result in suitable axis
4. verify the correlation property:Rxx(0)=energy(x)
5. verify the property :Rxx is a even function
MATLABCODE
clear
clc
close all
xlabel('nRxx--->');
ylabel('autocorrelation of x--->');
title('Autocorrelated sequence of x');
grid on;
RESULT:- AUTOCORRELATION
6. CROSSCORRELATION
Procedure:-
1. Read the input sequence
2. Cross correlate the signal
3. Display the cross correlate result in suitable axis
4. Verify the correlation property:Rxx(0)=energy(x)
5. Verify the property :Rxx is a even function
MATLABCODE
clear
clc
close all
nr = -7:1:6;
subplot(3,1,3);
stem(nr,r);
title('Crosscorrelation sequence');
grid on;
RESULT:-
CROSSCORRELATION OF TWO SEQUENCES
MATLABCODE
clear
close all
clc
b = [1];
a = [1 -0.9];
%a = [1,-5/6,1/6];
n = [-5:50];
x = [(n == 0)];
h = filter(b,a,x);
figure(1)
subplot(2,1,1);
stem(n,x);
xlabel('n --> ');
ylabel('x --> ');
title('Impulse Sequence');
grid on;
subplot(2,1,2);
stem(n,h);
xlabel('n --> ');
ylabel('h --> ');
title('Impulse Response');
grid on;
% FIND THE OUTPUT OF THE SYSTEM FOR THE INPUT SEQUENCE X(N)
y = filter(b,a,x);
figure(2)
subplot(2,2,1);
stem(n,x1);
xlabel('n --> ');
ylabel('x --> ');
title('Input squence x1(n)');
grid on;
subplot(2,2,2);
stem(n,x2);
xlabel('n --> ');
ylabel('x --> ');
title('Input squence x2(n)');
grid on;
subplot(2,2,3);
stem(n,x);
xlabel('n --> ');
ylabel('x --> ');
title('Input squence x(n)');
grid on;
subplot(2,2,4);
stem(n,y);
xlabel('n --> ');
ylabel('y --> ');
title('Output squence y(n)');
grid on;
clear
close all
clc
% SOLVE THE GIVEN DIFFERENCE EQUATION Y(N) - 1.5Y(N-1) + 0.5Y(N-2) =
X(N), N >= 0
% X(N) = (1/4)^n * U(N) SUBJECT TO Y(-1) = 4 AND Y(-2) = 10
% CALCULATE AND PLOT THE OUTPUT OF THE SYSTEM
% FIND THE TRANSFER FUNCTION OF THE GIVEN DIFFERENCE EQUATION
H(Z) = Y(Z)/X(Z)
% NUMERATOR POLYNOMIAL IS b AND DENOMINATOR POLYNOMIAL IS a
% FOR THE ABOVE EXAMPLE b = [1] AND a = [1 -1.5 0.5]
b = [1];
a = [1 -1.5 0.5];
% FIND THE INITIAL CONDITIONS FOR THE INPUT X SUCH THAT THE GIVEN
INITIAL CONDITIONS
% FOR Y ARE OBTAINED
yic = [4 10];
xic = filtic(b,a,yic);
xic
% GENERATE THE DISCRETE TIME INDEX
n = [0:7];
% GENERATE THE GIVEN INPUT X
x = (1/4).^n;
% FIND THE OUTPUT OF THE SYSTEM FOR THE INPUT SEQUENCE X
y = filter(b,a,x,xic);
figure(1)
subplot(2,1,1);
stem(n,x);
grid on;
xlabel('n --> ');
ylabel('x --> ');
title ('Input Sequence');
subplot(2,1,2);
stem(n,y);
xlabel('n --> ');
ylabel('y --> ');
title ('Output Sequence');
grid on;
RESULT:- DIFF EQN WITH INITIAL COND
clear
clc
close all
in =input('Enter a Sequence: ');
%% Description
N=length(in);
y=zeros(1,N);
%wn=exp(-(2*pi*i)/N);
for k=1:N,
for j=1:N,
y(k)=y(k)+in(j)*exp(-(2*pi*1i)*(j-1)*(k-1)/N);
end
end
out=y;
Mag_y=abs(y);
Phase_y=angle(y);
figure;
subplot(3,1,1)
stem(in);
subplot(3,1,2)
stem(Mag_y);
subplot(3,1,3)
stem(Phase_y);
%% To find IDFT
Y=zeros(1,N);
for k=1:N,
for j=1:N,
Y(k)=Y(k)+y(j)*exp((2*pi*1i)*(j-1)*(k-1)/N);
end
end
Y=Y/N;
RESULT:-
COMPUTATION OF DFT
clear
clc
close all
% FIRST SEQUENCE X1
x1 = [1 2 7 -2 3 -1 5];
nx1 = 0:length(x1)-1;
n1 = length(x1);
subplot(3,1,1);
stem(nx1,x1);
xlabel('n-->');
ylabel('x1-->');
title('First Sequence');
grid on;
% SECOND SEQUENCE X2
x2 = [1 3 5 -3 1];
nx2 = 0:length(x2)-1;
n2 = length(x2);
subplot(3,1,2);
stem(nx2,x2);
xlabel('n-->');
ylabel('x2-->');
title('Second Sequence');
grid on;
N = n1+n2-1;
% IF N > length(x1) or length(x2) ZERO PAD
newx1 = [x1,zeros(1,N-n1)];
newx2 = [x2,zeros(1,N-n2)];
MATLAB CODE
clear
clc
close all
% FIRST SEQUENCE X1
x1 = [1 0.5 1 0.5 1 0.5 1 0.5];
nx1 = 0:length(x1)-1;
n1 = length(x1);
subplot(3,1,1);
stem(nx1,x1);
xlabel('n-->');
ylabel('x1-->');
title('First Sequence');
grid on;
% SECOND SEQUENCE X2
x2 = [0 1 2 3];
nx2 = 0:length(x2)-1;
n2 = length(x2);
subplot(3,1,2);
stem(nx2,x2);
xlabel('n-->');
ylabel('x2-->');
title('Second Sequence');
grid on;
N = n1+n2-1;
% IF N > length(x1) or length(x2) ZERO PAD
newx1 = [x1,zeros(1,N-n1)];
newx2 = [x2,zeros(1,N-n2)];
RESULT:-
CIRCULAR CONVOLUTION USING DFT AND IDFT
y(n)=
14.0000 - 0.0000i
16.0000 + 0.0000i
14.0000 - 0.0000i
16.0000 - 0.0000i
MALABCODE
clear
clc
close all
Fn = Fs/2;
twn = tw/Fn;
if As <= 21
N = ceil(2/twn);
wn = boxcar(N);
elseif As > 21
N = ceil(6/twn);
wn = blackman(N);
end
fc = (fp+tw)/Fn;
hn= fir1(N-1,fc,wn);
wvtool(wn);
figure;
subplot(2,1,1);
plot(0:N-1,hn);
[H,f] = freqz(hn,1,512,Fs);
mag = 20*log10(abs(H));
subplot(2,1,2);
plot(f,mag);
xlabel('frequency(Hz)-->');
ylabel('magnitude(dB)-->');
title('SMagnitude response');
grid on;
close all
Fn = Fs/2;
[b,a] = butter(N,wc);
[H,f] = freqz(b,a,512,8000);
subplot(2,1,1);
plot(f,20*log10(abs(H)))
xlabel('frequency(Hz)-->');
ylabel('magnitude(dB)-->');
title('Magnitude response');
grid on;
subplot(2,1,2);
plot(f,angle(H))
xlabel('frequency(Hz)-->');
ylabel('Angles(rad)--->');
title('Phase Response');
PART – B
CODE COMPOSER STUDIO
(C/C++ Programming)
Package Contents
The C6713™ DSK builds on TI's industry-leading line of low cost, easy-to-use
DSP Starter Kit (DSK) development boards. The high-performance board features the
TMS320C6713 floating-point DSP. Capable of performing 1350 million floating-point
operations per second (MFLOPS), the C6713 DSP makes the C6713 DSK the most
powerful DSK development board.
The DSK is USB port interfaced platform that allows to efficiently develop and
test applications for the C6713. The DSK consists of a C6713-based printed circuit board
that will serve as a hardware reference design for TI’s customers’ products. With
extensive host PC and target DSP software support, including bundled TI tools, the DSK
provides ease-of-use and capabilities that are attractive to DSP engineers.
The following checklist details items that are shipped with the C6713 DSK.
The C6713 DSK has a TMS320C6713 DSP onboard that allows full-speed verification of
code with Code Composer Studio. The C6713 DSK provides:
A USB Interface
SDRAM and Flash ROM
An analog interface circuit for Data conversion (AIC)
An I/O port
Embedded JTAG emulation support
Connectors on the C6713 DSK provide DSP external memory interface (EMIF) and
peripheral signals that enable its functionality to be expanded with custom or third party
daughter boards.
The DSK provides a C6713 hardware reference design that can assist you in the
development of your own C6713-based products. In addition to providing a reference for
interfacing the DSP to various types of memories and peripherals, the design also
addresses power, clock, JTAG, and parallel peripheral interfaces.The C6713 DSK
includes a stereo codec. This analog interface circuit (AIC) has the following
characteristics:
logic equations and application notes are available to ease hardware development and
reduce time to market.
An on-board AIC23 codec allows the DSP to transmit and receive analog signals.
McBSP0 is used for the codec control interface and McBSP1 is used for data. Analog
audio I/O is done through four 3.5mm audio jacks that correspond to microphone input,
line input, line output and headphone output. The codec can select the microphone or the
line input as the active input. The analog output is driven to both the line out (fixed gain)
and headphone (adjustable gain) connectors. McBSP1 can be re-routed to the expansion
connectors in software.
The DSK includes 4 LEDs and 4 DIP switches as a simple way to provide the
user with interactive feedback. Both are accessed by reading and writing to the CPLD
registers. An included 5V external power supply is used to power the board. On-board
voltage regulators provide the 1.26V DSP core voltage, 3.3V digital and 3.3V analog
voltages.
A voltage supervisor monitors the internally generated voltage, and will hold the
boards in reset until the supplies are within operating specifications and the reset button is
released. If desired, JP1 and JP2 can be used as power test points for the core and I/O
power supplies.
Eight Serial Data Pins Per Port: Individually Assignable to any of the Clock Zones
Up to 16 transmit pins
Enhanced Channel Status/User Data
Extensive Error Checking and Recovery
Two Inter-Integrated Circuit Bus (I2C Bus™) Multi-Master and Slave Interfaces
Two 32-Bit General-Purpose Timers
Dedicated GPIO Module With 16 pins (External Interrupt Capable)
Flexible Phase-Locked-Loop (PLL) Based Clock Generator Module
• IDE
• Debug IDE
• Advanced watch windows
• Integrated editor
• File I/O, Probe Points, and graphical algorithm scope probes
• Advanced graphical signal analysis
• Interactive profiling
• Automated testing and customization via scripting
• Visual project management system
• Compile in the background while editing and debugging
• Multi-processor debugging
• Help on the target DSP
Note:-
Launch the DSK help file by opening the following file using Windows Explorer.
C:\CCStudio_v3.1\docs\hlp\c6713dsk.hlp
Start Code Composer Studio (ignore this if CCS is already running) by double-clicking
on the C6713 DSK icon on your desktop.
Use the Debug Connect menu option to open a debug connection to the DSK
board
1. LINEAR CONVOLUTION
Description:-
Linear Convolution Involves the following operations.
6. Folding
7. Multiplication
8. Addition
9. Shifting
= 7.
r= 0 1 2 3 4 5 6
n= 0 x[0]h[0] x[0]h[1] x[0]h[2] x[0]h[3]
1 x[1]h[0] x[1]h[1] x[1]h[2] x[1]h[3]
2 x[2]h[0] x[2]h[1] x[2]h[2] x[2]h[3]
3 x[3]h[0] x[3]h[1] x[3]h[2] x[3]h[3]
NOTE: At the end of input sequences pad ‘n’ and ‘k’ no. of zero’s
conv.cpp:
/* prg to implement linear convolution */
#include<cstdio>
using namespace std;
int *x,*h,*y;
int main()
{
int n,m,i,j,k;
printf("Enter Sequence Lengths n and m (space seperated) : ");
scanf("%d %d",&n,&m);
int l=m+n-1;
y=new int[l];
x=new int[l];
h=new int[l];
for(i=0;i<l;i++)
{
if(i<n)
scanf("%d",&x[i]);
else x[i]=0;
}
for(i=0;i<l;i++)
for(y[i]=0,j=0;j<=i;j++)
y[i] += x[j]*h[i-j];
for(i=0;i<l;i++)
printf("%d ",y[i]);
putchar('\n');
PROCEDURE:
Open Code Composer Studio, make sure the DSP kit is turned on.
Use the Debug Connect menu option to open a debug connection to the DSK
board
Start a new project using ‘Project-new ‘ pull down menu, save it in a
separate directory(C:\CCStudio_v3.1\myprojects) with name lconv.pjt.
Add the source files conv.c
to the project using ‘Project add files to project’ pull down menu.
Add the linker command file hello.cmd .
(Path: C:\CCStudio_v3.1\tutorial\dsk6713\hello1\hello.cmd)
Add the run time support library file rts6700.lib
(Path: C:\CCStudio_v3.1\c6000\cgtools\lib\rts6700.lib)
Compile the program using the ‘Project-compile’ pull down menu or by
clicking the shortcut icon on the left side of program window.
Build the program using the ‘Project-Build’ pull down menu or by
clicking the shortcut icon on the left side of program window.
Load the program(lconv.out) in program memory of DSP chip using the
‘File-load program’ pull down menu.
2. CIRCULAR CONVOLUTION
Description:-
Steps for cyclic convolution are the same as the usual convolution, except all index
calculations are done "mod N" = "on the wheel"
//Print output
for(i=0;i<l;i++)
printf("%d ",y[i]);
putchar('\n');
}
IN PUT:
Eg: x[4]={1, 2, 3,4}
h[4]={1, 2, 3,4}
OUT PUT y[4]={26, 28, 26,20}
PROCEDURE:
Open Code Composer Studio; make sure the DSP kit is turned on.
Start a new project using ‘Project-new ‘ pull down menu, save it in a
separate directory(C:\CCStudio_v3.1\myprojects) with name cir conv.pjt.
Add the source files Circular Convolution
to the project using ‘Projectadd files to project’ pull down menu.
Add the linker command file hello.cmd.
(Path: C:\CCStudio_v3.1\tutorial\dsk6713\hello1\hello.cmd)
Add the run time support library file rts6700.lib
(Path: C:\CCStudio_v3.1\c6000\cgtools\lib\rts6700.lib)
Compile the program using the ‘Project-compile’ pull down menu or by
In mathematics, the discrete Fourier transform (DFT) is one of the specific forms
of Fourier analysis. As such, it transforms one function into another, which is called the
frequency domain representation, or simply the DFT, of the original function (which is
often a function in the time domain). But the DFT requires an input function that is
discrete and whose non-zero values have a limited (finite) duration. Such inputs are often
created by sampling a continuous function, like a person's voice. And unlike the discrete
time Fourier transform (DTFT), it only evaluates enough frequency components to
reconstruct the finite segment that was analyzed. Its inverse transform cannot reproduce
the entire time domain, unless the input happens to be periodic (forever). Therefore it is
often said that the DFT is a transform for Fourier analysis of finite-domain discrete-time
functions. The sinusoidal basis functions of the decomposition have the same properties.
#include<cstdio>
#include<cmath>
double* real;
double* imag;
double *x;
#define PI 3.14159265
int main(void)
int l,i=0;
scanf("%d",&l);
real=new double[l];
imag=new double[l];
x=new double[l];
while(i<l)
scanf("%le",&x[i++]);
for (i=0;i<l;i++)
real[i]=imag[i]=0;
putchar('\n');
for(int k=0;k<l;k++)
real[k]+= double(x[j])*cos(2*PI*k*j/l);
imag[k]-= double(x[j])*sin(2*PI*k*j/l);
//Print answer
for (i=0;i<l;i++)
return 0;
PROCEDURE:
Open Code Composer Studio, make sure the DSP kit is turned on.
Use the Debug Connect menu option to open a debug connection to the DSK
board
Start a new project using ‘Project-new ‘ pull down menu, save it in a
separate directory(C:\CCStudio_v3.1\myprojects) with name dft.pjt.
Add the source files dft.c
to the project using ‘Projectadd files to project’ pull down menu.
Add the linker command file hello.cmd .
(Path: C:\CCStudio_v3.1\tutorial\dsk6713\hello1\hello.cmd)
Add the run time support library file rts6700.lib
(Path: C:\CCStudio_v3.1\c6000\cgtools\lib\rts6700.lib)
Compile the program using the ‘Project-compile’ pull down menu or by
clicking the shortcut icon on the left side of program window.
Build the program using the ‘Project-Build’ pull down menu or by
clicking the shortcut icon on the left side of program window.
Load the program(dft.out) in program memory of DSP chip using the
‘File-load program’ pull down menu.
Note:- To use microphone input change the analog audio path control register
value (Register no. 4) in Codec Configuration settings of the Source file
(Codec.c) from 0x0011 to 0x0015.
2. Connect CRO/Desktop Speakers to the Socket Provided for LINE OUT or connect a
headphone to the Headphone out Socket.
3. Now Switch on the DSK and Bring Up Code Composer Studio on the PC.
4. Use the Debug Connect menu option to open a debug connection to the DSK
board
8. Automatically three files are added in the Generated file folder in project pane
xyzcfg.cmd Command and linking file
xyzcfg.s62 optimized assembly code for configuration
xyzcfg_c.c Chip support initialization
Important note: Save your source code with preferred language extension. For
ASM codes save the file as code(.asm) For C and C++ codes code (*.c,*.cpp)
respectively.
11. Add the saved “Codec.c” file to the current project which has the main function and
calls all the other necessary routines.
Project Add files to Project Codec.c
13. Copy header files “dsk6713.h” and “dsk6713_aic23.h” from and paste it in current
project folder.
C:\CCStudio_v3.1\C6000\dsk6713\include.
Note:- Double click on xyzcfg_c.c. Copy the first line header (eg.#include
“xyzcfg.h”) and paste that in source file (eg.codec.c).
15. Compile the program using the ‘Project-compile’ pull down menu or by
Clicking the shortcut icon on the left side of program window.
16. Build the program using the ‘Project-Build’ pull down menu or by clicking the
shortcut icon on the left side of program window.
17. Load the program (Codec. Out) in program memory of DSP chip using the
‘File-load program’ pull down menu.
19. You can notice the input signal of 500 Hz. appearing on the CRO verifying the codec
configuration.
20. You can also pass an audio input and hear the output signal through the speakers.
21. You can also vary the sampling frequency using the DSK6713_AIC23_setFreq
Function in the “codec.c” file and repeat the above steps.
5.0 Conclusion:
The codec TLV320AIC23 successfully configured using the board support library
and verified.
III. Compute the desired Impulse Response h d (n) using particular Window
Eg: b_rect1=fir1 (order, Wc , 'high',boxcar(31));
IV. Convolve input sequence with truncated Impulse Response x (n)*h (n)
The cut-off frequency Wn must be between 0 < Wn < 1.0, with 1.0
B(N+2-k), k = 1,2,...,N+1.
If Wn is a multi-element vector,
For filters with a passband near Fs/2, e.g., highpass and bandstop filters, N must be
even.
By default, the filter is scaled so the center of the first pass band has magnitude exactly
one after windowing. Use a trailing 'noscale' argument to prevent this scaling,
e.g. B = FIR1(N,Wn,'noscale'),
B = FIR1(N,Wn,'high','noscale'), B = FIR1(N,Wn,wind,'noscale').
% FIR Low pass filters using rectangular, triangular and kaiser windows
order = 50;
b_rect1=fir1(order,cf(1),boxcar(51)); %Rectangular
b_tri1=fir1(order,cf(1),bartlett(51)); %Triangular
b_rect2=fir1(order,cf(2),boxcar(51));
b_tri2=fir1(order,cf(2),bartlett(51));
b_kai2=fir1(order,cf(2),kaiser(51,8));
b_rect3=fir1(order,cf(3),boxcar(51));
b_tri3=fir1(order,cf(3),bartlett(51));
b_kai3=fir1(order,cf(3),kaiser(51,8));
fid=fopen('FIR_lowpass_rectangular.txt','wt');
fprintf(fid,'\t\t\t\t\t\t%s\n','Cutoff -400Hz');
fprintf(fid,'\nfloat b_rect1[31]={');
fprintf(fid,'%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,\n',b_rect1);
fseek(fid,-1,0);
fprintf(fid,'};');
fprintf(fid,'\n\n\n\n');
fprintf(fid,'\t\t\t\t\t\t%s\n','Cutoff -800Hz');
fprintf(fid,'\nfloat b_rect2[31]={');
fprintf(fid,'%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,\n',b_rect2);
fseek(fid,-1,0);
fprintf(fid,'};');
fprintf(fid,'\n\n\n\n');
fprintf(fid,'\t\t\t\t\t\t%s\n','Cutoff -1200Hz');
fprintf(fid,'\nfloat b_rect3[31]={');
fprintf(fid,'%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,\n',b_rect3);
fseek(fid,-1,0);
fprintf(fid,'};');
fclose(fid);
winopen('FIR_highpass_rectangular.txt');
T.1 : Mat lab generated Coefficients for FIR Low Pass Kaiser filter:
Cutoff -500Hz
float b_kai1[51]={-0,0,0.0001,0.0002,0.0005,0.0008,0.0012,0.0013,0.001,-0,-0.0018,-
0.0045,
-0.0076,-0.0106,-0.0125,-0.0121,-
0.0082,0,0.0129,0.0302,0.0506,0.0723,0.0929,0.1099,0.1211,0.125,0.1211,0.1099,0.0929,
0.0723,0.0506,0.0302,0.0129,0,-0.0082,-0.0121,-0.0125,-0.0106,-0.0076,-0.0045,-
0.0018,-0,0.001,0.0013,0.0012,0.0008,0.0005,0.0002,0.0001,0,-0};
Cutoff -1000Hz
IMPLEMENTATION OF AN FIR FILTER :
float b_kai2[51]={- 0,-0,-0.0001,-0.0003,-0.0004,0,0.0009,0.0019,0.0018,-0,-0.0034,-
0.0064,-0.0059,0,0.0096,0.0171,0.0152,-0,-0.0238,-0.0426,-
0.0387,0,0.0711,0.1554,0.2237,0.25,0.2237,0.1554,0.0711,0,-0.0387,-0.0426,-0.0238,-
ALGORITHM TO IMPLEMENT :
0,0.0152,0.0171,0.0096,0,-0.0059,-0.0064,-0.0034,-0,0.0018,0.0019,0.0009,0,-0.0004,-
0.0003,-0.0001,-0,0};
We need -1500Hz
Cutoff to realize an advance FIR filter by implementing its difference equation as per
float
the b_kai3[51]={ A
specifications. 0,0.0001,0.0002,0.0001,-0.0003,-0.0008,-
direct form I implementation approach is taken. (The filter
0.001,0,0.002,0.0035,0.0024,-0.0022,-0.0078,-0.0092,-0.0023,0.011,0.0214,0.0173,-
coefficients are taken as ai as generated by the Matlab program.)
0.0059,-0.0369,-0.0514,-0.0247,0.0503,0.153,0.2424,0.2778,0.2424,0.153,0.0503,-
0.0247,-0.0514,-0.0369,-0.0059,0.0173,0.0214,0.011,-0.0023,-0.0092,-0.0078,-
0.0022,0.0024,0.0035,0.002,0,-0.001,-0.0008,-0.0003,0.0001,0.0002,0.0001,0};
•
•
T.2 :Matlab generated Coefficients for FIR Low Pass Rectangular filter
Cutoff -500Hz
float b_rect1[51]={-0.0046,0,0.005,0.0097,0.0133,0.0151,0.0147,0.0118,0.0068,-0,-
0.0077,-0.0152,-0.0214,-0.0251,-0.0253,-0.0213,-
0.0128,0,0.0165,0.0355,0.0557,0.0754,0.0929,0.1066,0.1154,0.1184,0.1154,0.1066,0.092
9,0.0754,0.0557,0.0355,0.0165,0,-0.0128,-0.0213,-0.0253,-0.0251,-0.0214,-0.0152,-
0.0077,-0,0.0068,0.0118,0.0147,0.0151,0.0133,0.0097,0.005,0,-0.0046};
Cutoff -1000Hz
float b_rect2[51]={-0.0091,-0,-0.0099,-0.0147,-0.0109,0,0.012,0.0179,0.0134,-0,-0.0152,-
0.0231,-0.0176,0,0.0207,0.0323,0.0254,-0,-0.0326,-0.0538,-
0.0456,0,0.0761,0.1614,0.2282,0.2535,0.2282,0.1614,0.0761,0,-0.0456,-0.0538,-0.0326,-
0,0.0254,0.0323,0.0207,0,-0.0176,-0.0231,-0.0152,-0,0.0134,0.0179,0.012,0,-0.0109,-
0.0147,-0.0099,-0,0.0091};
Cutoff -1500Hz
float b_rect2[51]={- 0.0021,0.0112,0.0126,0.0048,-0.0074,-0.0152,-
0.0125,0,0.0139,0.019,0.0103,-0.0076,-0.0224,-0.0223,-0.0049,0.0199,0.0344,0.0249,-
0.0077,-0.0447,-0.0582,-0.0265,0.0516,0.1524,0.237,0.27,0.237,0.1524,0.0516,-0.0265,-
0.0582,-0.0447,-0.0077,0.0249,0.0344,0.0199,-0.0049,-0.0223,-0.0224,-
0.0076,0.0103,0.019,0.0139,0,-0.0125,-0.0152,-0.0074,0.0048,0.0126,0.0112,0.0021};
T.3: Mat lab generated Coefficients for FIR Low Pass Triangular filter
Cutoff -500Hz
float b_tri1[51]={ [0,0,0.0005,0.0013,0.0024,0.0034,0.004,0.0037,0.0024,-0,-0.0035,-0.0075,-
0.0116,-0.0147,-0.016,-0.0144,-
0.0092,0,0.0134,0.0304,0.0502,0.0713,0.092,0.1105,0.1248,0.1334,0.1248,0.1105,0.092,0.0713
,0.0502,0.0304,0.0134,0,-0.0092,-0.0144,-0.016,-0.0147,-0.0116,-0.0075,-0.0035,-
0,0.0024,0.0037,0.004,0.0034,0.0024,0.0013,0.0005,0,0;]};
Cutoff -1000Hz
float b_tri2[51]={ 0,-0,-0.0008,-0.0018,-0.0018,0,0.0029,0.0051,0.0044,-0,-0.0062,-0.0103,-
0.0086,0,0.0118,0.0197,0.0165,-0,-0.0239,-0.0416,-
0.0372,0,0.0682,0.1512,0.2232,0.2582,0.2232,0.1512,0.0682,0,-0.0372,-0.0416,-0.0239,-
0,0.0165,0.0197,0.0118,0,-0.0086,-0.0103,-0.0062,-0,0.0044,0.0051,0.0029,0,-0.0018,-0.0018,-
0.0008,-0,0};
Cutoff -1500Hz
float b_tri3[51]={ 0,0.0005,0.0011,0.0006,-0.0012,-0.0032,-0.0032,0,0.0047,0.0073,0.0044,-
0.0035,-0.0114,-0.0123,-0.0029,0.0126,0.0233,0.0179,-0.0058,-0.0359,-0.0492,-
0.0235,0.048,0.1483,0.2407,0.2857,0.2407,0.1483,0.048,-0.0235,-0.0492,-0.0359,-
0.0058,0.0179,0.0233,0.0126,-0.0029,-0.0123,-0.0114,-0.0035,0.0044,0.0073,0.0047,0,-
0.0032,-0.0032,-0.0012,0.0006,0.0011,0.0005,0};
START
Initialize Counter = 0
Initialize Output = 0 , i =
0
Output += coeff[N-
i]*val[i]
Shift the input value by
one
NO
Is the loop
Cnt =
order
Output += coeff[0]*data
Put the ‘data’ in ‘val’
array.
fir.c
#include "xyzcfg.h"
#include "dsk6713.h"
#include "dsk6713_aic23.h"
DSK6713_AIC23_Config config = {\
0x0017, /* 0 DSK6713_AIC23_LEFTINVOL Leftline 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 */ \
};
/*
void main()
{
DSK6713_AIC23_CodecHandle hCodec;
DSK6713_AIC23_setFreq(hCodec, 1);
while(1)
{ /* Read a sample to the left channel */
while (!DSK6713_AIC23_read(hCodec, &l_input));
l_output=(Int16)FIR_FILTER(&filter_Coeff ,l_input);
r_output=l_output;
HOW TO PROCEED:
Note:- To use microphone input change the analog audio path control register
value (Register no. 4) in Codec Configuration settings of the Source file (Fir.c)
from 0x0011 to 0x0015.
3. Now Switch on the DSK and Bring Up Code Composer Studio on the PC.
4. Use the Debug Connect menu option to open a debug connection to the DSK
board
5. Create a new project with name Fir.pjt.
8. Automatically three files are added in the Generated file folder in project pane
xyzcfg.cmd Command and linking file
xyzcfg.s62 optimized assembly code for configuration
xyzcfg_c.c Chip support initialization
Important note: Save your source code with preferred language extension. For
ASM codes save the file as code(.asm) For C and C++ codes code (*.c,*.cpp)
respectively.
11. Add the saved “Fir.c” file to the current project which has the main function and
calls all the other necessary routines.
Project Add files to Project Codec.c
Path “C:\CCStudio_v3.1\C6000\dsk6713\lib\dsk6713bsl.lib”
13. Copy header files “dsk6713.h” and “dsk6713_aic23.h” from and paste it in
current project folder.
C:\CCStudio_v3.1\C6000\dsk6713\include.
Note:- Double click on xyzcfg_c.c Copy the first line header (eg.xyzcfg.h) and paste
that in source file (eg.Fir.c).
15. Compile the program using the ‘Project-compile’ pull down menu or by
Clicking the shortcut icon on the left side of program window.
16. Build the program using the ‘Project-Build’ pull down menu or by clicking the
shortcut icon on the left side of program window.
17. Load the program (Codec.out) in program memory of DSP chip using the
‘File-load program’ pull down menu.
Audio Application
This version of project makes use of RTDX with MATLAB for transferring data from the
DSK to the PC host. This section introduces configuration file(.CDB) file and RTDX
with MATLAB.
This project uses source program spectrogram_rtdx_mtl.c that runs on the DSK which
computes 256 point FFT and enables an RTDX output channel to write/send the resulting
FFT data to the PC running MATLAB for finding the spectrogram. A total of N/2 (128
points )are sent. The (.CDB) configuration file is used to set interrupt INT11. From this
configuration file select Input/Output RTDX. Right click on properties and change the
RTDX buffer size to 8200. Within CCS, select tools RTDX Configure to set the
host buffer size to 2048(from 1024).
An input signal is read in blocks of 256 samples. Each block of data is then multiplied
with a hamming window of length 256 points. The FFT of the windowed data is
calculated and squared. Half of the resulting FFT of each block of 256 points is then
transferred to the PC running MATLAB to find the specrtrogram.
main()
{
for (i = 0 ; i<PTS ; i++) //set up twiddle constants in w
{
w[i].real = cos(2*PI*i/512.0); //Re component of twiddle constants
w[i].imag =-sin(2*PI*i/512.0); //Im component of twiddle constants
}
comm_intr(); //init DSK, codec, McBSP
}
j = 0;
for (i = 1; i < (N-1); i++) //bit reversal for resequencing data
{
k = N/2;
while (k <= j)
{
j = j - k;
k = k/2;
}
j = j + k;
if (i<j)
{
temp1.real = (Y[j]).real;
temp1.imag = (Y[j]).imag;
(Y[j]).real = (Y[i]).real;
(Y[j]).imag = (Y[i]).imag;
(Y[i]).real = temp1.real;
(Y[i]).imag = temp1.imag;
}
}
return;
}
clc;
ccsboardinfo %board info
cc=ccsdsp('boardnum',0); %set up CCS object
reset(cc); %reset board
visible(cc,1); %for CCS window
enable(cc.rtdx); %enable RTDX
if ~isenabled(cc.rtdx);
error('RTDX is not enabled')
end
cc.rtdx.set('timeout',50); %set 50sec timeout for RTDX
open(cc,'spectrogram1.pjt'); %open CCS project
load(cc,'./debug/spectrogram1.out'); %load executable file
run(cc); %run program
configure(cc.rtdx,2048,1); %configure one RTDX channel
open(cc.rtdx,'ochan','r'); %open output channel
pause(3) %wait for RTDX channel to open
enable(cc.rtdx,'ochan'); %enable channel from DSK
isenabled(cc.rtdx,'ochan');
M = 256; %window size
N = round(M/2);
B = 128; %No. of blocks (128)
fs = 8000; %sampling rate
t=(1:B)*(M/fs); %spectrogram axes generation
f=((0:(M-1)/2)/(M-1))*fs;
set(gcf,'DoubleBuffer','on');
y = ones(N,B);
column = 1;
set(gca,'NextPlot','add');
axes_handle = get(gcf,'CurrentAxes');
set(get(axes_handle,'XLabel'),'String','Time (s)');
set(get(axes_handle,'YLabel'),'String','Frequency (Hz)');
set(get(axes_handle,'Title'),'String','\fontname{times}\bf Real-Time Spectrogram');
set(gca,'XLim', [0 4.096]);
set(gca,'YLim', [0 4000]);
set(gca,'XLimMode','manual');
set(gca,'YLimMode','manual');
for i = 1:32768
w=readmsg(cc.rtdx,'ochan','single'); %read FFT data from DSK
w=double(w(1:N));
y(:, column) = w';
imagesc(t,f,dB(y)); %plot spectrogram
column = mod(column, B) + 1;
end
halt(cc); %halt processor
close(cc.rtdx,'ochan'); %close channel
clear cc %clear object
NOTE: For this example works with CCS 2.2 and Matlab 6.5.
Procedure:
6) spectrogram_RTDX.m
6 Build project.
7. Close CCS
#include "xyzcfg.h"
#include "dsk6713.h"
#include "dsk6713_aic23.h"
#define beta 1E-12 //rate of convergence
#define N 30
short int adaptive_filter(short int ,short int );
float delay[N];
float w[N];
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 */ \
};
/*
DSK6713_AIC23_setFreq(hCodec, 1);
while(1)
{
l_output=(short int)adaptive_filter(l_input,r_input);
r_output=l_output;
desired = l_input1;
noise = r_input1;
dplusn = desired + noise; //desired+noise
delay[0] = noise; //noise as input to adapt FIR
}
output=((short)E); //error signal as overall output
//output=((short)dplusn);//output (desired+noise)
//overall output result
return(output);
}
PROCEDURE :
7. IMPULSE RESPONSE
‘CPP’ Program to Implement Impulse response:
Y(z)/X(z) = Numerator(z)/Denominator(z)
Then asks for the Order of the coefficients of 'a' i.e., The magnitude of
the maximum power of the denominator of the transfer function.
Then input the coefficients of a: a0 a1 a2 ...
The Progam then prints 'L' values of h[n] (from n=0->L-1) Impulse
response for the given equation for an Impulse Input.
Sample Output:
The above output is generated for an input of: y[n] - 0.5*y[n-1] = x[n]
which has a Transfer Function of :
#include <cstdio>
double *y,*b,*a;
int main(void)
int N,M,L,i,j;
scanf("%d",&N);
b= new double[++N];
for(i=0;i<N;i++)
scanf("%le",&b[i]);
scanf("%d",&M);
a=new double[++M];
for(i=0;i<M;i++)
scanf("%le",&a[i]);
scanf("%d",&L);
y=new double[L];
for(int n=0;n<L;n++)
y[n]=0;
for(j=1;j<M;j++)
if((n-j)>=0)
y[n] -=a[j]*y[n-j];
for(i=0;i<N;i++)
if(!(n-i))
y[n]+=b[i];
return 0;
PROCEDURE:
Open Code Composer Studio, make sure the DSP kit is turned on.
Use the Debug Connect menu option to open a debug connection to the DSK
board
Start a new project using ‘Project-new ‘ pull down menu, save it in a
separate directory(C:\CCStudio_v3.1\myprojects) with name
Impulse_response.pjt.
Add the source files impulse_res.c
to the project using ‘Projectadd files to project’ pull down menu.
Add the linker command file hello.cmd .
(Path: C:\CCStudio_v3.1\tutorial\dsk6713\hello1\hello.cmd)
Add the run time support library file rts6700.lib
(Path: C:\CCStudio_v3.1\c6000\cgtools\lib\rts6700.lib)
Compile the program using the ‘Project-compile’ pull down menu or by
clicking the shortcut icon on the left side of program window.