You are on page 1of 50

DEPARTMENT OF

ELECTRONICS & COMMUNICATION ENGINEERING

Digital SIGNAL PROCESSING


LAB MANUAL
PVP19 REGULATIONS

III B.TECH I SEM

PRASAD V POTLURI SIDDHARTHA INSTITUTE OF TECHNOLOGY


(Autonomous, Accredited by NBA & NAAC, an ISO 9001:2015 certified institution)
(Sponsored by Siddhartha Academy of General & Technical Education)
VIJAYAWADA – 520 007
1
PRASAD V POTLURI SIDDHARTHA INSTITUTE OF TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING

DIGITAL SIGNAL PROCESSING LAB

LIST OF EXPERIMENTS

Part – A: (Using MATLAB)


1. Frequency response of a system described by a difference equation.
2. Implementation of Discrete time systems in time domain
3. DFT and IDFT of the given sequences.
4. Properties of DFT
5. Fast Fourier Transform.
6. Design of IIR Low Pass Filter using Butterworth and Chebyshev approximations.
7. Design of IIR High Pass Filter using Butterworth and Chebyshev approximations.
8. Design of FIR Low Pass Filter using Window technique.
9. Design of FIR High Pass Filter using Window technique.

Part – B: (Using Code Composer Studio)


10. Linear Convolution.
11. Circular Convolution.
12. Generation of Sine wave & Square wave.

2
INDEX

Sign of
Page
S.No. Date Name of the Experiment the
No.
faculty

1.

2.

3.

4.

5.

6.

7.

8.

9.

10

11.

12.

3
Expt. No: 1
Dt: FREQUENCY RESPONSE OF A SYSTEM

Aim: To plot & observe the frequency response of first order and second order discrete-time
systems described by the difference equations
a) y(n) - 0.5 y(n-1) = x(n)
b) y(n) + 0.8 y(n-1) + 0.125 y(n-2) = x(n) + 2x(n-1)

Equipment Required:
PC loaded with MATLAB software

Algorithm:

Step : 1 Get/Read the coefficients of x(n) to a.


Step : 2 Get/Read the coefficients of y(n) to b.
Step : 3 Define the frequency range vector w.
Step : 4 Find the frequency response of the filter by using the coefficients b and a.
Step : 5 Calculate the magnitude of the frequency response
Step : 6 Plot the magnitude response of the filter
Step : 7 Calculate the phase response of the filter
Step : 8 Plot the phase response of the filter

Program:
clc;
clear all;
close all;
b=input('enter the coefficients of x(n): ');
a=input('enter the coefficients of y(n): ');
w= -2*pi: pi/256:2*pi;
g=freqz (b,a,w);
m=abs(g);
ph=angle(g);
subplot (2,1,1);
plot(w/pi, m);
xlabel('normalized frequency');
ylabel('magnitude');
grid on;
title('Magnitude response');
subplot(2,1,2);
plot(w/pi,ph);
4
xlabel(' normalized frequency');
ylabel('Phase');
grid on;
title ('phase response');

Procedure:
1. Click on the MATLAB icon on the desktop (or go to Start – All programs and click
on MATLAB) to get into the Command Window.
2. Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command window.
3. Write the program in the ‘Edit’ window and save it in ‘M-file’.
4. Run the program.
5. Enter the input in the command window.
6. The result is displayed in the Command window and the graphical output is displayed
in the Figure Window.

Input 1:
enter the coefficients of x(n): [1 ]
Enter the coefficients of y(n): [1, -0.5]

Output 1:
Magnitude response
2
---> magnitude

1.5

0.5
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2
---> normalized frequency
Phase response
1

0.5
---> phase

-0.5

-1
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2
---> normalized frequency

Input 2:
Enter the coefficients of x(n): [1 2]
Enter the coefficients of y(n): [1, 0.8, 0.125]

5
Output 2:
Magnitude response
3.5
---> magnitude

2.5

1.5
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2
---> normalized frequency
Phase response
4

2
---> phase

-2

-4
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2
---> normalized frequency

Result: Hence the frequency response of a first order and second order discrete-time systems
are observed and plotted using MATLAB.

6
Expt. No: 2
Dt: IMPLEMENTAION OF DISCRETE TIME SYSTEMS IN
TIME DOMAIN

Aim: To implement the following discrete time systems described by difference equation in
time domain using MATLAB.
a) y(n) - 0.8 y(n-1) = x(n)
b) y(n) + 0.8 y(n-1) + 0.125 y(n-2) = x(n)

Equipment Required:
PC loaded with MATLAB software

Algorithm:

Step : 1 Get/Read the coefficients of x(n) to a.


Step : 2 Get/Read the coefficients of y(n) to b.
Step : 3 Find the impulse response of the system by using the coefficients b and a.
Step : 4 Plot the impulse response of the system

Program:
clc;
clear all;
close all;
b=input('enter the coefficients of x(n): ');
a=input('enter the coefficients of y(n): ');
[h,N]=impz(b,a);
stem(N,h);
xlabel('Time n');
ylabel('Amplitude');
grid on;
title('Impulse response of the system');

Procedure:
1. Click on the MATLAB icon on the desktop (or go to Start – All programs and click
on MATLAB) to get into the Command Window.
2. Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command window.
3. Write the program in the ‘Edit’ window and save it in ‘M-file’.
4. Run the program.
5. Enter the input in the command window.
6. The result is displayed in the Command window and the graphical output is displayed
in the Figure Window.

7
Input 1:
Enter the coefficients of x(n): [1]
Enter the coefficients of y(n): [1, -0.8]
Output 1:

Input 2:
Enter the coefficients of x(n): [1 ]
Enter the coefficients of y(n): [1, 0.8, 0.125]
Output 2:

Result: Hence given discrete time system is implemented and its impulse response is
observed using MATLAB.

8
Expt. No: 3
Dt: DFT and IDFT OF GIVEN SEQUENCE

Aim: To determine and plot the DFT and IDFT of a given sequence using MATLAB.

Equipment Required:
PC loaded with MATLAB software

Algorithm:

Step : 1 Get/Read the samples of x[n] to x.


Step : 2 Find the length of x and store it in N.
Step : 3 Initialize the arrays xk & ixk with same size as that of x.
Step : 4 Find the DFT of the sequence x using

X(K) =

Use two for loops for the above expression


Step : 5 Find the IDFT of the sequence xk using
x(n) =

Use two for loops for the above expression


Step : 6 Plot the Graphs of x , xk and ixk.

Program:
clc
close all;
clear all;
xn=input('Enter the sequence x(n)'); %Get the sequence from user
ln=length(xn); %find the length of the sequence
xk=zeros(1,ln); % initilise an array of same size as that of input sequence
ixk=zeros(1,ln);
for k=0:ln-1
for n=0:ln-1
xk(k+1)=xk(k+1)+(xn(n+1)*exp((-i)*2*pi*k*n/ln));
end
end
t=0:ln-1;
subplot(221);
stem(t,xn);
grid
ylabel ('Amplitude');
xlabel ('Time Index');
9
title('Input Sequence x[n]');
magnitude=abs(xk);
t=0:ln-1;
subplot(222);
stem(t,magnitude);
grid
ylabel ('Amplitude');
xlabel ('index K');
title ('Magnitude Response of x[n]');
phase=angle(xk);
t=0:ln-1;
subplot(223);
stem(t,phase);
grid
ylabel ('Phase');
xlabel ('index K');
title('Phase Response of x[n]');
disp('DFT of the given sequence x[n] is');
disp(xk)
for n=0:ln-1
for k=0:ln-1
ixk(n+1)=ixk(n+1)+(xk(k+1)*exp(i*2*pi*k*n/ln));
end
end
ixk=ixk./ln;
t=0:ln-1;
subplot(224);
stem(t,ixk);
grid;
ylabel ('Amplitude');
xlabel ('Time Index');
title ('IDFT sequence');

Procedure:
1. Click on the MATLAB icon on the desktop (or go to Start – All programs and click
on MATLAB) to get into the Command Window.
2. Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command window.
3. Write the program in the ‘Edit’ window and save it in ‘M-file’.
4. Run the program.
5. Enter the input in the command window.
6. The result is displayed in the Command window and the graphical output is displayed
in the Figure Window.

Input:
Enter the sequence x(n): [1 2 3 4]

10
Output:
DFT of the given sequence x[n] is
10.0000 + 0.0000i -2.0000 + 2.0000i -2.0000 - 0.0000i -2.0000 - 2.0000i

X(K) = (10, -2+j2, -2, -2-j2)

Result: Hence DFT and IDFT of given sequence is performed and outputs are observed using
MATLAB.

11
Expt. No: 4
Dt: PROPERTIES OF DFT

Aim: To verify the following properties of DFT using MATLAB.

a) Linearity Property b) Circular Convolution Property

Equipment Required:
PC loaded with MATLAB software

Algorithm:
Linearity Property:

Step : 1 Get/Read the samples of sequence x1[n] to x1.


Step : 2 Get/Read the length of sequence x1 to N1.
Step : 3 Get/Read the samples of sequence x1[n] to x1.
Step : 4 Get/Read the length of sequence x1 to N1.
Step : 5 Get/Read the value of ‘a’ to a.
Step : 6 Get/Read the value of ‘b’ to b.
Step : 7 Find the maximum value of (N1, N2) and store it in N.
Step : 8 If N1 > N2, append N1-N2 zeros to x2.
Step : 9 If N2 > N1, append N2-N1 zeros to x1.
Step : 10 Determine DFT of x1 and store it in X1.
Step : 11 Determine DFT of x2 and store it in X2.
Step : 12 Determine DFT of [a*x1 + b*x2] and store it in X.
Step : 13 Determine a*X1 + b* X2 and store it in X3.
Step : 14 Display X and X3.
Step : 15 Verify and compare X and X3

Circular Convolution Property:

Step : 1 Get/Read the samples of sequence x1[n] to x1.


Step : 2 Get/Read the length of sequence x1 to N1.
Step : 3 Get/Read the samples of sequence x1[n] to x1.
Step : 4 Get/Read the length of sequence x1 to N1.
Step : 5 Find the maximum value of (N1, N2) and store it in N.
Step : 6 If N1 > N2, append N1-N2 zeros to x2.
12
Step : 7 If N2 > N1, append N2-N1 zeros to x1.
Step : 8 Determine N-point circular convolution of x1 and x2 and store it in x.
Step : 9 Determine DFT of x and store it in X.
Step : 10 Determine DFT of x1 and store it in X1.
Step : 11 Determine DFT of x2 and store it in X2.
Step : 12 Multiply X1 and X2 and store it in X3.
Step : 13 Display X and X3.
Step : 14 Verify and compare X and X3

Program:
clc;
close all;
clear all;
disp(' DFT properties ');
disp('1. Linearity Property');
disp('2. Circular Convolution Property');
ch=input('Enter your choice: ');
switch(ch)
case 1
disp('DFT[ax1(n)+bx2(n)] = aX1(k)+bX2(k)');
x1=input('enter the input sequence x1: ');
x2=input('enter the input sequence x2: ');
a=input('enter the value of constant a: ');
b=input('enter the value of constant b: ');
N1=length(x1);
N2=length(x2);
N=max(N1,N2);
X1=zeros(1,N);X2=zeros(1,N);X=zeros(1,N);X3=zeros(1,N);
if N1>N2
n=N2+1:N1;
x2(n)=0;
else
n=N1+1:N2;
x1(n)=0;
end
for k=1:N
for n=1:N
x(n)=a*x1(n)+b*x2(n);
X1(k)=X1(k)+x1(n)*exp(-j*2*pi*(k-1)*(n-1)/N);
X2(k)=X2(k)+x2(n)*exp(-j*2*pi*(k-1)*(n-1)/N);
X(k)=X(k)+x(n)*exp(-j*2*pi*(k-1)*(n-1)/N);
X3(k)=a*X1(k)+b*X2(k);
end

13
end
disp('DFT[ax1(n)+bx2(n)] = ');
disp(X);
disp('aX1(k)+bX2(k) = ');
disp(X3);

case 2
disp('DFT(x1(n)*x2(n_)) = X1(k).X2(k)');
x1=input('enter the sequence x1: ');
x2=input('enter the sequence x2: ');
N1=length(x1);
N2=length(x2);
N=max(N1,N2);
if N1>N2
n=N2+1:N1;
x2(n)=0;
else
n=N1+1:N2;
x1(n)=0;
end
X1=zeros(1,N);X2=zeros(1,N);X=zeros(1,N);X3=zeros(1,N);
x=cconv(x1,x2,N);
X=fft(x);
X1=fft(x1);
X2=fft(x2);
X3=X1.*X2;
disp('DFT(x1(n)*x2(n)) = ');
disp(X);
disp('X1(k).X2(k) = ');
disp(X3);
end

Procedure:
1. Click on the MATLAB icon on the desktop (or go to Start – All programs and click
on MATLAB) to get into the Command Window.
2. Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command window.
3. Write the program in the ‘Edit’ window and save it in ‘M-file’.
4. Run the program.
5. Enter the input in the command window.
6. The result is displayed in the Command window and the graphical output is displayed
in the Figure Window.

Input:
Case1:
Enter your choice: 1
Enter the input sequence x1: [1 2 3 4]
Enter the input sequence x2: [1 2 1 1]
14
Enter the value of constant a: 2
Enter the value of constant b: 3

Output1:
DFT[ax1(n)+bx2(n)] =
35.0000 + 0.0000i -4.0000 + 1.0000i -7.0000 - 0.0000i -4.0000 - 1.0000i

aX1(k)+bX2(k) =
35.0000 + 0.0000i -4.0000 + 1.0000i -7.0000 - 0.0000i -4.0000 - 1.0000i

Input:
Case2:

Enter your choice: 2


Enter the sequence x1: [1 2 3 4]
Enter the sequence x2: [1 2 1 1]

Output2:
DFT(x1(n)*x2(n)) =
50.0000 + 0.0000i 2.0000 + 2.0000i 2.0000 + 0.0000i 2.0000 - 2.0000i

X1(k).X2(k) =
50.0000 + 0.0000i 2.0000 + 2.0000i 2.0000 + 0.0000i 2.0000 - 2.0000i

Result: Hence the Linearity and Circular Convolution properties of DFT are verified using
MATLAB.

15
Expt. No: 5
Dt: FAST FOURIER TRANSFORM

Aim: To compute the Fast Fourier transform of a given signal using MATLAB.

Equipment Required:
PC loaded with MATLAB software

Algorithm:

Step : 1 Get/Read the length of sequence x[n] to N.


Step : 2 Get/Read the samples of sequence x[n] to x.
Step : 3 Find the length of x and store it in N1.
Step : 4 If N1< N then pad N-N1 number of zeros to x.
Step : 5 Initialize the time vector n from 0:N-1.
Step : 6 Find the FFT of the given sequence and store it in y.
Step : 7 Determine the magnitude of y and store it my.
Step : 8 Determine the phase of y and store it py.
Step : 9 Plot the Graphs of x, my and py.

Program:
clc;
clear all;
close all;
N=input('enter the length of sequence: ');
y=input('enter the samples of sequence: ');
for m= 1:N/2
w(m)=exp(-j*2*pi*(m-1)/N);
end
nos=log2(N);
legd=N/2;
for i=1:nos
for j=1:legd
for k=j:2*legd:N
ul=k;
ll=ul+legd;
temp1=y(ul) + y(ll);
temp2=y(ul)-y(ll);
y(ul)=temp1;
y(ll)=temp2*w(j);
end
end
16
legd=legd/2;
len=length(w);
w=w(1:2:len);
end
Y=bitrevorder(y);
disp(Y);
n=0:N-1;
subplot(2,1,1);
stem(n,abs(Y));
title('magnitude spectrum');
xlabel('Frequency index K');
ylabel('amplitude');
subplot(2,1,2);
stem(n,angle(Y));
title('Phase spectrum');
xlabel('Frequency index K');
ylabel('phase');

Procedure:
1. Click on the MATLAB icon on the desktop (or go to Start – All programs and click
on MATLAB) to get into the Command Window.
2. Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command window.
3. Write the program in the ‘Edit’ window and save it in ‘M-file’.
4. Run the program.
5. Enter the input in the command window.
6. The result is displayed in the Command window and the graphical output is displayed
in the Figure Window.

Input:
enter the length of sequence: 8
enter the samples of sequence: [1 2 3 4 5 6 7 8]

Output:

FFT of the given sequence x[n] is


Columns 1 through 4
36.0000 + 0.0000i -4.0000 + 9.6569i -4.0000 + 4.0000i -4.0000 + 1.6569i
Columns 5 through 8
-4.0000 + 0.0000i -4.0000 - 1.6569i -4.0000 - 4.0000i -4.0000 - 9.6569i

17
Magnitude spectrum
40

30
amplitude

20

10

0
0 1 2 3 4 5 6 7
frequency index K
Phase spectrum
4

2
Phase

-2

-4
0 1 2 3 4 5 6 7
frequency index K

Result: Hence Fast Fourier transform of a given signal is computed and its spectrum is
plotted using MATLAB

18
Expt. No: 6
Dt: DESIGN OF IIR LOW PASS DIGITAL FILTER

Aim: To design and plot the frequency response of IIR low pass digital filter using
Butterworth & Chebyshev approximations.

Equipment Required:
PC loaded with MATLAB software

Algorithm:

Step : 1 Get/Read the pass band frequency of LPF to fp.


Step : 2 Get/Read the stop band frequency of LPF to fs.
Step : 3 Get/Read the pass band ripple of LPF to rp.
Step : 4 Get/Read the stop band ripple of LPF to rs.
Step : 5 Get/Read the sampling frequency to f.
Step : 6 Normalize the pass band and stop band frequencies using
wp=2*fp/f; ws=2*fs/f;
Step : 7 Define the frequency vector w from 0:π.
Step : 8 Determine the order ‘n’ and cut off frequency ‘wn’ of the filter using
Butterworth approximation.
Step : 9 Determine the coefficients of digital filter [b, a] using ‘n’.
Step : 10 Determine the frequency response of low pass filter ‘H’ using the
coefficients [b, a].
Step : 11 Determine the magnitude of H in dB and store it in mag.
Step : 12 Determine the phase of H in and store it in phase.
Step : 13 Plot the Graphs of mag and phase.
Step : 14 Repeat the steps 8 to 13 for Chebyshev type I & type II approximations.

Program:
clc;
clear all;
close all;
rp=input('enter the passband ripple: ');
rs=input('enter the stopband ripple: ');
wp=input('enter the passband frequency: ');
ws=input('enter the stopband frequency: ');
fs=input('enter the sampling frequency: ');
w1=2*wp/fs;
19
w2=2*ws/fs;

% BUTTERWORTH FILTER
% Find the order n and cutoff frequency
[n,wn]=buttord(w1,w2,rp,rs);
[b,a]=butter(n,wn);
w=0:.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
subplot(3,2,1);
plot(om/pi,m);
title('magnitude response using Butterworth');
xlabel('(a) Normalized freq. -->');
ylabel('Gain in dB-->');
grid on;
an=angle(h);
subplot(3,2,2);
plot(om/pi,an);
title('phase response using Butterworth');
xlabel('(b) Normalized freq. -->');
ylabel('Phase in radians-->');
grid on;

%CHEBYSHEV TYPE I FILTER


% Find the order n and cutoff frequency
[n,wn]=cheb1ord(w1,w2,rp,rs);
[b,a]=cheby1(n,rp,wn);
w=0:.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
subplot(3,2,3);
plot(om/pi,m);
title('magnitude response using Chebyshev I');
xlabel('(a) Normalized freq. -->');
ylabel('Gain in dB-->');
grid on;
an=angle(h);
subplot(3,2,4);
plot(om/pi,an);
title('phase response using Chebyshev I');
xlabel('(b) Normalized freq. -->');
ylabel('Phase in radians-->');
grid on;

%CHEBYSHEV TYPE II FILTER


% Find the order n and cutoff frequency
[n,wn]=cheb2ord(w1,w2,rp,rs);
[b,a]=cheby2(n,rs,wn);
w=0:.01:pi;
20
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
subplot(3,2,5);
plot(om/pi,m);
title('magnitude response using Chebyshev II');
xlabel('(a) Normalized freq. -->');
ylabel('Gain in dB-->');
grid on;
an=angle(h);
subplot(3,2,6);
plot(om/pi,an);
title('phase response using Chebyshev II');
xlabel('(b) Normalized freq. -->');
ylabel('Phase in radians-->');
grid on;

Procedure:
1. Click on the MATLAB icon on the desktop (or go to Start – All programs and click
on MATLAB) to get into the Command Window.
2. Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command window.
3. Write the program in the ‘Edit’ window and save it in ‘M-file’.
4. Run the program.
5. Enter the input in the command window.
6. The result is displayed in the Command window and the graphical output is displayed
in the Figure Window.

Input:
enter the passband ripple: 3
enter the stopband ripple: 50
enter the passband frequency: 1000
enter the stopband frequency: 2000
enter the sampling frequency: 10000

21
Output:

Result: Hence an IIR low pass digital filter is designed and its frequency response is
observed using MATLAB.

22
Expt. No: 7
Dt: DESIGN OF IIR HIGH PASS DIGITAL FILTER

Aim: To design and plot the frequency response of IIR high pass digital filter using
Butterworth & Chebyshev approximations.

Equipment Required:
PC loaded with MATLAB software
Algorithm:

Step : 1 Get/Read the pass band frequency of HPF to fp.


Step : 2 Get/Read the stop band frequency of HPF to fs.
Step : 3 Get/Read the pass band ripple of HPF to rp.
Step : 4 Get/Read the stop band ripple of HPF to rs.
Step : 5 Get/Read the sampling frequency to f.
Step : 6 Normalize the pass band and stop band frequencies using
wp=2*fp/f; ws=2*fs/f;
Step : 7 Define the frequency vector w from 0:π.
Step : 8 Determine the order ‘n’ and cut off frequency ‘wn’ of the filter using
Butterworth approximation.
Step : 9 Determine the coefficients of digital filter [b, a] using ‘n’.
Step : 10 Determine the frequency response of the high pass filter ‘H’ using
the coefficients [b, a].
Step : 11 Determine the magnitude of H in dB and store it in mag.
Step : 12 Determine the phase of H in and store it in phase.
Step : 13 Plot the Graphs of mag and phase.
Step : 14 Repeat the steps 8 to 13 for Chebyshev type I & type II approximations.

Program:
clc;
clear all;
close all;
rp=input('enter the passband ripple: ');
rs=input('enter the stopband ripple: ');
wp=input('enter the passband frequency: ');
ws=input('enter the stopband frequency: ');
fs=input('enter the sampling frequency: ');
w1=2*wp/fs;
23
w2=2*ws/fs;

% BUTTERWORTH FILTER
% Find the order n and cutoff frequency
[n,wn]=buttord(w1,w2,rp,rs);
[b,a]=butter(n,wn,'high');
w=0:.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
subplot(3,2,1);
plot(om/pi,m);
title('magnitude response using Butterworth');
xlabel('(a) Normalized freq. -->');
ylabel('Gain in dB-->');
grid on;
an=angle(h);
subplot(3,2,2);
plot(om/pi,an);
title('phase response using Butterworth');
xlabel('(b) Normalized freq. -->');
ylabel('Phase in radians-->');
grid on;

%CHEBYSHEV TYPE I FILTER


% Find the order n and cutoff frequency
[n,wn]=cheb1ord(w1,w2,rp,rs);
[b,a]=cheby1(n,rp,wn,'high');
w=0:.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
subplot(3,2,3);
plot(om/pi,m);
title('magnitude response using Chebyshev I');
xlabel('(a) Normalized freq. -->');
ylabel('Gain in dB-->');
grid on;
an=angle(h);
subplot(3,2,4);
plot(om/pi,an);
title('phase response using Chebyshev I');
xlabel('(b) Normalized freq. -->');
ylabel('Phase in radians-->');
grid on;

%CHEBYSHEV TYPE II FILTER


[n,wn]=cheb2ord(w1,w2,rp,rs);
% Find the order n and cutoff frequency
[b,a]=cheby2(n,rp,wn,'high');
w=0:.01:pi;
24
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
subplot(3,2,5);
plot(om/pi,m);
title('magnitude response using Chebyshev II');
xlabel('(a) Normalized freq. -->');
ylabel('Gain in dB-->');
grid on;
an=angle(h);
subplot(3,2,6);
plot(om/pi,an);
title('phase response using Chebyshev II');
xlabel('(b) Normalized freq. -->');
ylabel('Phase in radians-->');
grid on;

Procedure:
1. Click on the MATLAB icon on the desktop (or go to Start – All programs and click
on MATLAB) to get into the Command Window.
2. Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command window.
3. Write the program in the ‘Edit’ window and save it in ‘M-file’.
4. Run the program.
5. Enter the input in the command window.
6. The result is displayed in the Command window and the graphical output is displayed
in the Figure Window.

Input:
enter the passband ripple: 2
enter the stopband ripple: 50
enter the passband frequency: 2000
enter the stopband frequency: 1000
enter the sampling frequency: 5000

25
Output:

Result: Hence an IIR high pass digital filter is designed and its frequency response is
observed using MATLAB.

26
Expt. No: 8
Dt: DESIGN OF FIR LOW PASS DIGITAL FILTER

Aim: To design and plot the frequency response of FIR low pass digital filter using
windowing technique.

Equipment Required:
PC loaded with MATLAB software

Algorithm:

Step : 1 Get/Read the pass band frequency of LPF to fp.


Step : 2 Get/Read the stop band frequency of LPF to fs.
Step : 3 Get/Read the pass band ripple of LPF to rp.
Step : 4 Get/Read the stop band ripple of LPF to rs.
Step : 5 Get/Read the sampling frequency to f.
Step : 6 Normalize the pass band and stop band frequencies using
wp=2*fp/f; ws=2*fs/f;
Step : 7 Define the frequency vector w from 0:π.
Step : 8 Determine the order ‘n’ of the filter using
num=-20*log10(sqrt(rp*rs))-13; dem=14.6*(fs-fp)/f
n=ceil(num/dem)
Step : 9 Make sure that the order of the filter is always odd.
if(rem(n,2)~=0)
n1=n; n=n-1;
else
n1=n+1;
end
Step : 10 Determine the coefficients ‘b’ of digital LPF using Rectangular window and
fir1 functions.
Step : 11 Determine the frequency response of low pass filter ‘H’ using the
coefficients ‘b’.
Step : 12 Determine the magnitude of H in dB and store it in mag.
Step : 13 Determine the phase of H in and store it in phase.
Step : 14 Plot the Graphs of mag and phase.
Step : 15 Repeat the steps 10 to 14 for triangular, Hanning, Hamming, Blackman and
Kaiser window functions.

27
Program:
clc;
clear all;
close all;
rp=input('enter passband ripple: ');
rs=input('enter the stopband ripple: ');
fp=input('enter passband frequency: ');
fs=input('enter stopband frequency: ');
f=input('enter sampling frequency: ');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n=ceil(num/dem);
if(rem(n,2)~=0)
n1=n;
n=n-1;
else
n1=n+1;
end

% LPF Rectangular window


y=rectwin(n1);
b=fir1(n,wp,y);
w=0:0.01:pi;
[h,o]=freqz(b,1,w);
m=20*log10(abs(h));
an=angle(h);
subplot(6,2,1)
plot(o/pi,m);
title('rectangular window magnitude');
ylabel('Gain in dB-->');
xlabel('Normalized frequency-->');
grid on;
subplot(6,2,2)
plot(o/pi,an);
title('rectangular window phase');
ylabel('phase in dB-->');
xlabel('Normalized frequency-->');
grid on;

% LPF Triangular window


y=bartlett(n1);
b=fir1(n,wp,y);
w=0:0.01:pi;
[h,o]=freqz(b,1,w);
m=20*log10(abs(h));
an=angle(h);
subplot(6,2,3)
28
plot(o/pi,m);
title('Trinngular window magnitude');
ylabel('Gain in dB-->');
xlabel('Normalized frequency-->');
grid on;
subplot(6,2,4)
plot(o/pi,an);
title('Trinngular window phase');
ylabel('phase in dB-->');
xlabel('Normalized frequency-->');
grid on;

% LPF Hanning window


y=hanning(n1);
b=fir1(n,wp,y);
w=0:0.01:pi;
[h,o]=freqz(b,1,w);
m=20*log10(abs(h));
an=angle(h);
subplot(6,2,5)
plot(o/pi,m);
title('Hanning window magnitude');
ylabel('Gain in dB-->');
xlabel('Normalized frequency-->');
grid on;
subplot(6,2,6)
plot(o/pi,an);
title('Hanning window phase');
ylabel('phase in dB-->');
xlabel('Normalized frequency-->');
grid on;

% LPF Hamming window


y=hamming(n1);
b=fir1(n,wp,y);
w=0:0.01:pi;
[h,o]=freqz(b,1,w);
m=20*log10(abs(h));
an=angle(h);
subplot(6,2,7)
plot(o/pi,m);
title('Hamming window magnitude');
ylabel('Gain in dB-->');
xlabel('Normalized frequency-->');
grid on;
subplot(6,2,8)
plot(o/pi,an);
title('Hamming window phase');
ylabel('phase in dB-->');
29
xlabel('Normalized frequency-->');
grid on;

% LPF Blackman window


y=blackman(n1);
b=fir1(n,wp,y);
w=0:0.01:pi;
[h,o]=freqz(b,1,w);
m=20*log10(abs(h));
an=angle(h);
subplot(6,2,9)
plot(o/pi,m);
title('Blackman window magnitude');
ylabel('Gain in dB-->');
xlabel('Normalized frequency-->');
grid on;
subplot(6,2,10)
plot(o/pi,an);
title('Blackman window phase');
ylabel('phase in dB-->');
xlabel('Normalized frequency-->');
grid on;

% LPF Kaiser window


y=kaiser(n1);
b=fir1(n,wp,y);
w=0:0.01:pi;
[h,o]=freqz(b,1,w);
m=20*log10(abs(h));
an=angle(h);
subplot(6,2,11)
plot(o/pi,m);
title('Kaiser window magnitude');
ylabel('Gain in dB-->');
xlabel('Normalized frequency-->');
grid on;
subplot(6,2,12)
plot(o/pi,an);
title('Kaiser window phase');
ylabel('phase in dB-->');
xlabel('Normalized frequency-->');
grid on;

Procedure:
1. Click on the MATLAB icon on the desktop (or go to Start – All programs and click
on MATLAB) to get into the Command Window.
2. Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command window.
3. Write the program in the ‘Edit’ window and save it in ‘M-file’.
4. Run the program.
30
5. Enter the input in the command window.
6. The result is displayed in the Command window and the graphical output is displayed
in the Figure Window.

Input:
enter passband ripple: 0.02
enter the stopband ripple: 0.01
enter passband frequency: 500
enter stopband frequency: 2000
enter sampling frequency: 8000

Output:

phase in dB-->
Gain in dB-->

rectangular window magnitude rectangular window phase


0 5
-50 0
-100 -5
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized frequency--> Normalized frequency-->
phase in dB-->
Gain in dB-->

Trinngular window magnitude Trinngular window phase


0 5
-20 0
-40 -5
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized frequency--> Normalized frequency-->
phase in dB-->
Gain in dB-->

Hanning window magnitude Hanning window phase


0 5
-100 0
-200 -5
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized frequency--> Normalized frequency-->
phase in dB-->
Gain in dB-->

Hamming window magnitude Hamming window phase


0 5
-50 0
-100 -5
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized frequency--> Normalized frequency-->
phase in dB-->
Gain in dB-->

Blackman window magnitude Blackman window phase


0 5
-50 0
-100 -5
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized frequency--> Normalized frequency-->
phase in dB-->
Gain in dB-->

Kaiser window magnitude Kaiser window phase


0 5
-50 0
-100 -5
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized frequency--> Normalized frequency-->

Result: Hence an FIR low pass digital filter is designed and its response is observed using
MATLAB.

31
Expt. No: 9
Dt: DESIGN OF FIR HIGH PASS DIGITAL FILTER

Aim: To design and plot the frequency response of FIR high pass filter using windowing
technique.

Equipment Required:
PC loaded with MATLAB software
Algorithm:

Step : 1 Get/Read the pass band frequency of HPF to fp.


Step : 2 Get/Read the stop band frequency of HPF to fs.
Step : 3 Get/Read the pass band ripple of HPF to rp.
Step : 4 Get/Read the stop band ripple of HPF to rs.
Step : 5 Get/Read the sampling frequency to f.
Step : 6 Normalize the pass band and stop band frequencies using
wp=2*fp/f; ws=2*fs/f;
Step : 7 Define the frequency vector w from 0:π.
Step : 8 Determine the order ‘n’ of the filter using
num=-20*log10(sqrt(rp*rs))-13; dem=14.6*(fs-fp)/f
n=ceil(num/dem)
Step : 9 Make sure that the order of the filter is always odd.
if(rem(n,2)~=0)
n1=n; n=n-1;
else
n1=n+1;
end
Step : 10 Determine the coefficients ‘b’ of digital HPF using Rectangular window and
fir1 functions.
Step : 11 Determine the frequency response of high pass filter ‘H’ using the
coefficients ‘b’.
Step : 12 Determine the magnitude of H in dB and store it in mag.
Step : 13 Determine the phase of H in and store it in phase.
Step : 14 Plot the Graphs of mag and phase.
Step : 15 Repeat the steps 10 to 14 for triangular, Hanning, Hamming, Blackman and
Kaiser Window functions.

32
Program:
clc;
clear all;
close all;
rp=input('enter passband ripple: ');
rs=input('enter the stopband ripple: ');
fp=input('enter passband frequency: ');
fs=input('enter stopband frequency: ');
f=input('enter sampling frequency: ');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fp-fs)/f;
n=ceil(num/dem);
if(rem(n,2)~=0)
n1=n;
n=n-1;
else
n1=n+1;
end
% HPF Rectangular window
y=rectwin(n1);
b=fir1(n,wp,'high',y);
w=0:0.01:pi;
[h,o]=freqz(b,1,w);
m=20*log10(abs(h));
an=angle(h);
subplot(6,2,1)
plot(o/pi,m);
title('rectangular window magnitude');
ylabel('Gain in dB-->');
xlabel('Normalized frequency-->');
grid on;
subplot(6,2,2)
plot(o/pi,an);
title('rectangular window phase');
ylabel('phase in dB-->');
xlabel('Normalized frequency-->');
grid on;
% HPF Triangular window

y=bartlett(n1);
b=fir1(n,wp,'high',y);
w=0:0.01:pi;
[h,o]=freqz(b,1,w);
m=20*log10(abs(h));
an=angle(h);
subplot(6,2,3)
plot(o/pi,m);
33
title('Trinngular window magnitude');
ylabel('Gain in dB-->');
xlabel('Normalized frequency-->');
grid on;
subplot(6,2,4)
plot(o/pi,an);
title('Trinngular window phase');
ylabel('phase in dB-->');
xlabel('Normalized frequency-->');
grid on;
% HPF Hanning window

y=hanning(n1);
b=fir1(n,wp,'high',y);
w=0:0.01:pi;
[h,o]=freqz(b,1,w);
m=20*log10(abs(h));
an=angle(h);
subplot(6,2,5)
plot(o/pi,m);
title('Hanning window magnitude');
ylabel('Gain in dB-->');
xlabel('Normalized frequency-->');
grid on;
subplot(6,2,6)
plot(o/pi,an);
title('Hanning window phase');
ylabel('phase in dB-->');
xlabel('Normalized frequency-->');
grid on;
% HPF Hamming window

y=hamming(n1);
b=fir1(n,wp,'high',y);
w=0:0.01:pi;
[h,o]=freqz(b,1,w);
m=20*log10(abs(h));
an=angle(h);
subplot(6,2,7)
plot(o/pi,m);
title('Hamming window magnitude');
ylabel('Gain in dB-->');
xlabel('Normalized frequency-->');
grid on;
subplot(6,2,8)
plot(o/pi,an);
title('Hamming window phase');
ylabel('phase in dB-->');
xlabel('Normalized frequency-->');
34
grid on;
% HPF Blackman window

y=blackman(n1);
b=fir1(n,wp,'high',y);
w=0:0.01:pi;
[h,o]=freqz(b,1,w);
m=20*log10(abs(h));
an=angle(h);
subplot(6,2,9)
plot(o/pi,m);
title('Blackman window magnitude');
ylabel('Gain in dB-->');
xlabel('Normalized frequency-->');
grid on;
subplot(6,2,10)
plot(o/pi,an);
title('Blackman window phase');
ylabel('phase in dB-->');
xlabel('Normalized frequency-->');
grid on;
% HPF Kaiser window

y=kaiser(n1);
b=fir1(n,wp,'high',y);
w=0:0.01:pi;
[h,o]=freqz(b,1,w);
m=20*log10(abs(h));
an=angle(h);
subplot(6,2,11)
plot(o/pi,m);
title('Kaiser window magnitude');
ylabel('Gain in dB-->');
xlabel('Normalized frequency-->');
grid on;
subplot(6,2,12)
plot(o/pi,an);
title('Kaiser window phase');
ylabel('phase in dB-->');
xlabel('Normalized frequency-->');
grid on;

Procedure:
1. Click on the MATLAB icon on the desktop (or go to Start – All programs and click
on MATLAB) to get into the Command Window.
2. Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command window.
3. Write the program in the ‘Edit’ window and save it in ‘M-file’.
4. Run the program.

35
5. Enter the input in the command window.
6. The result is displayed in the Command window and the graphical output is displayed
in the Figure Window.

Input:
enter passband ripple: 0.02
enter the stopband ripple: 0.01
enter passband frequency: 5000
enter stopband frequency: 1000
enter sampling frequency: 20000

Output:

phase in dB-->
Gain in dB-->

rectangular window magnitude rectangular window phase


100 5
0 0
-100 -5
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized frequency--> Normalized frequency-->
phase in dB-->
Gain in dB-->

Trinngular window magnitude Trinngular window phase


0 5
-20 0
-40 -5
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized frequency--> Normalized frequency-->
phase in dB-->
Gain in dB-->

Hanning window magnitude Hanning window phase


100 5
0 0
-100 -5
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized frequency--> Normalized frequency-->
phase in dB-->
Gain in dB-->

Hamming window magnitude Hamming window phase


0 5
-50 0
-100 -5
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized frequency--> Normalized frequency-->
phase in dB-->
Gain in dB-->

Blackman window magnitude Blackman window phase


0 5
-20 0
-40 -5
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized frequency--> Normalized frequency-->
phase in dB-->
Gain in dB-->

Kaiser window magnitude Kaiser window phase


100 5
0 0
-100 -5
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized frequency--> Normalized frequency-->

Result: Hence an FIR high pass digital filter is designed and its Frequency Response is
observed using MATLAB.
36
Expt. No: 10
Dt: LINEAR CONVOLUTION

Aim: To perform linear convolution of given sequences using TMS320C6713 DSP


Processor.

Equipment Required:
PC loaded with Code Composer Studio software, TMS320C6713 DSP Starter kit

Algorithm:

Step : 1 Get/Read the length of input sequence to N1.


Step : 2 Get/Read the length of impulse response to N2.
Step : 3 Get/Read Input Signal Samples to x[n].
Step : 4 Get/Read Impulse Response samples to h[n]
Step : 5 Calculate the length of output sequence N using
N=N1+N2-1
Step : 6 Perform Linear convolution using the formula
y[n] =
Step : 7 Display the values of y[n].
Step : 8 Plot the graphs for x[n], h[n] and y[n].

Program:
#include<stdio.h>
int x[10],y[10],h[20];
void main()
{
int i,j,N1,N2;
printf("enter the length of first sequence: ");
scanf("%d",&N1);
printf("enter the length of second sequence: ");
scanf("%d",&N2);
printf("enter the samples of first sequence x(n): ");
for(i=0;i<N1;i++)
{
scanf("%d",&x[i]);
}
printf("enter the samples of second sequence h(n): ");
for(i=0;i<N2;i++)
{
scanf("%d",&h[i]);

37
}
for(i=N1;i<N1+N2-1;i++)
x[i]=0;
for(i=N2;i<N1+N2-1;i++)
h[i]=0;
for(i=0;i<N1+N2-1;i++)
{
y[i]=0;
for(j=0;j<=i;j++)
y[i]=y[i]+x[j]*h[i-j];
}
printf("Linear convolution of x(n) and h(n) is y(n) = :\n");
for(i=0;i<N1+N2-1;i++)
printf("%d\t",y[i]);
}

Procedure:
1. Open CCS Version 6.1.1.
2. Go to File menu and select new CCS project.
3. Create new project with following specifications
Project → New CCS Project
Target: C671X Floating-point DSP TMS320C671X
Connection: Spectrum Digital DSK-EVM-eZdsp onboard USB Emulator

38
4. Select empty project with main.c and finish.
5. Create a new Source file
File → New →Browse the Source folder→ give file name & Save ( Eg: sum.c)

6. Write C program and save it.


7. Create New Target configuration file with extension .ccxml
File → New → Target configuration file

Connection: Spectrum Digital DSK - EVM-eZdsp onboard USB Emulator

39
8. Build the project.

9. Launch the target configuration.


Select Target configuration →Right click→ Launch target configuration
10. Click on Connect Target on menu bar.
11. Load the program
Run→ Load Programme →Browse .out file
12. Run the program.
13. Observe the output in the console window (to observe the graph, go to expressions,
right click on the expression and select the graph).

40
Input:
enter the length of first sequence: 6
enter the length of second sequence: 4
enter the samples of first sequence x(n): {1,2,3,4,5,6}
enter the samples of second sequence h(n): {1,2,3,4}

Output:

To view output graphically,


Select Tools  graph  Single Time.
Graph settings & graph as follows.

41
Result: Hence linear convolution of given sequences is performed and output is observed
using TMS320C6713 DSP starter kit.

42
Expt. No: 11
Dt: CIRCULAR CONVOLUTION

Aim: To perform circular convolution of given sequences using TMS320C6713 DSP


Processor.
.
Equipment Required:
PC loaded with Code Composer Studio software, TMS320C6713 DSP Starter kit

Algorithm:

Step : 1 Get/Read the length of input sequence to N1.


Step : 2 Get/Read the length of impulse response to N2.
Step : 3 Get/Read the Input Signal Samples to x[n].
Step : 4 Get/Read the Impulse Response samples to h[n]
Step : 5 Calculate the length of output sequence N using
N=N1+N2-1
Step : 6 If N1 > N2, pad N1-N2 zeros to h[n]
else pad N2-N1 zeros to x[n].
Step : 7 Perform Circular convolution using the formula
y[n] =
Step : 8 Display the values of y[n].
Step : 9 Plot the graphs for x[n], h[n] and y[n].

Program:
#include<stdio.h>
#include<math.h>
int x[10],y[10],h[10],a[10],t[10];
void main()
{
int i,j,k,n,m;
printf("enter the length of first sequence:\n ");
scanf("%d",&m);
printf("enter the length of second sequence:\n ");
scanf("%d",&n);
printf("enter the samples of first sequence:\n ");
for(i=0;i<m;i++)
{
scanf("%d",&x[i]);
}
43
printf("enter the samples of second sequence:\n ");
for(i=0;i<n;i++)
{
scanf("%d",&h[i]);
}
if (m-n!=0)
{
if(m>n)
{
for(i=n;i<m;i++)
h[i]=0;
n=m;
}
if(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]= y[0]+ x[i]*a[i];
for(k=1;k<n;k++)
{
y[k]=0;
for(j=1;j<n;j++)
t[j]=a[j-1];
t[0]=a[n-1];
for(i=0;i<n;i++)
{
a[i]=t[i];
y[k] = y[k] + x[i]*a[i];
}
}
printf("circular convolution of x(n) and h(n) is:\n");
for(i=0;i<n;i++)
printf("%d\t",y[i]);
}

Procedure:
1. Open Code Composer Studio 6.1.1
2. Create new project with following specifications

44
Project → New CCS Project
Target: C671X Floating -point DSP TMS320C671X
Connection: Spectrum Digital DSK - EVM-eZdsp onboard USB Emulator
3. Select empty project with main.c and finish.
4. Create a Source file
File → New →Browse the Source folder→ give file name & Save ( Eg: sum.c)
5. Write C program and save it.
6. Create New Target configuration file with extension .ccxml
File → New → Target configuration file
Connection: Spectrum Digital DSK - EVM-eZdsp onboard USB Emulator
Device type: DSK6713
Save
7. Build the project.
8. Launch the target configuration.
Select Target configuration →Right click→ Launch target configuration
9. Click on Connect Target on menu bar.
10. Load the program
Run→ Load Programme →Browse .out file
11. Run the program.
12. Observe the output in the console window
(to observe the graph, go to expressions, right click on the expression and
select the graph).

Input:
Enter the length of first sequence: 3
Enter the length of second sequence: 3
Enter the samples of first sequence:{1 2 3}
Enter the samples of second sequence:{1 2 3}

Output:
Circular convolution of x(n) and h(n) is:
13 13 10

45
Result: Hence circular convolution of given sequences is performed and output is observed
using TMS320C6713 DSP starter kit.

46
Expt. No: 12
Dt: GENERATION OF SINE WAVE AND SQUARE WAVE

Aim: To generate sine and square waves using TMS320C6713 DSP Processor.

Equipment Required:
PC loaded with Code Composer Studio software, TMS320C6713 DSP Starter kit

Algorithm for Sine wave generation

Step : 1 Get/Read the frequency of the sinusoidal signal to F.


Step : 2 Get/Read the number of samples to N.
Step : 3 Define time scale for a sine signal (Ex: 0<t<100)
Step : 4 Generate sinusoidal signal using
y[t]=sin(2*pi*f*t/N);
Step : 5 Plot the graph of y.

Algorithm for Square wave generation

Step : 1 Get/Read the time period of square signal to t.


Step : 2 Define time scale i for a square signal. (Ex: 0<i<100)
Step : 3 Generate square wave using
if((i*2)/t)%2==0
y[i]= 1 ;
else
y[i]= -1;
Step : 4 Plot the graph of y.

Program:
/*Sine wave generation*/
#include<stdio.h>
#include<math.h>
#define pi 3.14
float y[500];
voidmain()
{

47
int t,f,n;
printf("enter the frequency");
scanf("%d",&f);
printf("enter the no.of samples");
scanf("%d",&N);

for(t=0;t<=500;t++)
y[t]=sin(2*pi*f*t/N);
}

/* Square wave generation*/


#include<stdio.h>
#include<math.h>
float y[100];
voidmain()
{
int i,t;
printf("enter the time period: ");
scanf("%d",&t);
for(i=0;i<100;i++)
if(((i*2)/t)%2==0)
y[i]=1;
else
y[i]=-1;
}

Procedure:
1. Open Code Composer Studio 6.1.1
2. Create new project with following specifications
Project → New CCS Project
Target: C671X Floating -point DSP TMS320C671X
Connection: Spectrum Digital DSK - EVM-eZdsp onboard USB Emulator
3. Select empty project with main.c and finish.
4. Create a Source file
File → New →Browse the Source folder→ give file name & Save ( Eg: sum.c)
5. Write C program and save it.
6. Create New Target configuration file with extension .ccxml
File → New → Target configuration file
Connection: Spectrum Digital DSK - EVM-eZdsp onboard USB Emulator
48
Device type: DSK6713
Save
7. Build the project.
8. Launch the target configuration.
Select Target configuration →Right click→ Launch target configuration
9. Click on Connect Target on menu bar.
10. Load the program
Run→ Load Programme →Browse .out file
11. Run the program.
12. Observe the output in the console window
(to observe the graph, go to expressions, right click on the expression and select
the graph).

Input:
enter the frequency: 10
enter the no. of samples: 512

Output:

49
Input:
enter the time period: 10

Output:

Result: Hence sine wave and square waves are generated and observed using TMS320C6713
DSP starter kit.

50

You might also like