Professional Documents
Culture Documents
DSP Report
DSP Report
VENKATARAGHAVAN.T
USN
1CR07TE057
SEM/BRANCH
LABORATORY CERTIFICATE
This is to certify that Mr.VENKATARAGHAVAN.T
bearing USN 1CR07TE057 has satisfactorily completed the course of
experiments in DIGITAL SIGNAL PROCESSING
Laboratory(06ECL57) prescribed by the VTU for 5th semester BE
TELECOMUNICATION course in the laboratory of this college in
the year 2008 2009.
DATE:
Signature of HOD
(Mrs.Pakia Rani)
1C
CONTENTS
MATLAB Programs
II.
III.
IV.
QUESTION BANK
MATLAB PROGRAMS
1. Write a MATLAB program to verify the sampling theorem for the following
three cases
Right sampling
Under sampling
Over sampling
2. Write a MATLAB program to determine the impulse response of the given
system whose difference equation is given by: y (n) y (n-1) + 1/8 y (n-2) = x
(n) 1/3 x (n-1).
3. Write a MATLAB program to compute the N-Point DFT of the sequence
x(n) = {1,1,1,1} taking N=4 and N=8.
4. Write a MATLAB program to perform the linear convolution of the sequences
given
x1(n) = {1, 2, 3, 4, 5}
x2(n) = {2, 3, 4}
5. Write a MATLAB program to perform circular convolution of the given
sequences
x1(n) = {1, 2, 3, 4} and x2(n) = {4, 3, 2, 2}
6. Write a MATLAB program to perform linear convolution of the given sequences
x1(n) = {2, 3, 4, 0}
x2(n) = {2, 1, 0, 0} by using DFT and IDFT method.
7. Write a MATLAB program to perform circular convolution of the given
sequences
x1(n) = {1, 2, 3, 4}
x2(n) = {4, 3, 2, 2} by using DFT and IDFT method.
8. Write a MATLAB program to compute the autocorrelation of the given
sequence and verify its properties.
X = {1, 2, 3, 6, 2, 4}
9. Write a MATLAB program to find the cross correlation of the given two
sequences
x = {1, 2, 4, 6, 5} and y = {1, 3, 2, 1, 4}
11. Using MATLAB design an IIR filter with pass band edge frequency at 1500Hz
and stop band edge at 2000Hz for a sampling frequency of 8000Hz.passband
attenuation is 1dB and stop band attenuation is 15dB. Use butter worth
prototype design and bilinear transformation.
12. Using MATLAB design an FIR filter with pass band edge frequency at 1500Hz
and stop band edge at 2000Hz for a sampling frequency of 8000Hz.passband
attenuation is 1dB and stop band attenuation is 15dB. Use chebyshev prototype
design and bilinear transformation.
PART B
Code Composer Studio Programs
1. Find out the Discrete Time Convolution of the sequences x(n)={1 2 3 4 5 6} and
h(n)={1 2 3 4}, using Code Composer Studio. Verify the results graphically.
2. Perform Circular Convolution of the given sequence using Code Composer
Studio.
3. Compute the response of the system whose co-efficients are a0=0.1311, a1=0.2622,
a2=0.1311 and b0=1, b1= -0.7478, b2=0.2722, when the input is a unit impulse
signal.
4.
PROGRAM 1:
PROBLEM:
Using MATLAB, sample a band limited continuous time signal, band limited to fm=400Hz
under the following conditions:
1. Nyquist rate
2. Under sampling
3. Over sampling
MATLAB CODE:
s=800;
t=0:1/ s:256/ s;
X=sin(2*pi*400*t);
Xm=abs(fft(X));
K=0:length(X)-1;
Subplot(2,2,1);
Stem(k,Xm);
xlabel(Hz);
ylabel(Magnitude);
title(Nyquist Rate Sampling);
s=200;
t=0:1/ s:256/ s;
X=sin(2*pi*400*t);
Xm=abs(fft(X));
K=0:length(X)-1;
Subplot(2,2,2);
Stem(k,Xm);
xlabel(Hz);
ylabel(Magnitude);
title(Under Sampling);
s=1000;
t=0:1/ s:256/ s;
X=sin(2*pi*400*t);
Xm=abs(fft(X));
K=0:length(X)-1;
Subplot(2,2,3);
Stem(k,Xm);
xlabel(Hz);
ylabel(Magnitude);
title(Over Sampling);
OUTPUT:
PROGRAM 2:
PROBLEM:
Obtain the Impulse response of a system described by the difference equationy(n)-3/4 y(n-1)+1/8 y(n-2) = x(n)-1/3 x(n-1)
Solution:
Y(z) - 3/4 Y(z)z-1 + 1/8 Y(z)z-2 = X(z) - 1/3 X(z) z-1
H(z) = Y(z) / X (z) = (1-1/3 z-1) / (1-3/4 z-1+1/8 z-2)
Applying partial fractions ,
H (z) = (1-1/3 z-1) / (1-1/2 z-1)(1-1/4 z-1) = A / (1-1/2 z-1) + B / (1-1/4 z-1)
A=2/3;
B=1/3;
H(z) = (2/3) / (1-1/2 z-1) + (1/3) / (1-1/4 z-1)
h(n) = (2/3) (1/2)n u(n) + (1/3) (1/4)n u(n)
h(0)=1
h(1)=0.416
h(2)=0.187
h(3)=0.088
h(4)=0.0429
h(5)=0.02116
h(6)=0.0105
h(7)=0.0052
h(8)=0.0026
h(9)=0.0013
MATLAB CODE:
N=input('enter the length of impulse response');
b=input('enter the numerator coeff');
a=input('enter the denominator coeff');
[r,p,k]=residuez(b,a)
[h,t]=impz(b,a,N)
stem(t,h);
grid;
xlabel('time index');
ylabel('amplitude');
title('impulse response');
INPUT:
enter the length of impulse response 5
OUTPUT:
r=
0.6667
0.3333
p=
0.5000
0.2500
k=
[]
h=
1.0000
0.4167
0.1875
0.0885
0.0430
0.0212
PROGRAM 3:
PROBLEM:
Obtain the N point- dft of the sequence x (n) = {1 1 1 1}
Case1: With N=4
Solution:
1
-j
-1
4
0
=
-1
-1
-1
-j
MATLAB CODE:
x1=input('enter the sequence X1=');
N=input('enter the value of N=');
xk=fft(x1,N)
subplot(2,2,1);
n=0:1:length(xk)-1;
stem(n,abs(xk));
disp(abs(xk));
xlabel('time index');
ylabel('amplitude');
title('magnitude plot');
subplot(2,2,2);
stem(n,angle(xk));
disp(angle(xk));
xlabel('time index');
ylabel('amplitude');
title('angle plot');
xk1=ifft(xk,N)
subplot(2,2,3);
stem(n,(xk1));
xlabel('time index');
ylabel('amplitude');
title('inverse fourier transform');
Case2: With N=8
1
0
1
W 20
W2 0
W2 0
-1
-1
W40
-1
1 W 20
W2 0
-1
1
W41
W2 0
-1
-1
1
W20
-1
1
0
1-j
1j2.414
1+j
1-j0.414
W20
1
-1
W8
W8
W8
0
-1
1+j0.414
1-j
W4
W41
-1
-1
1 + j W8
-1
3
-1
1+j2.414
1
-1
INPUT:
Case1:
enter the sequence X1=[1 1 1 1]
enter the value of N=5
Case2:
enter the sequence X1=[1 1 1 1]
enter the value of N=8
OUTPUT:
Case1:
xk =
4 0
GRAPH:
Case2:
xk =
Columns 1 through 5
4.0000
1.0000 - 2.4142i
1.0000 - 0.4142i
Columns 6 through 8
1.0000 + 0.4142i
4.0000
0 1.0824
2.6131
0 -1.1781
0 -0.3927
1.0000 + 2.4142i
0
0
1.0824
0.3927
0
0
2.6131
1.1781
GRAPH:
PROGRAM 4:
The output using the convolution operation, is: y(t) = x(t) * h(t)
The asterisk operator means convolution.
LINEAR CONVOLUTION:
Let x1(n) be the input sequence and h(n) be the impulse response of the system as shown
below.i.e
y(n)=x1(n)*h(n)
where y(n) is the output sequence.
h(n)
X1(n)
y(n)
Solution:
1
2
2
4
3
6
4
8
5
10
12
15
12
16
20
MATLAB CODE:
X1=input('First Sequence');
X2=input('Second Sequence');
subplot(2,2,1);
n1=0:1:length(X1)-1;
stem(n1,X1);
xlabel('Time');
ylabel('Amplitude');
title('First sequence');
subplot(2,2,2);
n2=0:1:length(X2)-1;
stem(n2,X2);
xlabel('Time');
Department of Telecommunication CMRIT
ylabel('Amplitude');
title('Second Sequence');
Y=conv(X1,X2)
subplot(2,2,3);
n3=0:1:length(Y)-1;
stem(n3,Y);
xlabel('Time');
ylabel('Amplitude');
title('Linear Convolution Output');
INPUT:
first sequence=[1 2 3 4 5]
second sequence=[2 3 4]
OUTPUT:
Y=
2
16
25
34 31
20
GRAPH:
10
PROGRAM 5:
Circular Convolution
THEORY:
A circular convolution of two functions is defined in terms of the periodic extension of
one or both functions. Periodic extension means a new function is formed by shifting the
original function by multiples of some period, T, and adding all the copies together.
PROBLEM:
For a given two sequences x(n) and h(n) compute the circular convolution.
Solution:
Finding Circular convolution using Matrix method:
Y=
26
25
=
28
31
MATLAB CODE:
x=input('Enter the sequence x(n) ');
h=input('Enter the sequence h(h) ');
N1=length(x);
N2=length(h);
N=max(N1,N2);
N3=N1N2;
if(N3>0)
h=[h zeros(1,N3)];
else
x=[x zeros(1,N3);];
end
disp('Sequence x(n) ');
disp(x);
disp('Sequence h(n) ');
disp(h);
n=1:N;
disp(n);
y=0;
for m=1:N
disp(m);
y=y+x(m)*h(mod(n-m,N)+1)
11
end
disp('circular covolution');
disp(y);
subplot(2,2,1);
stem(n,x);
title('Sequence x(n)');
xlabel('n');
ylabel('Amplitude');
subplot(2,2,2);
stem(n,h);
title('Sequence h(n)');
xlabel('n');
ylabel('Amplitude');
subplot(2,2,3);
stem(n,y);
title('Sequence y(n)');
xlabel('n');
ylabel('Amplitude');
INPUT:
Enter the sequence x(n) [1 2 3 4]
Enter the sequence h(h) [4 3 2 2]
OUTPUT:
y=
26
25
28
12
PROGRAM 6:
PROBLEM:
X1 =
X2 =
-j
-1
-2-3j
-1
-1
-1
-j
-j
-1
2-j
-1
-1
-1
-j
4
-2+3j
1
2+j
Y=X1*X2
Y={27, -7-4j, 3, -7+4j}
Finding IDFT of Y
Department of Telecommunication CMRIT
13
Y=
27
16
-1
-j
-7-4j
-1
-1
44
-j
-1
-7+4j
16
32
MATLAB CODE:
x1=input('Enter the sequence x1(n) ');
x2=input('Enter the sequence x2(n) ');
N1=length(x1);
N2=length(x2);
N3=N1+N2-1;
if (N3>N2)
x2=[x2 zeros(1,N3-N2)];
end
if (N3>N1)
x1=[x1 zeros(1,N3-N1)];
end
X1=fft(x1,N3)
X2=fft(x2,N3)
Y=X1.*X2;
y=ifft(Y,N3)
subplot(3,1,1);
n1=0:1:length(x1)-1;
stem(n1,x1);
xlabel('Time');
ylabel('Amplitude');
title('First Sequence');
subplot(3,1,2);
n2=0:1:length(x2)-1;
stem(n2,x2);
xlabel('Time');
ylabel('Amplitude');
title('Second Sequence');
subplot(3,1,3);
n=0:1:length(y)-1;
stem(n,y);
xlabel('Time');
14
ylabel('Amplitude');
title('Linear Convolution using DFT and IDFT');
INPUT:
Enter the sequence x1(n) [2 3 4 0]
Enter the sequence x2(n) [2 1 0 0]
OUTPUT:
X1 =
Columns 1 through 5
9.0000
2.9804 - 6.2452i -2.2714 - 1.1892i 1.7911 + 1.8257i 1.7911 - 1.8257i
Columns 6 through 7
-2.2714 + 1.1892i 2.9804 + 6.2452i
X2 =
Columns 1 through 5
3.0000
2.6235 - 0.7818i 1.7775 - 0.9749i 1.0990 - 0.4339i 1.0990 + 0.4339i
Columns 6 through 7
1.7775 + 0.9749i 2.6235 + 0.7818i
y=
4.0000
8.0000 11.0000
4.0000
0.0000
0.0000
0.0000
15
PROGRAM 7:
PROBLEM:
Write a MatLab program to compute the circular convolution using DFT IDFT method
for the given to sequences.
Solution:
Finding the DFT of the two input sequences:
X1 =
X2 =
10
-j
-1
-2+2j
-1
-1
-1
-j
-2
-2-2j
11
-j
-1
-1
-1
2-j
=
1
-1
-j
2+j
Y=X1*X2
Y={110, -2+6j, -2, -2-6j}
Department of Telecommunication CMRIT
16
Finding IDFT of Y
1
110
104
-1
-j
-2+6j
-1
-1
-2
112
-j
-1
-2-6j
124
100
MATLAB CODE:
x1 = input('Enter the first sequence');
x2 = input('Enter the second sequence');
N1= length(x1);
N2= length(x2);
N=max(N1,N2);
N3=N1-N2;
if(N3>0)
x2=[x2 zeros(1,N3)];
else
x1=[x1 zeros(1,N3)];
end
X1=fft(x1,N)
X2=fft(x2,N)
y=X1.*X2
y=ifft(y,N)
subplot(3,1,1);
n1=0:1:length(X1)-1;
stem(n1,X1);
xlabel('Time');
ylabel('Amplitude');
title('First sequence');
subplot(3,1,2);
n2=0:1:length(X2)-1;
stem(n2,X1);
xlabel('Time');
ylabel('Amplitude');
title('Second sequence');
subplot(3,1,3);
n=0:1:length(y)-1;
stem(n,y);
xlabel('Time');
ylabel('Amplitude');
title('Circular Convolution using DFT and IDFT');
OUTPUT:
X1 = 10.0000
-2.0000 - 2.0000i
17
X2 = 11.0000
y=
26
25
2.0000 + 1.0000i
31
18
PROGRAM 8:
Auto Correlation
THEORY:
Autocorrelation is a mathematical tool for finding repeating patterns, such as the presence
of a periodic signal which has been buried under noise, or identifying the missing
fundamental frequency in a signal implied by its harmonic frequencies. It is used
frequently in signal processing for analyzing functions or series of values, such as time
domain signals. Informally, it is the similarity between observations as a function of the
time separation between them. More precisely, it is the cross-correlation of a signal with
itself.
PROBLEM:
Write a MatLab program to compute the auto correlation of the given sequence and verify
its properties.
Solution:
1
8
2
12
4
6
24
6
12
3
8
12
18
6
2
16
4
36
9
4
1
8
12
18
6
2
24
6
12
3
12
4
6
8
2
70
46
45
22
10
10
22
45
46
MATLAB CODE:
x=[1 2 3 6 2 4];
subplot(2,2,1);
n=0:1:length(x)-1;
stem(n,x);
xlabel('n');
ylabel('amplitude');
title('input sequence');
Rxx=xcorr(x,x);
subplot(2,2,2);
nRxx=-length(x)+1:length(x)-1;
stem(nRxx,Rxx);
xlabel('auto correlation axis');
ylabel('auto correlation magnitude');
title('auto correlation output');
%verification of properties
energy=sum(x.^2)
center_index=ceil(length(Rxx)/2)
Rxx_0=Rxx(center_index)
19
if Rxx_0==energy
disp('Rxx(0) gives energy - proved');
else
disp('Rxx(0) gives energy - not proved');
end
Rxx_right=Rxx(center_index:1:length(Rxx))
Rxx_left=Rxx(center_index:-1:1)
if Rxx_right == Rxx_left
disp('Rxx is even');
else
disp('Rxx is odd');
end
OUTPUT:
energy =
70
center_index =
Rxx_0 =
70
70
70
46
46
45
45
22
22
10
10
4
4
Rxx is even
20
PROGRAM 9:
Cross correlation
THEORY:
In signal processing, cross-correlation is a measure of similarity of two waveforms as a
function of a time-lag applied to one of them. This is also known as a sliding dot product
or inner-product. It is commonly used to search a long duration signal for a shorter,
known feature. It also has applications in pattern recognition and cryptanalysis.For
continuous functions f and g the cross-correlation is defined as:
PROBLEM:
Compute the cross correlation of the two sequences.
Solution:
16
24
20
12
10
12
18
15
41
31
32
21
3
2
1
4
4
20
35
MATLAB CODE:
X=[1 2 4 6 5]
Y=[1 3 2 1 4]
n = 0:1:length(X)-1;
m = 0:1:length(Y)-1;
subplot(2,2,1);
stem(n,X);
xlabel('n');
ylabel('amplitude');
title('input1 sequence');
subplot(2,2,2);
stem(m,Y);
xlabel('n');
ylabel('amplitude');
Department of Telecommunication CMRIT
21
title('input2 sequence');
RXY = Xcorr(X,Y)
nRXY = -length(X) +1:length(X)-1
subplot(2,2,3);
stem(nRXY,RXY);
xlabel('crosscorr axis');
ylabel('crosscorr magnitude');
title('crosscorr output');
OUTPUT:
RXY =
4.0000
nRXY =
-4 -3
-1
GRAPH:
22
PROGRAM 10:
initial condition
y(-1)=4, y(-2)=10.
SOLUTION:
x(n)=
n=0:5
n=0,x(0)=1
n=1,x(1)=0.25
n=2,x(2)=0.0625
n=3,x(3)=0.0156
n=4,x(4)=0.0039
n=5,x(5)=0.0010
n=0
y(0)=1+6-5
=2
n=1
y(1) =.25+3-2
=1.2500
n=2
y(2)=0.625+1.875-1
=0.7969
n=3
y(3)=0.0156+1.40625-0.625
=0.7969
n=4
y(4)=0.0039+1.19535-0.46625
=0.7365
23
n=5
y(5) =0.0010+1.09575-.3982 = 0.6982
MATLAB CODE:
a=[1 -3/2 1/2]
b=[1]
n=0:5;
xn=(1/4).^n;
disp('values of x(n)');
disp(xn);
y=[4,10];
xic=filtic(b,a,y);
y=filter(b,a,xn,xic);
disp('the solution for difference equation');
disp(y)
OUTPUT:
a = 1.0000 -1.5000
0.5000
b= 1
values of x(n)
1.0000 0.2500 0.0625
0.0156
0.0039
0.0010
0.6982
24
PROGRAM 11:
Order
10
10
2 log10
K1
10
K2
10
1
1
1
2
H j
N1
N2
N3
N2
N3
25
N=5 (s+1)(s^2+0.6180s+1)(s^2+1.6180s+1)
CHEBYSHEV FILTERS:
Chebyshev filters are equiripple in either the passband or stopband. Hence the magnitude
response oscillates between the permitted minimum and maximum values in the band a
number of times depending upon the order of filters. There are two types of chebyshev
filters. The chebyshev I filter is equiripple in passband and monotonic in the stopband,
where as chebyshev II is just the opposite.
The Chebyshev low-pass filter has a magnitude response given by
H j
where
C N2
0.5
c
for x
1, passband
CN x
cosh N cosh 1 x ,
for x
1, stopband
H j
N odd
K1
N even
N1 N 2
N 2 N3
K2
N3
The magnitude response has equiripple pass band and maximally flat stop band.
It can be seen that by increasing the filter order N, the Chebyshev response approximates the
ideal response.
The phase response of the Chebyshev filter is more non-linear than the Butter worth filter for a
given filter length N.
26
PROBLEM:
Using MATLAB design an IIR filter with passband edge frequency 1500Hz and stop band
edge at 2600Hz for a sampling frequency of 8000Hz, variation of gain within pass band
1db and stopband attenuation of 15 db. Use Butterworth prototype design and Bilinear
Transformation.
Design:
W1=(2*pi* F1 )/ Fs = 2*pi*250)/1000 =0.5 rad
W2=(2*pi* F2 )/ Fs = 2*pi*375)/1000 =0.75 rad
Prewarp:
1 = 2/T tan (w1/2)
= 2 rad/sec
T=1sec
1/[ s2 + 1.4142s + 1]
27
MATLAB CODE:
%Butterworth Prototype
Ap=input(enter passband attenuation =);
As=input(enter stopband attenuation =);
fp=input(enter passband frequency =);
fs= input(enter stopband frequency =);
Fs=input(enter sampling frequency=);
W1=2* fp / Fs ;
W2=2* fs / Fs ;
[N,Wn]=buttord(W1,W2,Ap,As)
[b,a]=butter(N,Wn)
freqz(b,a);
title(Butterworth frequency response)
INPUT:
enter passband attenuation =1
enter stopband attenuation =15
enter passband frequency =1500
enter stopband frequency =2000
enter sampling frequency=8000
OUTPUT:
N= 6
Wn = 0.4104
b = 0.0117 0.0699 0.1748 0.2331 0.1748 0.0699 0.0117
a = 1.0000 -1.0635 1.2005 -0.5836 0.2318 -0.0437 0.0043
28
Chebyshev Filter
PROBLEM:
Using MATLAB design an IIR filter with passband edge frequency 1500Hz and stop band
edge at 2600Hz for a sampling frequency of 8000Hz, variation of gain within pass band 1
db and stopband attenuation of 15 db. Use Chebyshev prototype design and Bilinear
Transformation.
DESIGN:
W1=(2*pi* F1 )/ Fs = 2*pi*100)/4000 =0.05 rad
W2=(2*pi* F2 )/ Fs = 2*pi*500)/4000 =0.25 rad
Prewarp:
1 = 2/T tan (w1/2)
T=1sec
= 0.157 rad/sec
2 = 2/T tan (w2/2)
= 0.828 rad/sec
Order:
=
10-Ap/10 - 1
= 0.765
A= 10-As/20
g=
, A = 1020/20
(A2 - 1) /
r= 2 / 1
A=10
, g = 13.01
29
n=log10
(g2-1)
g+
log10{r+
(r2 1) }
n= 1.388
Therefore n= 2.
Cut-off Frequency:
c = p = 1 = 0.157 rad\sec
Normalized Transfer Function:
H(s)=[bo /
1+ 2
] / [ s2+b1s+b0]
= 0.505/[ s2+0.8s+0.036]
Denormalized Transfer Function:
H(s)= Hn(s) |s-s/c
MATLAB CODE:
%Chebyshev Prototype
Ap=input(enter passband attenuation =);
As=input(enter stopband attenuation =);
fp=input(enter passband frequency =);
f s= input(enter stopband frequency =);
Fs=input(enter sampling frequency=);
W1=2* fp / Fs ;
W2=2* fs / Fs ;
[N,Wn]=cheb1ord(W1,W2,Ap,As)
[b,a]=cheby1(N,Ap,Wn)
freqz(b,a);
title(Chebyshev frequency response);
30
INPUT:
enter passband attenuation =1
enter stopband attenuation =15
enter passband frequency =1500
enter stopband frequency =2000
enter sampling frequency=8000
OUTPUT:
N= 4
Wn = 0.3750
b = 0.0191 0.0764 0.1147 0.0764 0.0191
a=
1.0000 -1.7994 1.9637 -1.1513 0.3301
31
PROGRAM 12:
0nN-1
otherwise
.(a)
The impulse response hd(n) is truncated at n = 0, since we are interested in causal FIR
Filter. It is possible to write above equation alternatively as
h(n) = hd(n)w(n)
.(b)
HAMMING WINDOW:
The impulse response of an N-term Hamming window is defined as follows:
wHam(n) = 0.54 0.46cos(2n / (N-1)) 0nN-1
=0
otherwise
PROBLEM:
Using MATLAB design an IIR filter to meet the following specifications choosing
Hamming window:
Window length, N = 27
Stop band attenuation = 50dB
Cut-off frequency = 100 Hz
32
MATLAB CODE:
N=input(Enter the window length=);
fc=input(Enter cut-off frequency=);
Fs=input(Enter sampling frequency=);
Wc=2*fc/ Fs;
Wh = (hamming(N))
b = fir1(N-1, Wc ,Wh)
[h,omega] = freqz(b,1,256);
mag = 20*log10(abs(h));
plot(omega/pi,mag);
grid;
xlabel(Frequncy in radians in terms of pi);
ylabel(gain in dB);
title(Response of FIR filter using Hamming window);
INPUT:
Enter the window length=27
Enter cut-off frequency=100
Enter sampling frequency=1000
OUTPUT:
Wh =
0.0800
0.0934
0.1327
0.1957
0.2787
0.3769
0.4846
0.5954
0.7031
0.8013
0.8843
0.9473
0.9866
1.0000
0.9866
0.9473
0.8843
0.8013
0.7031
0.5954
0.4846
0.3769
Department of Telecommunication CMRIT
33
0.2787
0.1957
0.1327
0.0934
0.0800
b=
Columns 1 through 6
0.0019 0.0023 0.0022 -0.0000 -0.0058 -0.0142
Columns 7 through 12
-0.0209 -0.0185 0.0000
0.0374
0.0890
0.1429
Columns 13 through 18
0.1840 0.1994 0.1840
0.1429
0.0890
0.0374
Columns 19 through 24
0.0000 -0.0185 -0.0209 -0.0142 -0.0058 -0.0000
Columns 25 through 27
0.0022 0.0023 0.0019
34
GENERAL LAYOUT OF
CODE COMPOSER STUDIO
STEPS TO EXECUTE A PROGRAM USING CCS
1. In the main screen go to project - - > new.. the following screen will appear .
Give a appropriate project name, project type as executable (.out) file.
Select target as TMS320C67xx (depends on the target processor we are using, in our
case its 67xx), and click finish in dialog box finally.
2. Now a new project will be created(e.g. linear.pjt) and a tree will be displayed on
left hand side.
3. Now we need to write C source code . Go to File - - > New - - > Source file.
4. Now a blank screen will appear in which we have to write our C source
code. Type the source code and click save.
5. We have to save the source code file as .c file .When we press save icon in main
screen, following dialog box will open. Save the file as C\C++ source file (e.g. lin.c).
6. Now we have to add 3 files to our project.
C source code (e.g. lin.c).
A library file (e.g. rts6700.lib).
A linker command file (e.g. hello.cmd).
Firstly add the source code file.
Go to Project - - > Add files to project...
Now dialog box will open ,here browse for the source code file in projects directory
and click open .(usually the common paths are ..\ti\MyProjects\projectname\...)
Similarly Add two more files following same procedure .
First, add a library file from path...\ti\c6000\cgtools\lib\rts6700.lib (here file
type is object and library file).
Secondly, add a linker command file from path
\ti\tutorial\dsk6713\hello1\hello.cmd (here the file type is linker
command file *.lcf,*.cmd).
Department of Telecommunication CMRIT
35
7. After the addition of all three files ,the expanded project tree on left hand side will
resemble this format.(observe the LHS project tree which contains a library file, a
source code and linker command file.)
8. Now we need to compile and build our program.
To compile go to project -- > compile file. Now the project will be compiled and any
errors will be displayed below if there.
To build go to project - - >build. Now project will be built and any errors or warnings
will be displayed below.
9. Now we need to load program in CPU or simulator .
Go to file - - > load program.
A dialog box will open in which we have select executable .out file.
The usual path is \ti\MyProjects\linear\debug\linear.out
10. Now we can assembly equivalent of C source code which the simulator has
generated.
11. To see the output of the program we have to run the program.
Go to Debug - - > Run .
12. Now we can see output of the program below.
If the program needs any user input, a pop-up window will open.
13. Now we need to see the plot of output .
Go to View - - > Graph - - > Time\frequency..
Now a graph property dialog box will open up.
Select Display type = single time.
Graph title = Any name.
Start address = the variable which we want to display.
Index increment= 1(usually).
DSP data type = 32-bit signed integer.
DATA plot style = bar(for displaying discrete values).
Grid style = Full grid.
Now the graph will be displayed.
*We can select different elements by using left and right keys of keyboard.
36
PROGRAM 1:
37
38
PROGRAM 2:
Circular Convolution
PROBLEM:
Perform the Circular Convolution of the given sequence using Code Composer
Studio.
#include<stdio.h>
int m,n,x[30],h[30],y[30],i,j,temp[30],k,x2[30],a[30];
void main()
{
printf(" enter the length of the first sequence\n");
scanf("%d",&m);
printf(" enter the length of the second sequence\n");
scanf("%d",&n);
printf(" enter the first sequence\n");
for(i=0;i<m;i++)
scanf("%d",&x[i]);
printf(" enter the second sequence\n");
for(j=0;j<n;j++)
scanf("%d",&h[j]);
if(m-n!=0)
{
if(m>n)
{
for(i=n;i<m;i++)
h[i]=0;
n=m;
}
for(i=m;i<n;i++)
x[i]=0;
m=n;
}
y[0]=0;
a[0]=h[0];
for(j=1;j<n;j++)
a[j]=h[n-j];
for(i=0;i<n;i++)
y[0]+=x[i]*a[i];
for(k=1;k<n;k++)
{
y[k]=0;
for(j=1;j<n;j++)
x2[j]=a[j-1];
x2[0]=a[n-1];
39
for(i=0;i<n;i++)
{
a[i]=x2[i];
y[k]+=x[i]*x2[i];
}
}
printf(" the circular convolution is\n");
for(i=0;i<n;i++)
printf("%d \t",y[i]);
}
INPUT:
Length of first sequence = 4
Length of second sequence = 4
First sequence =[1 2 2 1 ]
Second sequence =[1 2 2 1]
OUTPUT:
The circular convolution is [9 8 9 10]
40
PROGRAM 3:
for(j=0;j<10;j++)
{
x[0]=impulse[j];
y[0] = (a[0] *x[0]) +(a[1]* x[1] ) +(x[2]*a[2]) - (y[1]*b[1])-(y[2]*b[2]);
printf("%f\n",y[0]);
z[j]=y[0];
y[2]=y[1];
y[1]=y[0];
x[2]=x[1];
x[1] = x[0];
}
}
INPUT:
Coefficient of x(n)={0.1311,0.2622,0.1311}
Coefficient of y(n)={1,-0.7478,0.2722}
OUTPUT:
0.131100
0.360237
0.364799
0.174741
0.031373
-0.024104
-0.026565
-0.013304
41
-0.002718
0.001589
GRAPH:
42
PROGRAM:4
Input:
Output:
43
44