Digital Signal Processing Lab Manual
Digital Signal Processing Lab Manual
Digital Signal Processing Lab Manual
SATHYABAMA UNIVERSITY
(Established under Section 3 of the UGC Act, 1956)
(A CHRISTIAN MINORITY INSTITUTION)
Jeppiaar Nagar, Rajiv Gandhi Road, Chennai – 600 119, Tamilnadu. India.
-1-
LIST OF EXPERIMENTS
Sl.No DATE DESCRIPTION PAGE NO
1. Generation of signals- Discrete form & 3
Continuous form
2. Linear Convolution 6
3. Circular Convolution 7
4. Auto Correlation 9
5. Cross Correlation 10
-2-
1. GENERATION OF SIGNALS
DISCRETE & CONTINUOUS FORM
ALGORITHM:
Formula used
Unit impulse
Unit step
Sine signal
X(n)= A sin(wn+θ)
Cosine signal
X(n)= A cos(wn+θ)
Exponential Signal
X(n)=exp(n)
PROGRAM MODEL :
clc
N=21
x=ones(1,N);
n=0:1:N-1
subplot(3,2,1);
stem(n,x);
xlabel('n');
ylabel('x(n)');
title('unit step signal');
N=21
-3-
x=sin(.2*pi*n);
n=0:1:N-1;
subplot(3,2,2);
stem(n,x); SIMULATED OUTPUT:
xlabel('n');
ylabel('y(n)'); CONTINUOUS SIGNALS OUTPUT
title('sinusoidal signal');
N=21
x=cos(.2*pi*n);
n=0:1:N-1;
subplot(3,2,3);
stem(n,x);
xlabel('n');
ylabel('y(n)');
title('cosine signal');
N=21
x=n;
n=0:1:N-1
subplot(3,2,4);
stem(n,x);
xlabel('n');
ylabel('x(n)');
title('ramp signal');
N=21
x=exp(n);
n=0:1:N-1
subplot(3,2,5);
stem(n,x);
xlabel('n');
ylabel('x(n)');
title('exponential signal');
N=21
x=[ones(1,1),zeros(1,N-1)];
n=0:1:N-1
subplot(3,2,6);
stem(n,x);
xlabel('n');
ylabel('y(n)');
title('impulse signal');
clc
N=21
x=ones(1,N);
n=0:1:N-1
subplot(3,2,1);
plot(n,x);
xlabel('n');
ylabel('x(n)');
title('unit step signal');
N=21
x=sin(.2*pi*n);
-4-
n=0:1:N-1;
subplot(3,2,2);
plot(n,x);
xlabel('n');
ylabel('y(n)');
title('sinusoidal signal');
N=21;
x=cos(.2*pi*n);
n=0:1:N-1; SIMULATED OUTPUT:
subplot(3,2,3);
plot(n,x); DISCRETE SIGNAL OUTPUT
xlabel('n');
ylabel('y(n)');
title('cosine signal');
N=21
x=n;
n=0:1:N-1
subplot(3,2,4);
plot(n,x);
xlabel('n');
ylabel('x(n)');
title('ramp signal');
N=21
x=exp(n);
n=0:1:N-1
subplot(3,2,5);
plot(n,x);
xlabel('n');
ylabel('x(n)');
title('exponential signal');
N=21
x=[ones(1,1),zeros(1,N-1)];
n=0:1:N-1;
subplot(3,2,6);
plot(n,x);
xlabel('n');
ylabel('y(n)');
title('impulse signal');
RESULT: Thus the program was executed in MATLAB & the output was verified.
-5-
2. LINEAR CONVOLUTION
ALGORITHM:
RESULT: Thus the program was executed in MATLAB & the output was verified.
-6-
3. CIRCULAR CONVOLUTION
ALGORITHM :
Formula:
PROGRAM :
SIMULATED OUTPUT :
RESULT : Thus the program was executed in MATLAB and the output was
verified.
-8-
4. AUTO – CORRELATION
ALGORITHM :
Formula
PROGRAM :
SIMULATED OUTPUT :
g=[1,2,3,4];
n1=length(g);
m=0:1:n1-1;
figure();
subplot(2,2,1);
stem(m,g);
xlabel('m');
ylabel('g(m)');
grid;
title('Input Sequence-1');
y=xcorr(g,g);
n2=n1+n1-1;
x=0:1:n2-1;
subplot(2,2,2);
stem(x,y);
disp(y);
xlabel('x');
ylabel('y(x)');
grid;
title('Output Sequence');
RESULT : Thus the program was executed in MATLAB & the output was
verified.
-9-
5. CROSS – CORRELATION
ALGORITHM :
g=[1,2,3,4];
h=[4,3,2,1];
n1=length(g);
n2=length(h); SIMULATED OUTPUT :
m=0:1:n1-1;
figure();
subplot(2,2,1);
stem(m,g);
xlabel('m');
ylabel('g(m)');
grid;
title('Input Sequence-1');
n=0:1:n2-1;
subplot(2,2,2);
stem(n,h);
xlabel('n');
ylabel('h(n)');
grid;
title('Input Sequence-2');
y=xcorr(g,h);
n3=n1+n2-1;
x=0:1:n3-1;
subplot(2,2,3);
stem(x,y);
disp(y);
xlabel('x');
ylabel('y(x)');
grid;
title('Output Sequence');
RESULT : Thus the program was executed in MATLAB & the output was
verified.
- 10 -
6. DISCRETE FOURIER TRANSFORM
ALGORITHM :
x=[1,2,3,4,0,0,0,0];
N=8;
y=fft(x,N);
mag=abs(y); SIMULATED OUTPUT :
phase=angle(y);
n=0:1:N-1;
subplot(2,2,1);
stem(n,x);
xlabel('n');
ylabel('x(n)');
title('input sequence');
subplot(2,2,2);
stem(n,mag);
xlabel('n');
ylabel('magnitude');
title('magnitude sequence');
subplot(2,2,3);
stem(n,phase);
xlabel('n');
ylabel('angle');
title('phase sequence');
RESULT : Thus the program was executed in MATLAB & the output was
verified.
- 11 -
7. INVERSE DISCRETE FOURIER TRANSFORM
ALGORITHM :
Formula
PROGRAM :
X=[4,3,2,1,0,0,0,0];
N=8;
SIMULATED OUTPUT :
y=ifft(x,N);
mag=abs(y);
phase=angle(y);
k=0:1:N-1;
subplot(2,2,1);
stem(k,X);
xlabel('k');
ylabel('X(k)');
title('input sequence');
subplot(2,2,2);
stem(k,mag);
xlabel('k');
ylabel('magnitude');
title('magnitude sequence');
subplot(2,2,3);
stem(k,phase);
xlabel('k');
ylabel('angle');
title('phase sequence');
disp(y);
RESULT : Thus the program was executed in MATLAB & the output was
verified.
- 12 -
8. BUTTERWORTH FILTER
ALGORITHM :
N =(log√(10^0.1αs-1)(10^0.1αp-1))/(log(Ωs/Ωp)).
Formula
The transfer function of the Butterworth reference analog prototype filter is
expressed as follows:
where: Sk is the k-th pole of the Butterworth filter transfer function, N is the filter
order.
PROGRAM :
INPUT :
COMMAND WINDOW :
h =4
wn =0.5821
b =0.1518 0.6073 0.9109 0.6073 0.1518
a =1.0000 0.6418 0.6165 0.1449 0.0259
ALGORITHM :
N =(log√(10^0.1αs-1)(10^0.1αp-1))/(log(Ωs/Ωp)).
- 14 -
5. Find the filter coefficients.
6. Draw the magnitude and phase responses.
7. Stop.
PROGRAM :
clc;clear all; close all;
alphap=input('enter the pass band ripple');
alphas=input('enter the stop band ripple');
fp=input('enter the pass band freq');
fs=input('enter the stop band freq');
f=input('enter the sampling frequency');
omp=2*(fp/f);
oms=2*(fs/f);
[h,wn]=buttord(omp,oms,alphap,alphas)
[b,a]=butter(h,wn,'high')
w=0:0.01:pi;
[h,om]=freqz(b,a,w); SIMULATED OUTPUT(HPF) :
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(om/pi,m);
grid;
ylabel('gain in db');
xlabel('Normalised frequency');
subplot(2,1,2);
plot(om/pi,an);
grid;
ylabel('phase in radians');
xlabel('Normalized frequency');
INPUT:
COMMAND WINDOW :
h =4
wn =0.5821
b =0.0535 -0.2139 0.3209 -0.2139 0.0535
a =1.0000 0.6418 0.6165 0.1449 0.0259
ALGORITHM :
- 15 -
1. Get the pass band and stop band ripples.
2. Calculate the order of the filter using the formula,
N =(log√(10^0.1αs-1)(10^0.1αp-1))/(log(Ωs/Ωp)).
PROGRAM :
INPUT :
ALGORITHM :
- 16 -
N =(log√(10^0.1αs-1)(10^0.1αp-1))/(log(Ωs/Ωp)).
PROGRAM :
INPUT :
RESULT : Thus the program was executed in MATLAB & the output was verified.
9. CHEBYSHEV FILTER
ALGORITHM :
1. Get the pass band and stop band ripples.
2. Calculate the order of the filter using the formula,
N = (cosh^-1(√((10^0.1αs-1)/(10^0.1αp-1))))/(cosh^-1(Ωs/Ωp)).
- 17 -
3. Find the filter coefficients.
4. Draw the magnitude and phase responses.
5. Stop.
Formula
Chebyshev analog filter is defined via expression:
Ω is the frequency;
N is the filter order;
ε is a parameter used to define maximum oscillations in the passband
frequency response; and
TN is the Chebyshev polynomial. The Chebyshev polynomial TN(Ω) can be
obtained via recursive relations:
where:
si is the i-th transfer function pole of analog prototype filter (complex value);
σi is the pole; and
Ωi is the imaginary pole.
where:
N is the filter order; and i=1, 2, ..., N.
The value of parameter ε is obtained via expression:
- 18 -
Low-pass filter
s1 is a lower cut-off frequency in the stopband and Ωs2 is a higher cut-off frequency in
the stopband.
The transformation into a band-pass analog filter is expressed as:
where:
Ωp1 is a lower cut-off frequency in the passband and Ωp2 is a higher cut-off frequency in
the passband.
PROGRAM :
clc;close all;clear all;
ap=input('give the pass band attenuation in db');
as=input('give the stop band in db');
wp=.2*pi;
ws=.3*pi;
[n,wn]=cheb1ord(wp/pi,ws/pi,ap,as);
[b,a]=cheby1(n,ap,wn);
w=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(om/pi,m);
grid;
ylabel('gain in db');
xlabel('normalised frequency');
- 19 -
subplot(2,1,2);
plot(om/pi,an);
grid;
ylabel('phase in radians');
xlabel('normalised frequency');
title('cheby low pass filter');
INPUT :
ALGORITHM :
N = (cosh^-1(√((10^0.1αs-1)/(10^0.1αp-1))))/(cosh^-1(Ωs/Ωp)).
PROGRAM :
clc;close all;clear all;
ap=input('give the pass band attenuation in db');
as=input('give the stop band in db');
ws=.2*pi;
wp=.3*pi;
[n,wn]=cheb1ord(wp/pi,ws/pi,ap,as);cv
[b,a]=cheby1(n,ap,wn,'high');
w=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log(abs(h));
an=angle(h);
subplot(2,1,1);
plot(om/pi,m);
grid;
ylabel('gain in db');
xlabel('normalised frequency');
subplot(2,1,2);
plot(om/pi,an);
grid;
ylabel('phase in radians');
xlabel('normalised frequency');
- 20 -
title('cheby high pass filter');
INPUT :
ALGORITHM :
N = (cosh^-1(√((10^0.1αs-1)/(10^0.1αp-1))))/(cosh^-1(Ωs/Ωp)).
PROGRAM :
INPUT :
- 21 -
Give the pass band attenuation in db 0.4
Give the stop band in db 30
ALGORITHM :
N = (cosh^-1(√((10^0.1αs-1)/(10^0.1αp-1))))/(cosh^-1(Ωs/Ωp)).
PROGRAM :
INPUT :
Give the pass band attenuation in db .4
Give the stop band in db30
RESULT : Thus the program was executed in MATLAB & the output was verified.
- 22 -
10. RECTANGULAR AND HAMMING WINDOW
ALGORITHM :
hd(n)=1/πn sin(πn/2).
PROGRAM :
RESULT : Thus the program was executed in MATLAB & the output was verified
ALGORITHM :
3. Find Wc = 0.5 * Pi
4. Calculate hd(n), hw(n), h(n) for various values of Kaiser window.
5. Plot the graph n
Hint:
To create the Kaiser windows, use the Matlab command kaiser(N,beta) command where N
is the length of the filter and beta is the shape parameter β
PROGRAM :
ALGORITHM:
PROGRAM:
clear all;
clc;
n=0:50;
x=cos(2*pi*500*n/1000);
xk=fft(x);
xk_conj=conj(xk);
k=0:50;
esdk=(xk.*xk_conj)/length(n);
stem(k,esdk);
xlabel('k');
ylabels('magnitude');
- 25 -
RESULT: Thus the program was executed in MATLAB & the output was
verified
ALGORITHM:
RESULT : Thus the program was executed in MATLAB & the output was verified
- 26 -
14. FREQUENCY RESPONSE OF SYSTEM
AIM: To write a program in MATLAB to plot the frequency response of the system.
ALGORITHM:
1.Get the input for the signal
2. Calculate the required parameter for first order frequency response.
3.Plot the given input signal.
4.Plot the graph of magnitude spectrum.
5.Plot the graph of phase spectrum.
6.Stop
Theory
The frequency response of a system, H ( ) is just the transfer function, H (s ) evaluated at
s j . Frequency response is usually a complex valued function, so it can be written as
H () H () H () , where H () is the magnitude response and H ( ) is the phase
response.
PROGRAM:
clc;
b=[1];
a=[1,-.8];
w=0:.01:2*pi;
[h]=freqz(b,a,w);
subplot(2,1,1),plot(w/pi,abs(h));
xlabel('Normalised frequency\omega/\pi');
ylabel('Magnitude');
title('the frequency response of a first order system h(n)=.8.^nu(n)')
subplot(2,1,2),plot(w/pi,angle(h));
xlabel('Normalised frequency\omega/\pi');
ylabel('phase in radians');
SIMULATED OUTPUT:
RESULT: Thus the program was executed in MATLAB & the output was verified
- 27 -
15. STEP RESPONSE OF SYSTEM
AIM: To write a program in MATLAB to find the step response of a system.
ALGORITHM:
SIMULATED OUTPUT:
RESULT: Thus the program was executed in MATLAB & the output was
verified
- 28 -
16. Z TRANSFORMS AND INVERSE Z TRANSFORMS
AIM
To write a program to illustrate the Z transforms process using MATLAB
functions.
ALGORITHM
1. Mention Number of Frequency Points, Numerator Coefficients and Denominator Coefficients.
2. Compute the frequency response of Z transform of Unit circle
3. Plot the Frequency Response.
4. Plot the Z transform using freqz function in MATLAB.
5. Plot the Real, Imaginary and Magnitude plots,
Formula
PROGRAM
k = input('Number of frequency points = ');
% Read in the numerator and denominator coefficients
num = input('Numerator coefficients = ');
den = input('Denominator coefficients = ');
% Compute the frequency response/Evaluate Z transform on unit circle
w = 0:pi/(k-1):pi;
h = freqz(num, den, w); SIMULATED OUTPUT OF Z TRANSFORM
% Plot the frequency response
subplot(2,2,1)
plot(w/pi,real(h));grid
title('Real part')
xlabel('\omega/\pi'); ylabel('Amplitude')
subplot(2,2,2)
plot(w/pi,imag(h));grid
title('Imaginary part')
xlabel('\omega/\pi'); ylabel('Amplitude')
subplot(2,2,3)
plot(w/pi,abs(h));grid
title('Magnitude Spectrum')
xlabel('\omega/\pi'); ylabel('Magnitude')
subplot(2,2,4)
plot(w/pi,angle(h));grid
title('Phase Spectrum')
xlabel('\omega/\pi'); ylabel('Phase, radians')
- 29 -
16.b INVERSE Z TRANSFORMS
AIM
To write a program to illustrate the Inverse Z transforms process using MATLAB functions
ALGORITHM
1. The function impz provides the samples of the time domain sequence,
2. where num and den are row vectors containing the coefficients of the numerator
and denominator polynomials of G(z) in ascending powers of z−1, L is the desired
number of the samples of the inverse transform,
3. g is the vector containing the samples of the inverse transform starting with the
sample at n = 0, t is the length of g, and FT is the specified sampling frequency in
Hz with default value of unity.
4. The function y=filter(num,den,x) can also be used to calculate the input response
of a z-transform . Where num, den represent vectors containing numerator and
denominator coefficients of z-transform.
5. While x represents input to the filter / z-transform .The length of output y is equal to
input x. If an impulse input sequence is passed to the z-transform , the output will
be the inverse z-transform
AIM
These processors can perform parallel multiply and arithmetic logic unit (ALU)
operations on integer or floating-point data in a single cycle.
EXPLANATION
- 31 -
Separate program and data buses allow simultaneous access to program
instructions and data, providing a high degree of parallelism. Such parallelism
supports a powerful set of arithmetic, logic, and bit-manipulation operations that
can all be performed in a single machine cycle. It also includes the control
mechanisms to manage interrupts ,repeated operations, and function calling.
Memory-mapped registers
Program controller
The CPU uses the CALU to perform 2scomplement arithmetic. The CALU
consists of these elements:
16-bit multiplier
Additional shifters at the outputs of both the accumulator and the product
register (PREG)
The CPU includes an independent PLU, which operates separately from, but in
parallel with, the ALU. The PLU performs Boolean operations or the bit
manipulations required of high-speed controllers.
The PLU can set, clear, test, or toggle bits in a status register, control register, or
any data memory location.
Results of a PLU function are written back to the original data memory location.
- 32 -
The CPU includes an unsigned 16-bit arithmetic logic unit that calculates indirect
addresses by using inputs from the auxiliary registers (ARs), index register
(INDX), and auxiliary register compare register (ARCR).
Accessing data does not require the CALU for address manipulation; therefore,
the CALU is free for other operations in parallel. This makes instruction to
executes faster compared to micro processors.
The program controller contains logic circuitry that decodes the operational
instructions, manages the CPU pipeline, stores the status of CPU operations,and
decodes the conditional operations.
Program counter
Hardware stack
Instruction register
Program ROM:
- 33 -
Block B1,B2 configured as data memory and B0 configured software as
data or program memory.
Hardware Timer:A 16-bit hardware timer with a 4-bit prescaler is available. The
timer can be stopped, restarted, reset, or disabled by specific status bits.
Host Port Interface (HPI) :The HPI available on the ’C57S and ’LC57 is an 8-
bit parallel I/O port that provides an interface to a host processor. Information is
exchanged between the DSP and the host processor through on-chip memory that
is accessible to both the host processor and the ’C57.
(TDM) serial port : The TDM serial port available on the ’C50, ’C51, and ’C53
devices is a fullduplexed
A buffered serial port (BSP) : The BSP available on the ’C56 and ’C57 devices
is a full-duplexed, double buffered serial port and an autobuffering unit (ABU).
The BSP provides flexibility on the data stream length.
The serial port transmitter and receiver are double-buffered and individually
controlled by maskable external interrupt signals. Data is framed either as bytes or
as words.
- 34 -
RESULT
AIM
ARCHITECTURE
EXPLANATION
- 35 -
Bus Performance) Dual Data Address Generators with Modulo and Bit-Reverse
Addressing Efficient Program Sequencing with Zero-Overhead Looping: Single-
Cycle Loop Setup Automatic Booting of On-Chip Program Memory from Byte-
Wide External Memory (e.g., EPROM ) Double-Buffered Serial Ports with
Companding Hardware, Automatic Data Buffering, and Multichannel Operation
ADSP-2111 Host Interface Port Provides Easy Interface to 68000, 80C51, ADSP-
21xx, Etc. Automatic Booting of ADSP-2111 Program Memory Through Host
Interface Port Three Edge- or Level-Sensitive Interrupts Low Power IDLE
Instruction PGA, PLCC, PQFP, and TQFP Packages MIL-STD-883B Versions
Available
3. The ADSP-2100 Family processors are single-chip microcomputers optimized for
digital signal processing (DSP) and other high speed numeric processing
applications. The ADSP-21xx processors are all built upon a common core. Each
processor combines the core DSP architecture—computation units, data address
generators, and program sequencer—with differentiating features such as on-chip
program and data memory RAM, a programmable timer, one or two serial ports,
and, on the ADSP-2111, a host interface port.
4. Fabricated in a high speed, submicron, double-layer metal CMOS process, the
highest-performance ADSP-21xx processors operate at 25 MHz with a 40 ns
instruction cycle time. Every instruction can execute in a single cycle. Fabrication
in CMOS results in low power dissipation.
5. The ADSP-2100 Family’s flexible architecture and comprehensive instruction set
support a high degree of parallelism. In one cycle the ADSP-21xx can perform all
of the following operations
RESULT
Studied Architecture and explanation of the ADSP21xx Processor
- 36 -
- 37 -