Digital Signal Processing Lab Manual
Digital Signal Processing Lab Manual
LAB MANUAL
Regulation – 2019
Prepared by
Ms.K.Arthi, AP
Mr. R. Dhananjeyan, AP
Ms.K.Durgadevi, AP
1
SRM VALLIAMMAI ENGINEERING COLLEGE
(An Autonomous Institution)
SRM Nagar, Kattankulathur – 603 203
• To contribute to the development of human resources in the form of professional engineers and
managers of international excellence and competence with high motivation and dynamism, who
besides serving as ideal citizen of our country will contribute substantially to the economic
development and advancement in their chosen areas of specialization.
• To build the institution with international repute in education in several areas at several levels with
specific emphasis to promote higher education and research through strong institute-industry
interaction and consultancy.
To excel in the field of electronics and communication engineering and to develop highly competent
technocrats with global intellectual qualities.
2
SRM VALLIAMMAI ENGINEERING COLLEGE
(An Autonomous Institution)
SRM Nagar, Kattankulathur – 603 203
PROGRAM OUTCOMES
PSO1: Ability to apply the acquired knowledge of basic skills, mathematical foundations, principles of
electronics, modeling and design of electronics based systems in solving engineering Problems.
PSO2: Ability to understand and analyze the interdisciplinary problems for developing innovative
sustained solutions with environmental concerns.
PSO3: Ability to update knowledge continuously in the tools like MATLAB, NS2, XILINIX and
technologies like VLSI, Embedded, Wireless Communications to meet the industry requirements.
PSO4: Ability to manage effectively as part of a team with professional behavior and ethics.
3
SYLLABUS
OBJECTIVES:
The student should be made:
• To perform basic signal processing operations such as Linear Convolution, Circular Convolution,
Auto Correlation, Cross Correlation and Frequency analysis in MATLAB
• To implement FIR and IIR filters in MATLAB and DSP Processor
• To study the architecture of DSP processor
• To design a DSP system to demonstrate the Multi-rate and Adaptive signal processing concepts.
LIST OF EXPERIMENTS:
TOTAL: 60 PERIODS
OUTCOMES:
At the end of the course, the student should be able to:
• Carryout basic signal processing operations
• Demonstrate their abilities towards MATLAB based implementation of various DSP systems
• Analyze the architecture of a DSP Processor
• Design and Implement the FIR and IIR Filters in DSP Processor for performing filtering operation
over real-time signals
• Design a DSP system for various applications of DSP
LIST OF EXPERIMENTS
4
CYCLE I
5
Ex No: Date:
Aim:
To write a MATLAB program to generate unit step, unit impulse, unit ramp, exponential, sine
waveform, cosine waveform, random signal and correlation.
Description:
Input : Enter the sequence length for the generation of signals.
Algorithm:
6
Program:
7
%Program for Cosine waveform
t=-pi:0.01:pi;
y=cos(t);
subplot(2,2,2);
plot(t,y);
ylabel('amplitude --->');
xlabel('t --->');
title('Cosine waveform');
8
Model Graph:
amplitude --->
amplitude --->
0.5 0.5
0 0
-4 -2 0 2 4 0 2 4 6
t ---> t --->
Ramp Signal Exponential Signal
6 150
amplitude --->
amplitude --->
4 100
2 50
0 0
0 2 4 6 0 2 4 6
t ---> t --->
0.5 0.5
amplitude --->
amplitude --->
0 0
-0.5 -0.5
-1 -1
-4 -2 0 2 4 -4 -2 0 2 4
t ---> t --->
Discrete Sine waveform Discrete Cosine waveform
1 1
0.5 0.5
amplitude --->
amplitude --->
0 0
-0.5 -0.5
-1 -1
-4 -2 0 2 4 -4 -2 0 2 4
t ---> t --->
9
%Program for Random Signal
t = rand(1,10);
subplot(2,1,1);
plot(t);
ylabel('amplitude --->');
xlabel('t --->');
title('Random Signal');
disp('t=');
disp(t);
a=2;
b=3;
t1 = a + (b-a).*rand(100,1);
subplot(2,1,2);
plot(t1)
ylabel('amplitude --->');
xlabel('t --->');
title('Random Signal');
disp('t1=');
disp(t1);
Random Signal
1
amplitude --->
0.5
0
1 2 3 4 5 6 7 8 9 10
t --->
Random Signal
3
amplitude --->
2.5
2
0 10 20 30 40 50 60 70 80 90 100
t --->
10
% Program for computing cross-correlation of the sequences x[1 2 3 4] and h[4 3 2 1]
clc;
clear all;
close all;
x=input('enter the 1st sequence');
h=input('enter the 2nd sequence');
y= xcorr(x,h);
subplot(3,1,1);
stem(x);
ylabel('Amplitude --.');
xlabel('(a) n --.');
title('input sequence');
subplot(3,1,2);
stem(h);
ylabel('Amplitude --.');
xlabel('(b) n --.');
title('impulse sequence');
subplot(3,1,3);
stem(y);
ylabel('Amplitude --.');
xlabel('(c) n --.');
title('Cross correlated sequence');
disp('The resultant signal is y=');
disp(y)
Output:
enter the 1st sequence[1 2 3 4]
enter the 2nd sequence[4 3 2 1]
The resultant signal is y=
1.0000 4.0000 10.0000 20.0000 25.0000 24.0000 16.0000
11
Model Graph:
input sequence
4
Amplitude --.
2
0
1 1.5 2 2.5 3 3.5 4
(a) n --.
impulse sequence
4
Amplitude --.
0
1 1.5 2 2.5 3 3.5 4
(b) n --.
Cross correlated sequence
40
Amplitude --.
20
0
1 2 3 4 5 6 7
(c) n --.
Output:
enter the sequence[1 2 3 4]
The resultant signal is y=
4.0000 11.0000 20.0000 30.0000 20.0000 11.0000 4.0000
12
Model Graph
original signal
4
Amplitude --. 3
0
1 1.5 2 2.5 3 3.5 4
(a) n --.
Auto correlated sequence
30
Amplitude --.
20
10
0
1 2 3 4 5 6 7
(a) n --.
Postlab Questions:
1. Modify Program (b) to generate a delayed unit step sequence u[n] with an advance of “n”
samples. Run the modified program and display the sequence generated.
2. What is the subplot command used to plot 4 figures in 2 rows and 2 columns?
3. How can you compute the average power of the generated sinusoidal sequence?
4. Write the syntax to determine auto correlation of the given signal x[n].
5. Give the examples for 1-D, 2-D & 3-D signals.
Result:
Thus a program to generate sequence for unit step, unit impulse, unit ramp, exponential,
sine, cosine and correlation signal using MATLAB was written and executed and the
corresponding simulation output is plotted.
13
Ex No: Date:
Aim:
To write a program to find out the linear convolution of two sequence using Matlab.
Program:
% Program for Linear Convolution
clc;
clear all;
close all;
%x=[1 1 1 1];
%h=[4 5 6 7];
x=input('enter the value x=');
h=input('enter the value h=');
subplot(3,1,1);
stem(x);
title('Input x(n)');
ylabel('x(n) --->');
xlabel('t --->');
subplot(3,1,2);
stem(h);
14
title('Input h(n)');
ylabel('h(n) --->');
xlabel('t --->');
h1=fliplr(h);
n1=length(x);
n2=length(h);
n=n1+n2-1;
x=[zeros(1,n2-1),x];
h1=[h1,zeros(1,n1-1)];
for i=1:n
new=[zeros(1,i-1),h1(1:n-i+1)];
out(i)=x*new';
end
disp('output=');
disp(out);
subplot(3,1,3);
t=0:1:n-1;
stem(t,out);
title('Output y(n)');
ylabel('y(n) --->');
xlabel('t --->');
MODEL GRAPH
Input x(n)
1
x(n) --->
0.5
0
1 1.5 2 2.5 3 3.5 4
t --->
Input h(n)
10
h(n) --->
0
1 1.5 2 2.5 3 3.5 4
t --->
Output y(n)
20
y(n) --->
10
0
0 1 2 3 4 5 6 7
t --->
THEORETICAL CALCULATION
Aim:
To write a program to find out the circular convolution of two sequences using MATLAB.
Description:
Input : Give the input x(n) and h(n) in matrix form.
N 1
y ( n) x ( k ) h( n k )
k 0
Algorithm:
1. Start the program.
2. Get the two input sequence x(n) and h(n) and compute the length of the sequence.
3. Append zeros to x(n) or h(n) to make both sequence of same length.
4. Rotate the sequence h(-k), ‘n’ times. If ‘n’ is positive shift the sequence in anticlockwise
direction else in the clockwise direction.
5. Determine the product of sequence x(n) and shifted h(n) sequence and sum it.
6. Execute the program, display the result and verify it theoretically.
7. Plot the output graph for each sequence.
8. Stop the process.
Program:
% Program for Circular Convolution
clc;
clear all;
close all;
%g=[1,2,3,4];
%h=[2,4,6];
x=input('enter the sequence');
h=input('enter the sequence');
N1=length(x);
N2=length(h);
subplot(3,1,1);
n=0:1:N1-1;
stem(n,x);
title('x(n)');
ylabel('amplitude --->');
xlabel('time --->');
subplot(3,1,2);
n=0:1:N2-1;
stem(n,h);
title('h(n)');
ylabel('amplitude --->');
xlabel('time --->');
16
N=max(N1,N2);
if(N1<=N);
x1=[x,zeros(1,N-N1)];
end
if(N2<=N);
h1=[h,zeros(1,N-N2)];
end
for n=1:N
y(n)=0;
for i=1:N
j=n-i+1;
if(j<=0)
j=N+j;
end
y(n)=y(n)+x1(i)*h1(j);
end
end
disp('y=');
disp(y);
subplot(3,1,3);
n=0:1:N-1;
stem(n,y);
title('output y(n)');
ylabel('amplitude --->');
xlabel('time --->');
MODEL GRAPH
g(n)
4
amplitude --->
0
0 0.5 1 1.5 2 2.5 3
time --->
h(n)
amplitude --->
10
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
time --->
output y(n)
40
amplitude --->
20
0
0 0.5 1 1.5 2 2.5 3
time --->
17
THEORITICAL CALCULATION
y ( n) x ( n) h( n)
N 1
y ( n) x ( k ) h( n k )
k 0
Output Sequence is = 36 32 20 32
Matrix Method:
Postlab Questions :
Result:
Thus a program to find out the linear and circular convolution of two sequences using Matlab was
written and executed.
18
Ex No: Date :
Aim:
To analyze the amplitude and phase response of the DFT and IDFT signalusing MATLAB.
Algorithm:
Program:
% Program for Discrete Fourier Transform
clc;
clear all;
close all;
%x=[1 2 3 4 5 6 7 8];
%N=[8];
x=input('enter the input x=');
N=input('enter the order of dft N=');
k=0:1:N-1;
disp('Input Sequence x=');
disp(x);
XK=fft(x,N);
disp('XK=');
disp(XK);
R=real(XK);
disp('Real part=');
disp(R);
I=imag(XK);
disp('Imaginary part=');
disp(I);
19
mag=abs(XK);
disp('Magnitude=');
disp(mag);
ang=angle(XK);
disp('Angle=');
disp(ang);
xn=ifft(XK,N);
disp('IDFT xn=');
disp(xn);
figure(1);
subplot(2,1,1);
stem(x);
xlabel('time -->');
ylabel('Amplitude -->');
title('Given sequence');
subplot(2,1,2);
stem(R,'r*');
hold on;
stem(I);
legend('Real Part','Imaginary Part');
xlabel('time -->');
ylabel('Amplitude -->');
title('Discrete Fourier Transform')
figure(3);
subplot(2,2,1);
stem(k,mag);
xlabel('time -->');
ylabel('x(k) --->');
title('Magnitude response');
subplot(2,2,2);
stem(k,ang);
xlabel('time -->');
ylabel('ang x(k) --->');
title('Phase response');
subplot(2,2,3);
stem(k,xn);
xlabel('time -->');
ylabel('x(n)');
title('Inverse Discrete Fourier transform');
%Spectrum analysis
Fs=[10];
xdft = XK(1:N/2+1);
psdx = (1/(Fs*N)) * abs(xdft).^2;
psdx(2:end-1) = 2*psdx(2:end-1);
20
freq = 0:Fs/N:Fs/2;
subplot(2,2,4);
plot(freq,psdx);
grid on;
xlabel('hz -->');
ylabel('db');
title('Spectrum analysis DFT');
disp('Spectrum analysis DFT=');
disp(psdx);
Output:
enter the input x=[1 2 3 4 5 6 7 8]
enter the order of dft N=[8]
Input Sequence x=1 2 3 4 5 6 7 8
XK=
36.0000 + 0.0000i
-4.0000 - 9.6569i
-4.0000 - 4.0000i
-4.0000 - 1.6569i
-4.0000 + 0.0000i
-4.0000 + 1.6569i
-4.0000 + 4.0000i
-4.0000 + 9.6569i
Real part= 36 -4 -4 -4 -4 -4 -4 -4
IDFT xn= [1 2 3 4 5 6 7 8]
Spectrum analysis DFT= 16.2000 2.7314 0.8000 0.4686 0.2000
21
Model Graph
Given sequence
8
Amplitude -->
4
0
1 2 3 4 5 6 7 8
time -->
Discrete Fourier Transform
40
Real Part
Amplitude -->
Imaginary Part
20
-20
1 2 3 4 5 6 7 8
time -->
30 2
ang x(k) --->
x(k) --->
20 0
10 -2
0 -4
0 4 6 82 0 2 4 6 8
time --> time -->
Inverse Discrete Fourier transform Spectrum analysis DFT
8 20
6 15
x(n)
db
4 10
2 5
0 0
0 2 4 6 8 0 2 4 6
time --> hz -->
Postlab Questions :
Result:
Thus a MATLAB program for Spectrum analysis of the DFT and IDFT signal was written,
executed and the graphs were plotted.
22
Ex : No: Date:
3(b).FAST FOURIER TRANSFORM AND INVERSE FAST FOURIER
TRANSFORM (FFT & IFFT)
Aim:
To write a program to find out the Fast Fourier transform and Inverse Fast Fourier transform of the
sequence using MATLAB and display the magnitude and phase response.
Description
FFT
N 1
X (k ) x(n) kn
N
n0
IFFT
1 N 1
x ( n) X (k ) kn
N
N
k 0
j 2kn
N
N e
kn
Algorithm:
23
Program:
% Program for FFT & IFFT
clc;
clear all;
close all;
%x=[2 2 2 2 1 1 1 1];
%N=[8];
x=input('enter the input x=');
N=input('enter the order of fft N=');
k=0:1:N-1;
XK=fft(x,N);
disp('XK=');
disp(XK);
R=real(XK);
disp('Real part=');
disp(R);
I=imag(XK);
disp('Imaginary part=');
disp(I);
mag=abs(XK);
disp('Mag=');
disp(mag);
ang=angle(XK);
disp('angle=');
disp(ang);
xn=ifft(XK,N);
disp('IFFT xn=');
disp(xn);
figure(1);
stem(R,'r*');
hold on;
stem(I);
legend('Real Part','Imaginary Part');
xlabel('time -->');
ylabel('Amplitude -->');
title('Fast Fourier Transform')
24
figure(2);
subplot(2,2,1);
stem(x);
xlabel('time -->');
ylabel('Amplitude -->');
title('Given sequence');
subplot(2,2,2);
stem(k,mag);
xlabel('time -->');
ylabel('x(k) --->');
title('Magnitude response');
subplot(2,2,3);
stem(k,ang);
xlabel('time -->');
ylabel('ang x(k) --->');
title('Phase response');
subplot(2,2,4);
stem(k,xn);
xlabel('time -->');
ylabel('x(n)');
title('Inverse Fast Fourier transform');
Output:
enter the input x=[2 2 2 2 1 1 1 1]
enter the order of fft N=[8]
Input Sequence x= 2 2 2 2 1 1 1 1
XK=
12.0000 + 0.0000i
1.0000 + 2.4142i
0.0000 + 0.0000i
1.0000 + 0.4142i
0.0000 + 0.0000i
1.0000 - 0.4142i
0.0000 + 0.0000i
1.0000 - 2.4142i
Real part= 12 1 0 1 0 1 0 1
IFFT xn= 2 2 2 2 1 1 1 1
25
Model Graph:
Fast Fourier Transform
12
Real Part
10 Imaginary Part
6
Amplitude -->
-2
-4
1 2 3 4 5 6 7 8
time -->
1.5
Amplitude -->
10
x(k) --->
1
5
0.5
0 0
0 2 4 6 8 0 2 4 6 8
time --> time -->
Phase response Inverse Fast Fourier transform
2 2
1 1.5
ang x(k) --->
x(n)
0 1
-1 0.5
-2 0
0 2 4 6 8 0 2 4 6 8
time --> time -->
26
27
PostLab Questions:
1. How many multiplications and additions are involved in radix-2 FFT for N=1024 when compared
to DFT?
2. Draw the 2-point DIF-FFT butterfly structure.
3. Compare DIF and DIT FFT algorithm.
4. Why FFT is needed?
5. Mention the applications of FFT algorithm?
Result:
Thus a program to find out the fast Fourier (FFT) and inverse fast Fourier transform (IFFT) of the
sequence using Matlab was written and executed.
28
Ex:No: Date:
4.FIR FILTER DESIGN
Aim:
To write a program to design the FIR low pass, high pass, band pass and band stop filters and
obtain thefrequency response of the filter using MATLAB.
Description:
Output: 1) Find the impulse response hd (n) for the given cut-off frequency and
Order of the filter.
2) Decide the window function w (n) and compute the window
Coefficients.
3) Find the filter coefficients h (n) =hd (n)*w (n).
4) Plot the frequency response for Low pass, High pass, Band pass and
Band stop filters
Algorithm:
29
Program:
% Function:
function [hd]=ideal_lp(wc,M)
alpha=(M-1)/2;
n=0:1:M-1;
N=n-alpha+eps; % add smallest number to avoid divide by zero
hd=sin(wc*N)./(pi*N);
Program:
%PROGRAM FOR LOW PASS FILTER
clc;
clear all;
close all;
M=7;
wc=1.2;
n=0:1:M-1;
hd=ideal_lp(wc,M);
w=hamming(M);
h=hd.*w';
disp('Filter coefficients for LPF=');
[M1,P]=freqz(h,1,2000);
mag=20*log10(abs(M1));
subplot(2,2,1);
stem(n,hd);
xlabel('n--->');
ylabel('hd(n)--->');
title('Ideal Impulse Response');
disp('hd=');
disp(hd);
subplot(2,2,2);
stem(n,w);
xlabel('n--->');
ylabel('w(n)--->');
title('Hamming Window');
disp('w=');
disp(w);
subplot(2,2,3);
stem(n,h);
xlabel('n--->');
30
ylabel('h(n)--->');
title('Actual Impulse Response');
disp('h=');
disp(h);
subplot(2,2,4);
plot(P/pi, mag);
grid on;
xlabel('Normalized frequency--->');
ylabel('Magnitude in db--->');
title('Frequency Response ');
Output:
Filter coefficients for LPF=
Model Graph:
0.4
hd(n)--->
w(n)--->
0.2 0.5
-0.2 0
0 2 4 6 0 2 4 6
n---> n--->
Actual Impulse Response Frequency Response
0.6 0
Magnitude in db--->
0.4
-50
h(n)--->
0.2
-100
0
-0.2 -150
0 2 4 6 0 0.5 1
n---> Normalized frequency--->
31
%PROGRAM FOR HIGH PASS FILTER
clc;
clear all;
close all;
M=11;
wc=1.2;
n=0:1:M-1;
hd=ideal_lp(pi,M)-ideal_lp(wc,M);
w=hann(M);
h=hd.*w';
disp('Filter coefficients for HPF=');
[M1,P]=freqz(h,1,2000);
mag=20*log10(abs(M1));
subplot(2,2,1);
stem(n,hd);
xlabel('n--->');
ylabel('hd(n)--->');
title('Ideal Impulse Response');
disp('hd=');
disp(hd);
subplot(2,2,2);
stem(n,w);
xlabel('n--->');
ylabel('w(n)--->');
title('Hanning Window');
disp('w=');
disp(w);
subplot(2,2,3);
stem(n,h);
xlabel('n--->');
ylabel('h(n)--->');
title('Actual Impulse Response');
disp('h=');
disp(h);
subplot(2,2,4);
plot(P/pi, mag);
grid on;
xlabel('Normalized frequency--->');
ylabel('Magnitude in db--->');
title('Frequency Response ');
32
Output:
w=0 0.0955 0.3455 0.6545 0.9045 1.0000 0.9045 0.6545 0.3455 0.0955
0
h=0 0.0076 0.0162 -0.0704 -0.2683 0.6180 -0.2683 -0.0704 0.0162 0.0076
0
Model Graph:
0.5
hd(n)--->
w(n)--->
0.5
0
-0.5 0
0 5 10 0 5 10
n---> n--->
Actual Impulse Response Frequency Response
1 50
Magnitude in db--->
0.5 0
h(n)--->
0 -50
-0.5 -100
0 5 10 0 0.5 1
n---> Normalized frequency--->
33
%PROGRAM FOR BAND PASS FILTER
clc;
clear all;
close all;
M=11;
wc1=1.2;
wc2=2;
n=0:1:M-1;
hd=ideal_lp(wc2,M)-ideal_lp(wc1,M);
w=hann(M);
h=hd.*w';
disp('Filter coefficients for BPF=');
[M1,P]=freqz(h,1,2000);
mag=20*log10(abs(M1));
subplot(2,2,1);
stem(n,hd);
xlabel('n--->');
ylabel('hd(n)--->');
title('Ideal Impulse Response');
disp('hd=');
disp(hd);
subplot(2,2,2);
stem(n,w);
xlabel('n--->');
ylabel('w(n)--->');
title('Hanning Window');
disp('w=');
disp(w);
subplot(2,2,3);
stem(n,h);
xlabel('n--->');
ylabel('h(n)--->');
title('Actual Impulse Response');
disp('h=');
disp(h);
subplot(2,2,4);
plot(P/pi, mag);
grid on;
xlabel('Normalized frequency--->');
ylabel('Magnitude in db--->');
title('Frequency Response ');
34
Output:
Model Graph:
BANDPASS FILTER
0.2
hd(n)--->
w(n)--->
0 0.5
-0.2
-0.4 0
0 5 10 0 5 10
n---> n--->
Actual Impulse Response Frequency Response
0.6 0
Magnitude in db--->
0.4 -20
h(n)--->
0.2 -40
0 -60
-0.2 -80
0 5 10 0 0.5 1
n---> Normalized frequency--->
35
%PROGRAM FOR BAND STOP FILTER
clc;
clear all;
close all;
M=7;
wc1=1.2;
wc2=2;
n=0:1:M-1;
hd=ideal_lp(pi,M)-ideal_lp(wc2,M)+ideal_lp(wc1,M);
w=rectwin(M);
h=hd.*w';
disp('Filter coefficients for BSF=');
[M1,P]=freqz(h,1,2000);
mag=20*log10(abs(M1));
subplot(2,2,1);
stem(n,hd);
xlabel('n--->');
ylabel('hd(n)--->');
title('Ideal Impulse Response');
disp('hd=');
disp(hd);
subplot(2,2,2);
stem(n,w);
xlabel('n--->');
ylabel('w(n)--->');
title('Rectangular Window');
disp('w=');
disp(w);
subplot(2,2,3);
stem(n,h);
xlabel('n--->');
ylabel('h(n)--->');
title('Actual Impulse Response');
disp('h=');
disp(h);
subplot(2,2,4);
plot(P/pi, mag);
grid on;
xlabel('Normalized frequency--->');
ylabel('Magnitude in db--->');
title('Frequency Response ');
36
Output:
w= 1 1 1 1 1 1 1
Model Graph:
BANDSTOP FILTER
0.5
hd(n)--->
w(n)--->
0.5
0
-0.5 0
0 2 4 6 0 2 4 6
n---> n--->
Actual Impulse Response Frequency Response
1 5
Magnitude in db--->
0
0.5
h(n)--->
-5
0
-10
-0.5 -15
0 2 4 6 0 0.5 1
n---> Normalized frequency--->
Windows:
Theoretical calculation:
1. hd (n)=1/2π ∫ Hd(w)ejwndw
2. Select w (n)
3. Find h (n) = hd (n)w(n)
37
Rectangular Window
1, 0 n M 1
w(n)
0, otherwise
Hanning Window
2n
0.5 * 1 cos , 0 n M 1
w(n) M 1
0, otherwise
Hamming Window
2n
0.54 0.46 * cos , 0 n M 1
M 1
1. w(n)
0, otherwise
Kaiser window
2
1
/ I0 ( ) 0 n M 1
2
0
I 1 ( n ) /
w(n)
0 otherwise
Where = (M-1)/2 and I0 = the zeroth order Modified Bessel Function
If p , s , R p , and As are giventhen the following equations are needed for design.
s p
Transition width f
2
As 7.95
Filter order M 1
14.36f
0.1102( As 8.7), As 50
Parameter 0.5842( As 21)0.4 0.07886( As 21), 21 As 50
As 21
0
PostLab questions:
1. What is meant by linear phase filters?
2. What is the condition for the impulse response of FIR filter to satisfy for constant and
Phase delay and for only constant group delay?
3. What are Gibbs oscillations?
4. Give the equation for rectangular, hamming and Kaiser Windows.
5. State the condition for linear phase characteristics in FIR.
Result:
Thus a program to design the FIR low pass, high pass, band pass and band stop filters was
Written and response of the filter using MATLAB was executed.
38
Ex : No: Date:
5.IIR FILTER DESIGN
Aim:
To write a program to design the Butterworth low pass, high pass filters and find out the response
of the filter using MATLAB.
Description:
Input :( a) Enter the pass band ripple and stop band attenuation
(b)Enter the passband and stop band frequency
Output : (a) Find the order and cutoff frequency using bilinear and impulse
Invariant transformation
(b) Calculate the Analog filter coefficients H(s)
(c) Transform the Analog filter to digital filter and find H (z)
(d) Plot the responses for all the filters.
Algorithm:
Program:
% function to find order of butterworth filter using impulse invariant transformation
% Save as butt_impord
function [N,Wc]= butt_impord(w1,w2,a1,a2)
l=sqrt((1/a2^2)-1)
e=sqrt((1/a1^2)-1)
num=log10(l/e)
den=log10(w2/w1)
N=ceil((num/den))
Wc=(w1)/((e)^(1/N))
39
%function to find order of butterworth filter using bilinear transformationSave is as
butt_biord.
function [N1,Wc1]= butt_biord(w1,w2,a1,a2)
T=1;
wp1=(2/T)*tan(w1/2)
ws1=(2/T)*tan(w2/2)
lam=sqrt((1/a2^2)-1)
ep=sqrt((1/a1^2)-1)
num1=log10(lam/ep)
den1=log10(ws1/wp1)
N1=ceil((num1/den1))
Wc1=wp1/((ep)^(1/N1))
40
ylabel('magnitude --->');
Output:
Enter the Passband frequency w1=[0.2*pi]
Enter the Stopband frequency w2=[0.6*pi]
Enter the Passband ripple a1=[0.8]
Enter the Stopband ripple a2=[0.2]
l = 4.8990 ,e = 0.7500
N = 2 ,Wc = 0.7255
num = 0 0 0.5264
b= 0 0.3015 0
T = 1, wp1 = 0.6498
ep = 0.7500
N1 = 2
Wc1 = 0.7504
num1 = 1 0 0
41
Model graph
Low Pass Butterworth Filter
0
-5
-10
-15
magnitude --->
-20
-25
-30
-35
-40
-45
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
frequency --->
-20
-40
-60
magnitude --->
-80
-100
-120
-140
-160
-180
-200
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
frequency --->
42
Theoretical calculation
Bilinear Transformation
wp1=(2/T)*tan(w1/2)
ws1=(2/T)*tan(w2/2)
lam=sqrt((1/a2^2)-1)
ep=sqrt((1/a1^2)-1)
N=log10(lam/ep) / log10(ws1/wp1);
Wc1=wp1/((ep)^(1/N1));
S= 2(Z-1)
T(Z+1)
l=sqrt((1/a2^2)-1)
e=sqrt((1/a1^2)-1)
N=log10(l/e) / log10(w2/w1); ;
Wc=(w1)/((e)^(1/N));
H(S) is same
43
PostLab questions:
1. What are the properties of Butterworth low pass filters?
2. Give the magnitude function of Butterworth filter.
3. What is meant by conformal mapping?
4. Define warping effect?
5. What are the advantages and disadvantages of bilinear transformations?
Result:
Thus a program to design the Butterworth low pass and high pass filter using Matlab was written
and response of the filter was executed.
44
Ex : No: Date:
6. MULTIRATE FILTERS
Aim:
Write a program to perform the decimation and interpolation on the given input sequence operation
using Matlab.
Description:
Output: Find the decimated and interpolated output signal for the given number of samples.
Algorithm:
1. Start the program.
2. Get the amplitude of the input signal.
3. Get the decimation and interpolation factor.
4. Perform the decimation and interpolation operations using Matlab functions.
5. Plot the output signals.
6. Stop the process.
Program:
%Program for Decimate signal
clc;
clear all;
close all;
t=0:0.00025:1; % Time vector
x=sin(2*pi*30*t)+sin(2*pi*60*t);
r=4; % Factor of 4
y=decimate(x,r);
45
%View the decimated signal
subplot(2,1,2);
stem(y(1:30));
xlabel('n--->');
ylabel('Amplitude--->');
title('Decimated Signal');
46
Model graph:
Original Signal
2
1
Amplitude--->
-1
-2
0 20 40 60 80 100 120
n--->
Decimated Signal
2
1
Amplitude--->
-1
-2
0 5 10 15 20 25 30
n--->
Original Signal
2
1
Amplitude--->
-1
-2
0 5 10 15 20 25 30
n--->
Interpolated Signal
2
1
Amplitude--->
-1
-2
0 20 40 60 80 100 120
n--->
47
PostLab Questions:
Result:
Thus a program to perform decimation and interpolation the input signal was written using
MATLABand plotted.
48
Ex : No: Date:
7.EQUALIZATION
Aim:
ALGORITHM:
1. The Input values are all set
2. For input generate normally distributed random matrix.
3. For filter generate uniform distributed pseudo random matrix.
4. The filter coefficients are determined.
5. The input vector is filtered with the specified vector and stored in another vector.
6. Now all the outputs and vectors are initialized.
7. Now the LMS adaptation curve is determined using the equation
w=w+mu(Re(e(n)*conj(in))-iImg(e(n)*conj(in)))
8. Finally the generated output waveform is plotted in a semilog graph sheet
% ****************************************************
% LEAST MEAN SQUARE ALGORITHM
% ****************************************************
clear all;
close all;
randn('state',sum(100*clock)); % Returns a matrix with pseudorandom values in normal
distribution
rand('state',sum(100*clock)); % Returns a matrix with pseudorandom values in uniform
distribution
numpoints=5000; % Sampling points
numtaps = 10; % No of filter coefficients
Mu=0.01;
49
x=randn(numpoints,1)+i*randn(numpoints,1); % Complex Random Input Signal
h=rand(numtaps,1); % filter transfer function
h=h /max(h);
d = filter(h,1,x); % digital filter with num coeff h and den coeff 1 and vector x
w=[];
y=[];
in=[];
e=[];
w=zeros(numtaps+1,1)+i*zeros(numtaps+1,1); % initialize the w matrix
for n=numtaps+1:numpoints
in=x(n:-1:n-numtaps);
y(n)=w'*in;
e(n)=d(n)-y(n); % Calculates the error value
w=w+Mu*(real(e(n)*conj(in))-i*imag(real(e(n)*conj(in))));
end
figure(10);
semilogy(abs(e));grid on;
title(['LMS Adaptation Learning Curve using Mu=',num2str(Mu)]);
xlabel('Iteration Number');
ylabel('Output estimation error in db');
OUTPUT
PostLab Questions:
1. List the applications of adaptive filtering.
2. What do you mean by adaptive noise cancellation?
3. Define mean square error criterion.
4. What is in-phase and quadrature signals?
5. What are the characteristics of LMS algorithm?
RESULT :
Thus the Least Mean Square (LMS) channel equalizer was designed and the generated output
sequence was plotted using MATLAB software.
50
Ex : No: Date:
8. STUDY OF ARCHITECTURE OF DIGITAL SIGNAL PROCESSOR
Aim:
To Study the architecture of TMS320C5416 Digital Signal Processor Starter Kit (DSK).
Description:
The TMS320VC5416 fixed-point, digital signal processor (DSP) (hereafter referred to as the
device unless otherwise specified) is based on an advanced modified Harvard architecture that has one
programMemory bus and three data memory buses. This processor provides an arithmetic logic unit
(ALU) with aHigh degree of parallelism, application-specific hardware logic, on-chip memory, and
additional on-chipPeripherals. The basis of the operational flexibility and speed of this DSP is a highly
specialized instructionSet. Separate program and data spaces allow simultaneous access to program
instructions and data, providing, a high degree of parallelism. Two read operations and one write
operation can be performed in a single cycle. Instructions with parallel store and application-specific
instructions can fully utilize this architecture. In addition, data can be transferred between data and
program spaces. Such parallelism supports a powerful set of arithmetic, logic, and bit-manipulation
operations that can all be performed in a single machine cycle. The device also includes the control
mechanisms to manage interrupts, repeated
Operations, and function calls.
Architecture:
The ‟54x DSPs use an advanced, modified Harvard architecture that maximizes processing power
by maintaining one program memory bus and three data memory buses. These processors also provide an
arithmetic logic unit (ALU) that has a high degree of parallelism, application-specific hardware logic, on-
chip memory, and additional on-chip peripherals. These DSP families also provide a highly specialized
instruction set, which is the basis of the operational flexibility and speed of these DSPs. Separate program
and data spaces allow simultaneous access to program instructions and data, providing the high degree of
parallelism. Two reads and one write operation can be performed in a single cycle. Instructions with
parallel store and application-specific instructions can fully utilize this architecture. In addition, data can
be transferred between data and program spaces. Such parallelism supports a powerful set of arithmetic,
logic, and bit-manipulation operations that can all be performed in a single machine cycle. Also included
are the control mechanisms to manage interrupts, repeated operations, and function calls.
51
Architecture of TMS320VC5416 Fixed-Point Digital Signal Processor:
52
Central Processing Unit (CPU)
The CPU is common to all C54x™ devices. The C54x CPU contains:
40-bit arithmetic logic unit (ALU)
Two 40-bit accumulators
Barrel shifter
17 × 17-bit multiplier
40-bit adder
Compare, select, and store unit (CSSU)
Data address generation unit
Program address generation unit
Arithmetic Logic Unit (ALU)
The C54x DSP performs 2s-complement arithmetic with a 40-bit arithmetic logic unit
(ALU)and two 40-bit accumulators(accumulators A and B). The ALU can also perform Boolean
operations. The ALU uses these inputs:
16-bit immediate value
16-bit word from data memory
16-bit value in the temporary register, T
Two 16-bit words from data memory
32-bit word from data memory
40-bit word from either accumulator
The ALU can also function as two 16-bit ALUs and perform two 16-bit operations
simultaneously.
Accumulators
Accumulators A and B store the output from the ALU or the multiplier/adder block. They
can also provide a second input to the ALU; accumulator A can be an input to the multiplier/adder.
Each accumulator is divided into three parts:
Guard bits (bits 39–32)
High-order word (bits 31–16) Low-order word (bits 15–0)
Instructions are provided for storing the guard bits, for storing the high- and the low-order
accumulator words in data memory, and for transferring 32-bit accumulator words in or out of data
memory. Also, either of the accumulators can be used as temporary storage.
Barrel Shifter
The C54x DSP barrel shifter has a 40-bit input connected to the accumulators or to data
memory (using CB or DB), and a 40-bit output connected to the ALU or to data memory (using
EB). The barrel shifter can produce a left shift of 0 to 31 bits and a right shift of 0 to 16 bits on the
input data. The shift requirements are defined in the shift count field of the instruction, the shift
count field (ASM) of status register ST1, or in temporary register T (when it is designated as a
shift count register).
The barrel shifter and the exponent encoder normalize the values in an accumulator in a
single cycle. The LSBs of the output are filled with 0s, and the MSBs can be either zero filled or
sign extended, depending on the state of the sign-extension mode bit (SXM) in ST1. Additional
shift capabilities enable the processor to perform numerical scaling, bit extraction, extended
arithmetic, and overflow prevention operations.
53
Multiplier/Adder Unit
The multiplier/adder unit performs 17 17-bit 2s-complement multiplication with a 40-bit
addition in a single instruction cycle. The multiplier/adder block consists of several elements: a
multiplier, an adder, signed/unsigned input control logic, fractional control logic, a zero detector, a
rounder (2s complement), overflow/saturation logic, and a 16-bit temporary storage register (T).
The multiplier has two inputs: one input is selected from T, a data-memory operand, or
accumulator A; the other is selected from program memory, data memory, accumulator A, or an
immediate value.
The fast, on-chip multiplier allows the C54x DSP to perform operations efficiently such as
convolution, correlation, and filtering. In addition, the multiplier and ALU together execute
multiply/accumulate (MAC) computations and ALU operations in parallel in a single instruction
cycle. This function is used in determining the Euclidian distance and in implementing
symmetrical and LMS filters, which are required for complex DSP algorithms.
Compare, Select, and Store Unit (CSSU)
The compare, select, and store unit (CSSU) performs maximum comparisons between the
accumulator’s high and low word, allows both the test/control flag bit (TC) in status register ST0
and the transition register (TRN) to keep their transition histories, and selects the larger word in
the accumulator to store into data memory. The CSSU also accelerates Viterbi-type butterfly
computations with optimized on-chip hardware.
Status Registers (ST0, ST1)
The status registers ST0 and ST1 contain the status of the various conditions and modes for
the C54x devices. ST0 contains the flags (OVA, OVB, C, and TC) produced by arithmetic
operations and bit manipulations, in addition to the DP and the ARP fields. ST1 reflects the status
of modes and instructions executed by the processor.
54
Branch metrics used by the DADST and DSADT instructions for ACS operation of Viterbi
decoding
In addition, the EXP instruction stores the exponent value computed into T register, and
then the NORM instruction uses the T register value to normalize the number.
Memory-Mapped Registers
The 64K words of data memory space include the device’s memory-mapped registers,
which reside in data page 0 (data addresses 0000h–007Fh).
The peripheral registers are used as control and data registers in peripheral circuits. These
registers reside within addresses 0020h–005F and reside on a dedicated peripheral bus structure.
For a list of peripherals on a particular C54x device.
The scratch-pad RAM block (60h–7Fh in data memory) includes 32 words of DARAM for
variable storage that helps avoid fragmenting the large RAM block.The data memory space
contains memory-mapped registers for the CPU and the on-chip peripherals. Simplifying access to
them. The memory-mapped access provides a convenient way to save and restore the registers for
context switches and to transfer information between the accumulators and the other registers.
Data Memory
The data memory space addresses up to 64K of 16-bit words. The device automatically
accesses theOn-chip RAM when addressing within its bounds. When an address is generated
outside the RAM bounds,the device automatically generates an external access.
The advantages of operating from on-chip memory are as follows:
· Higher performance because no wait states are required
· Higher performance because of better flow within the pipeline of the central arithmetic logic unit
(CALU)
55
· Lower cost than external memory
· Lower power than external memory
The advantage of operating from off-chip memory is the ability to access a larger address space.
Program Memory
Software can configure their memory cells to reside inside or outside of the program
address map. When the cells are mapped into program space, the device automatically accesses
them when their addressesare within bounds. When the program-address generation (PAGEN)
logic generates an address outside itsBounds, the device automatically generates an external
access.
The advantages of operating from on-chip memory are as follows:
· Higher performance because no wait states are required
· Lower cost than external memory
· Lower power than external memory
The advantage of operating from off-chip memory is the ability to access a larger address space.
Code Composer is the DSP industry's first fully integrated development environment (IDE)
with DSP-specific functionality. With a familiar environment liked MS-based C++TM, Code
Composer lets you edit, build, debug, profile and manage projects from a single unified
environment. Other unique features include graphical signal analysis, injection/extraction of data
56
signals via file I/O, multi-processor debugging, automated testing and customization via a C-
interpretive scripting language and much more.
To Compile:
Project Compile
To Build:
Project Build
If there is more number of warnings after build, then
Project Build Options Advanced (in Category) Use Far Calls (- mf)
57
To execute project:
Debug Run.
To Plot Graph:
View Graph (OR Right click in the program Insert Graph)
Select proper Properties and specify the address.
Result:
Thusthe architecture of TMS320C5416 Digital Signal Processor Starter Kit (DSK) and
programming steps for Code Composer Studio was studied.
58
Ex : No: Date:
9. MAC OPERATION USING VARIOUS ADRESSING MODES
Aim:
To perform MAC operation usingvarious addressing modes of TMS320C5416 DSP processor.
Algorithm:
Program:
.global _main
.mmregs
.data
X: .word 50h
Y: .word 20h
.text
_main
STM X,AR2
STM Y,AR3
STM #1500h,AR4
ADD *AR2,*AR3,A
STL A,*AR4+
STH A,*AR4
.end
Output:
0x1500: 0x0000
59
0x1501: 0x0070
.global _main
.mmregs
.data
X: .word 60h
Y: .word 20h
.text
_main
STM X,AR2
STM Y,AR3
STM #1500h,AR4
SUB *AR2,*AR3,A
STL A,*AR4+
STH A,*AR4
.end
Output:
0x1500: 0x0000
0x1501: 0x0040
.global _main
.mmregs
.data
X: .word 30h
Y: .word 20h
.text
_main
STM X,AR2
STM Y,AR3
STM #1500h,AR4
MPY *AR2,*AR3,A
STL A,*AR4+
STH A,*AR4
.end
Output:
0x1500: 0x0600
.global _main
.mmregs
.data
X: .word 90h
Y: .word 30h
.text
60
_main
STM X,AR2
STM Y,AR3
STM #1500h,AR4
LD *AR2+,A
RPT #15
SUBC *AR3,A
STL A,*AR4+
STH A,*AR4
.end
SUBC performs binary division like long division. For 16-bit by 16-bit integer division, the dividend is
stored in low part accumulator A. The program repeats the SUBC command 16 times to produce a 16-bit
quotient in low part accumulator A and a 16-bit remainder in high part accumulator B. For each SUBC
subtraction that results in a negative answer, you must left-shift the accumulator by 1 bit. This corresponds
to putting a 0 in the quotient when the divisor does not go into the dividend. For each subtraction that
produces a positive answer, you must left shift the difference in the ALU output by 1 bit, add 1, and store
the result in accumulator A. This corresponds to putting a 1 in the quotient when the divisor goes into the
dividend.
Output:
0x1500: 0x0003
PostLab Questions:
1. Give an example for immediate and indirect addressing modes?
2. What do you mean by bit reversal addressing mode?
3. What are the registers available for indirect addressing mode?
4. What are barrel shifters?
5. What is arithmetic and logical shift in DSP Processors?
Result:
Thus the assembly coding for MAC operation usingvarious addressing modes of DSP processor
TMS320C5416 was written and executed.
Ex :No: Date:
10.LINEAR CONVOLUTION
Aim:
Write a program to find out the linear convolution of two sequence using TMS320C5416
processor.
61
2. What is zero padding ?
3. List the properties of linear convolution.
Description:
#include<stdio.h>
int x[10]; /*={1 2 3 4 0 0 0} Input Signal Samples*/
int h[10]; /*={1 2 3 4 0 0 0} Impulse Response */
/*At the end of input sequences pad 'M' and 'N' no. of zero's*/
int y[10];
int m=4; /*Lenght of input samples sequence x(n)*/
int n=4; /*Lenght of impulse response h(n) */
int i,j;
main()
{
printf(" enter the first sequence\n");
for(i=0;i<m+n-1;i++)
scanf("%d",&x[i]);
printf(" enter the second sequence\n");
for(j=0;j<m+n-1;j++)
scanf("%d",&h[j]);
for(i=0;i<m+n-1;i++)
{
y[i]=0;
for(j=0;j<=i;j++)
y[i]+=x[j]*h[i-j];
}
printf("output\n");
for(i=0;i<m+n-1;i++)
printf("%d\n",y[i]);
62
}
Result:
MODEL GRAPH
63
Postlab Questions :
64
Result:
Thus a program to find out the linear convolution of two sequences using TMS320C5416
processor was written and executed.
Ex:No: Date:
11.CIRCULAR CONVOLUTION
Aim:
Write a program to find out the circular convolution of two sequences using TMS320C5416
processor.
65
1. What is the MATLAB function used to perform linear & circular convolution?
2. How will you determine the maximum length of the convolution of the sequences?
3. List the methods used to find the circular convolution.
Description:
Input: Give the input x (n) and h (n) in matrix form.
N 1
y ( n) x ( k ) h( n k )
k 0
Algorithm:
#include <stdio.h>
int N1,N2,N,x[30],h[30],y[30],i,j,k;
void main()
{
printf("enter the length of first sequence\n");
scanf("%d",&N1);
printf("enter the length of second sequence\n");
scanf("%d",&N2);
printf("Enter first sequence elements\n");
for(i=0;i<N1;i++)
scanf("%d",&x[i]);
printf("Enter second sequence elements\n");
for(i=0;i<N2;i++)
scanf("%d",&h[i]);
if(N1>N2)
{
N=N1;
66
}
else
{
N=N2;
}
for(i=N1;i<N;i++)
x[i]=0;
for(j=N2;j<N;j++)
h[j]=0;
for(k=0;k<N;k++)
{
y[k]=0;
for(i=0;i<N;i++)
{
j=k-i;
if(j<0)
{
j=N+j;
}
y[k]=y[k]+(x[i]*h[j]);
}
}
printf("The circular convolution is \n");
for(k=0;k<N;k++)
printf("%d\t",y[k]);
#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 length of both sequences are not equal*/
{
if(m>n) /* Pad the smaller sequence with zero*/
67
{
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++) /*folding h(n) to h(-n)*/
a[j]=h[n-j];
/*Circular convolution*/
for(i=0;i<n;i++)
y[0]+=x[i]*a[i];
for(k=1;k<n;k++)
{
y[k]=0;
/*circular shift*/
for(j=1;j<n;j++)
x2[j]=a[j-1];
x2[0]=a[n-1];
for(i=0;i<n;i++)
{
a[i]=x2[i];
y[k]+=x[i]*x2[i];
}
}
/*displaying the result*/
printf(" the circular convolution is\n");
for(i=0;i<n;i++)
printf("%d \t",y[i]);
}
Model Graph:
68
Output:
69
PostLab Questions:
Result:
Thus a program to find out the circular convolution of two sequences using TMS320C5416
processor was written and executed.
Program:
for (n=0;n<=N-1;n++)
{
xr[n]=sin(2*pi*10*n/8.0);
xi[n]=0;
}
for (k=0;k<N;k++)
{
XR[k]=0;
XI[k]=0;
X[k]=sqrt((XR[k]*XR[k])+(XI[k]*XI[k]));
}
printf("X(k) and magnitude of X(k)\n");
for (k=0;k<N;k++)
{
printf("\n X[%d] = %f + j %f \n",k,XR[k],XI[k]);
printf(" magnitude of X(%d) = %f\n",k,X[k]);
}
}
//Program for DFT
#include<stdio.h>
#include<math.h>
#define pi 3.1415
#define N 8
int i,k,n;
float X[N];
float xr[N],xi[N];
float XR[N],XI[N];
main()
{
for (n=0;n<=N-1;n++)
{
xr[n]=sin(2*pi*10*n/8.0);
xi[n]=0;
}
for (k=0;k<N;k++)
{
XR[k]=0;
XI[k]=0;
X[k]=sqrt((XR[k]*XR[k])+(XI[k]*XI[k]));
}
printf("X(k) and magnitude of X(k)\n");
for (k=0;k<N;k++)
{
72
printf("\n X[%d] = %f + j %f \n",k,XR[k],XI[k]);
printf(" magnitude of X(%d) = %f\n",k,X[k]);
}
}
Model Graph:
Graph Properties:
Sample Values:
X(k) and magnitude of X(k)
73
X[2] = -0.002035 + j 3.999998
magnitude of X(2) = 3.999999
Calculation:
Formula:
M nk
j 2
X ( k ) x ( n) e n
;0 k N 1
k 0
Postlab Questions :
Result:
Thus a program was written to perform Discrete Fourier Transform and executed using DSP
processor.
74
Ex : No: Date:
13. WAVEFORM GENERATION
Aim:
To write a program to generate Sine wave and Ramp wave form using TMS320C5416 DSP
Processor.
Algorithm:
.global _main
.mmregs
.def start
.data
.text
_main
75
RAMP1 SUB B,0,A
STM #40,BRC
RPTB RAMP2
STL A,*AR4+
LD #1h,0,B
The repeat-block instructions are used to repeat a block of code N + 1 times, where N is the value loaded
into the block-repeat counter register (BRC).
BRC contains the value N, which is one less than the number of times the block is to be repeated. The
block-repeat start address register (RSA) holds the address of the first instruction of the block of code to
be repeated. The block-repeat end address register (REA) holds the address of the last instruction word of
the block of code to be repeat
Model Graph:
Graph Property:
76
Program:
#include <stdio.h>
#include<math.h>
#define FREQ 1000
float a[128];
main()
{
int i=0;
for(i=0;i<128;i++)
{
a[i]=sin(2*3.14*FREQ*i/24000);
printf("%f",a[i]);
}
}
Model Graph:
77
Graph Property:
Result:
Thus the program was written to generate a Ramp signal, Sine signal and executed using DSP
processor.
Description:
Input: Give the cutoff frequency and order of the filter
Output: 1. Find the ideal impulse response hd (n) of the filter order.
2. Find the window coefficients w (n) using the appropriate window
Function.
3. Find the filter coefficients h (n) =hd (n)*w (n).
4. Plot hd (n), w (n) and h (n).
Algorithm:
Program:
#include<stdio.h>
#include<math.h>
#define pi 3.14
int n,N;
float hd[10],alpha,w[10],h[10],wc;
main()
{
printf("enter N value");
scanf("%d",&N);
printf("enter wc value");
scanf("%f",&wc);
for(n=0;n<N;n++)
{
/*Hamming window function*/
79
w[n]=0.54-0.46*(cos((2*pi*n)/(N-1)));
printf("w[%d]= %f \n",n,w[n]);
}
alpha=(N-1)/2;
/* Impulse function */
for(n=0;n<N;n++)
{
if(n!=alpha)
hd[n]=sin(wc*(n-alpha))/(pi*(n-alpha));
else
hd[n]=wc/3.14;
printf("hd[%d]= %f\n",n,hd[n]);
}
/*Filter coefficients*/
for(n=0;n<N;n++)
{
h[n]=hd[n]*w[n];
printf("h[%d]= %f\n",n,h[n]);
}
Output:
enter N value11
enter wc value1.2
window coefficients:
w[0]= 0.080000 w[1]= 0.167766 w[2]= 0.397574 w[3]= 0.681730
w[4]= 0.911803 w[5]= 0.999999 w[6]= 0.912664 w[7]= 0.683123
w[8]= 0.398967 w[9]= 0.168629 w[10]= 0.080002
Model Graph:
80
Graph Property:
Theoretical calculation:
81
1. hd(n)=1/2π ∫ Hd(w)ejwndw
2. Select w (n)
3. Find h (n) = hd (n) w (n)
Rectangular Window
1, 0 n M 1
w(n)
0, otherwise
Hanning Window
2n
0.5 * 1 cos , 0 n M 1
M 1
w(n)
0, otherwise
Hamming Window
2n
0.54 0.46 * cos , 0 n M 1
M 1
2. w(n)
0, otherwise
1. What is the necessary and sufficient condition for linear phase characteristics in
FIR filter?
2. What is the principle of designing FIR filter using frequency sampling method?
3. What is the principle of designing FIR filter using frequency sampling method?
4. What are the disadvantages of' Fourier series method?
Result:
Thus a program was written to implement Low pass filter using Finite Impulse Response and
executed using DSP processor.
Ex No : Date :
82
15. FINITE WORD LENGTH EFFECT
Aim:
To study the functions of finite word length effect in fixed point DSP systems..
Apparatus Required:
Hardware : Personal Computer & TMS320C67XX kit
Software : Code Composer Studio version4
Program:
function ADCNoiseGain=ADCNoise(b,a,n,FM) [B,A] = sos2tf([b a]);
%form A(z) and B(z) [h,t] = impz(B,A,n);
ADCNoiseGain = sum(h.^2)/12.0;
fprintf('ADC noise gain is %f\n\n',ADCNoiseGain);
if FM~=1
fprintf('ADC noise is %g^2*%g*q^2\n',[FM ADCNoiseGain]);
else
fprintf('ADC noise is %g*q^2\n',ADCNoiseGain);
end function
CoeffQuantizeErr(b,a,maxbits,ftype,f,Fs)
%COEFFICIENT QUANTIZATION ERROR ANALYSIS
n=256;
for nbits=2:maxbits [B,A]=QuantizeCoeff(b,a,nbits);
[B,A] = sos2tf([B A]);
[h,w] = freqz(B,A,n);
amag = abs(h);
amag = amag/max(amag);
fprintf('\n\nnbits\tstage\tA1\tA2\tradius1\tangle1\tradiu s2\tangle2\n');
for nbits=2:maxbits [B,A]=QuantizeCoeff(b,a,nbits);
for i=1:size(b,1) r1 = sqrt(abs(A(i,3)));
angle1 = 180/pi*acos(A(i,2)/(-2.0*r1));
r2 = sqrt(abs(a(i,3)));
angle2 = 180/pi*acos(a(i,2)/(-2.0*r2));
fprintf('%d\t%d\t%-7.4f\t%-7.4f\t%-7.4f\t%-7.2f\t%- 7.4f\t%-7.2f\n', nbits, i,A(i,2) , A(i,3),
r1,angle1,r2,angle2);
end
end format;
function ScaleFactor(b,a,nstep,size,structure) norm0 = DirectScale(b,a,0,nstep);
norm1 = DirectScale(b,a,1,nstep);
norm2 = DirectScale(b,a,2,size);
83
else norm0 = CanonicScale(b,a,0,nstep);
norm1 = CanonicScale(b,a,1,nstep);
norm2 = CanonicScale(b,a,2,size);
end disp('L1-norms of the second order sections:');
disp(norm0); disp('L2-norms of the second order sections:');
disp(norm1); disp('Loo-norms of the second order sections:');
disp(norm2);
function s = DirectScale(b,a,iopt,n)
if(iopt>=3) s = ones(1,size(b,1));
return;
else
A = 1; B = 1;
for i=1:size(b,1)
%loop for each stage
A = conv(A,a(i,:));
B = conv(B,b(i,:));
s(i) = GetScaleFactor(B,A,iopt,n);
end
end function
s = CanonicScale(b,a,iopt,n)
if(iopt>=3)
s = ones(1,size(b,1));
return;
else
A = 1;
B = 1;
for i=1:size(b,1)
A = conv(A,a(i,:));
if i>1 B = conv(B,b(i-1,:));
end
s(i) = GetScaleFactor(B,A,iopt,n);
end
end
Result:
Thus the function of finite word length effect in fixed point DSP processor is studied.
Ex :No: Date:
84
16. INTRODUCTION TO IMAGE PROCESSING TOOLBOX
Aim:
To study the basic operations in image processing using MATLAB program.
Description:
Input: Give input images from MATLAB edit window.
Output: Perform various image processing techniques given and display it in different Figure
window.
Algorithm:
Program:
85
% PROGRAM FOR CONVERTING COLOR IMAGE TO GRAY SCALE
I = imread('board.tif');
J = rgb2gray(I);
figure, imshow(I), figure, imshow(J);
Sample Output
ORIGINAL IMAGE
IMAGE HISTOGRAM
1600
1400
1200
1000
800
600
400
200
86
COLOR IMAGE GRAY SCALE IMAGE
PostLab Questions:
Result:
Thus a MATLAB program for studying the image processing tool box was written, executed and
the graphs were plotted.
87
Ex No : Date :
Aim:
To study the applications of Dual Tone Multi- Frequency (DTMF) signals in telephones and to
generate and visualize the DTMF signals using MATLAB program.
Description:
Input: Generate sine input signal for low and high frequencies.
Output:
i. Represent the generated low and high frequency signals using DFT.
ii. Generate the Matlab code for the generation and visualization of the DTMF tones
Algorithm:
1. Start the program.
2. Generate the sinusoidal signal with low frequency group f = 697 Hz, 770 Hz, 852 Hz,
941 Hz and high frequencies h= 1209 Hz, 1336 Hz, 1477Hz.
3Set the sampling frequency 8 KHz,N = 800 , No of samples at a spacing of 100ms.
4. Generate and visualize the DFT of the corresponding low and high frequency signal.
5. Stop the program.
Theory :
Dual-tone Multi-Frequency (DTMF) signaling is the basis for voice communications control and is widely
used worldwide in modern telephony to dial numbers and configure switchboards. It is also used in
systems such as in voice mail, electronic mail and telephone banking.
Generating DTMF Tones. A DTMF signal consists of the sum of two sinusoids - or tones - with
frequencies taken from two mutually exclusive groups. These frequencies were chosen to prevent any
harmonics from being incorrectly detected by the receiver as some other DTMF frequency. Each pair of
tones contains one frequency of the low group (697 Hz, 770 Hz, 852 Hz, 941 Hz) and one frequency of
the high group (1209 Hz, 1336 Hz, 1477Hz) and represents a unique symbol. The frequencies allocated to
the push-buttons of the telephone pad are shown below:
88
Matlab Program
i. Generation of the twelve frequency pairs
Clear all;
Close all;
symbol = {'1','2','3','4','5','6','7','8','9','*','0','#'};
lfg = [697 770 852 941]; % Low frequency group
hfg = [1209 1336 1477]; % High frequency group
f = [];
for c=1:4,
for r=1:3,
f = [ f [lfg(c);hfg(r)] ];
end
end
ans =
697 1209
697 1336
697 1477
770 1209
770 1336
770 1477
852 1209
852 1336
852 1477
941 1209
941 1336
941 1477
Matlab code for the generation and visualization of the DTMF tones
tones = zeros(N,size(f,2));
for toneChoice=1:12,
% Generate tone
tones(:,toneChoice) = sum(sin(f(:,toneChoice)*pit))';
% Plot tone
subplot(4,3,toneChoice),plot(t*1e3,tones(:,toneChoice));
title(['Symbol "', symbol{toneChoice},'":
[',num2str(f(1,toneChoice)),',',num2str(f(2,toneChoice)),']'])
set(gca, 'XLim', [0 25]);
ylabel('Amplitude');
if toneChoice>9, xlabel('Time (ms)'); end
89
end
set(gcf, 'Color', [1 1 1], 'Position', [1 1 1280 1024])
annotation(gcf,'textbox', 'Position',[0.38 0.96 0.45 0.026],...
'EdgeColor',[1 1 1],...
'String', '\bf Time response of each tone of the telephone pad', ...
'FitBoxToText','on');
MODEL GRAPH
Amplitude
Amplitude
0 0 0
-2 -2 -2
0 5 10 15 20 25 0 5 10 15 20 25 0 5 10 15 20 25
Amplitude
Amplitude
0 0 0
-2 -2 -2
0 5 10 15 20 25 0 5 10 15 20 25 0 5 10 15 20 25
Amplitude
Amplitude
0 0 0
-2 -2 -2
0 5 10 15 20 25 0 5 10 15 20 25 0 5 10 15 20 25
Amplitude
Amplitude
0 0 0
-2 -2 -2
0 5 10 15 20 25 0 5 10 15 20 25 0 5 10 15 20 25
Time (ms) Time (ms) Time (ms)
PostLab Questions:
1. What are the applications of DSP systems?
2. List the procedure for generation of DTMF signals.
3. Define Goertzel algorithm for DFT estimation.
4. What are the types of multiple access in communication systems?
5. Define OFDM.
Result:
Thus a program to generate and visualize DTMF tones for telephone communication using Matlab
was written and executed.
90