Professional Documents
Culture Documents
Digital Signal Processing Lab Manual
Digital Signal Processing Lab Manual
MANUAL
ECE: V SEMESTER
LIST OF EXPERIMENTS
MATLAB:-
INTRODUCTION TO MATLAB.
GENERATION OF SIGNALS.
LINEAR AND CIRCULAR CONVOLUTION OF TWO SEQUENCES.
SAMPLING AND EFFECT OF ALIASING.
DESIGN OF FIR FILTERS.
CALCULATION OF FFT OF A SIGNAL.
DESIGN OF IIR FILTERS.
PROCESSOR:-
AIM:
APPARATUS REQUIRED:
THEORY:
MATLAB is a high performance language for technical computing. It integrates computing, visualization
and programming in an easy way to be used by the environment where problems and solutions are
expressed in familiar mathematical notation.
2. Algorithm development
3. Data acquisition
MATLAB SYSTEM:
This is the set of tools and facilities that help you use MATLAB function and files. Many of these tools are
graphical user interfaces. It includes the MATLAB desktop and command window, command history and
editor and debugger, a code analyzer and other reports, and browser for viewing help, the workspace, files
and the search path.
This is a vast collection of computational algorithm ranging from elementary function like sum, sine,
cosine and complex arithmetic to more sophisticated functions like matrix inverse, matrix Eigen values,
Bessel functions and fast Fourier transform.
3. The MATLAB Language
This is a high level matrix/array language with control flow statements, functions, data structures, input and
output and object oriented programming features. It allows both programming in the small to rapidly create
quick and dirty throw away program and programming in the large to create large and complex
application programmer.
4. Graphics
MATLB has extensive facilities for displaying vectors and matrices as graphs as well as annotating and
printing these graphs. It includes high-level functions for two and three dimensional data visualization,
image processing animation and presentation graphics.
This is a library that allows you to write a C program and function FORTRAN programmer that interacts
with MATLAB. It includes facilities for calling routines from MATLAB (dynamic range), calling
MATLAB as a computational engine, and for reading and writing MATLAB files.
EXAMPLES:
RESULT:
AIM:
To draw the waveform for unit step, unit ramp, unit impulse, exponential, sine and cosine wave using
MATLAB program.
APPARATUS REQUIRED:
PC with MATLAB
ALGORITHM:
STEP2: Divide output screen into number of portions by using sub-plot command.
STEP3: Then the function for unit step, ramp, impulse and exponential, sine and cosine waves are
declared.
PROCEDURE:
4. Note the output and plot the graph for the output.
PROGRAM:
clc;
clear all;
figure(1);
subplot(3,2,1);
a=5;
t=-a ; a;
i =[zeros(1,a),1,ones(1,a)];
x label (time);
y label (amplitude);
subplot (3,2,2);
figure (1);
a=5;
t=-a;a;
x=t.i;
stem(t,x);
x label (time);
y label (amplitude);
subplot (3,2,3);
figure (1);
a=5;
t=-a:a;
j=[zeros(1,a),1,zeros(1,a)];
stem (t,j);
x label (time);
y label (amplitude);
subplot (3,2,4);
figure (1);
a=5;
t=-a:a;
x=exp(t);
stem (t,x);
x label (time);
y label (amplitude);
subplot (3,2,5);
t=0:.01:2;
x=sin(2*pi*t);
plot (t,x);
line ([0,2],[0,0]);
x label (time);
y label (amplitude);
subplot (3,2,6);
t=0:.01:2;
x=cos(2*pi*t);
plot(t,x);
line([0,2],[0,0]);
x label (time);
y label (amplitude);
title(cosine wave);
RESULT:
Thus the waveform for unit step, unit ramp, unit impulse, unit exponential, and sine and cosine wave
obtained using MATLAB program.
3. LINEAR AND CIRCULAR CONVOLUTION OF TWO SEQUENCES
AIM:
APPARATUS REQUIRED:
PC with MATLAB
ALGORITHM:
THEORY:
LINEAR CONVOLUTION:
If the two inputs are each of length n1 and n2 the output is of length n1+n2-1.the linear convolution
between the two inputs is equivalent to flipping one input and running it through the other like a train.
CIRCULAR CONVOLUTION:
We know that linear convolution of two finite length data sequence is done by assuming that the data is
zero outside the length in which it is defined[recall that linear convolution runs from to ].this need not
be the only valid assumption. For e.g. one can assume that the data is periodic outside the sequence length
in which it is defined. This is consistent with the definition of DFT.DFT is equivalent to discrete time
Fourier series and that all Fourier series assume periodicity. So this definition of convolution would be
more practical use since it implies with DFT definition. Therefore circular
Convolution is defined
n-1
m=0
PROCEDURE:
%linear convolution
clear all;
clc;
close all;
subplot (3,1,1);
stem (a);
subplot (3,1,2);
stem(b);
c=conv(a,b);
subplot (3,1,3);
stem (c);
%circular convolution
clear all;
clc;
close all;
a=length(x);
b=length(y);
n=a+b/2
%zero padding
if a~=b
if a<b
n=b;
x=[x,zeros(1,b-1)];
else
n=a;
y=[y,zeros(1,a-1)];
end
else
n=a;
end
%circular convolution
for i=1:n
z(i)=0;
for j=1:n
k=mod(i-j(n))+1;
z(i)=z(i)+[x(j)*y(k)];
end
end
subplot (3,1,1);
stem (x);
x label (n);
y label (x(n));
disp(sequence 1 :);x
subplot (3,1,2);
stem (y);
x label (n);
ylabel (y(n));
title(sequence 2);
disp(sequence 2 :);y
subplot(3,1,3);
stem (z);
x label (n);
y label (z(n));
title (output);
disp(output :);z
g.text(circular convolution);
RESULT:
Thus program to perform linear and circular convolution in MATLAB has been verified and processed.
4.SAMPLING AND EFFECT OF ALIASING
AIM:
The sample sine wave and plot it on the screen and study the effect of aliasing using MATLAB.
APPARATUS REQUIRED:
PC with MATLAB.
ALGORITHM:
STEP2: Design the value of the signal frequency of sine wave and the sampling frequency.
STEP3: Define the number of samples required and the time of simulation.
STEP4: Calculate the values of sine wave at each time using the appropriate formula.
STEP6: Increase the frequency of sine wave when fo > fs/2 so that aliasing takes place.
THEORY:
According to sampling theorem a band limited signal with highest frequency component of Wm must be
sampled (i.e.) Ws=2Wm is not satisfied, and then the signal will be aliased to another signal of linear
frequency this is known as aliasing.
PROCEDURE:
4. Note the output and plot the graph for the output.
PROGRAM:
clc;
clear all;
close all;
disp(aliasing);
fc1=50;
fc2=10;
t=0:(1/10)e2:0.1;
x1=sin(2*pi*fc1*t);
x2= sin(2*pi*fc2*t);
subplot (2,3,1);
plot(x1);
line ([0,200],[0,0]);
x label (time);
y label (amplitude);
subplot (2,3,4);
plot (x2);
line([0,100],[0,0]);
x label (time);
y label (amplitude);
fs=40;
n=0:1:15;
x3=sin(2*pi*fc1*n/fs);
x4=sin(2*pi*fc2*n/fs);
subplot (2,3,2);
stem(x3);
line ([0,15],[0,0]);
x label (time);
y label (amplitude);
subplot (2,3,5);
stem (x4);
line ([0,15],[0,0]);
x label (time);
y label (amplitude);
fs1=150
n=0:1:10
x5=sin (2*pi*fc1*n/fs1);
x6=sin(2*pi*fc2*n/fs1);
subplot (2,3,3);
stem (x5);
line([0,10],[0,0]);
x label (time);
y label (amplitude);
subplot(2,3,6);
stem (x6);
line ([0,10],[0,0]);
x label (time);
y label (amplitude);
Thus a sine wave is sampled and the effects of aliasing are studied.
5. DESIGN OF FIR FILTERS
AIM:
To write a MATLAB program for FIR filter using different window techniques for the given order and
sampling frequency.
APPARATUS REQUIRED:
PC with MATLAB
ALGORITHM:
STEP4: Input to the FIR filter is given as a sequence square wave & the output is computed using filter
command.
STEP5: Frequency response of the filter with various windows functions calculated using frequency.
THEORY:
FIR is the non-recursive filter that has the impulse response for finite number of n, n1 n n2 with n1
and n2 being finite. This filter is also known as convolution filter b0 and is all non-zero system.
In general, the unit sample response is of finite duration and must be truncated at some point to yield FIR
filter of finite length. This method is called as WINDOWING. Thus multiplying a window function in time
domain results in the convolution of Fourier transform of window with that of unit sample response, which
will be a sine function .In most of times, two criteria that has satisfied by the window functions are-
(i) The width of the main lobe should be small for the ripples to be small.
(ii) The height of the side lobe should be small for the ripples to be small.
PROCEDURE:
4. Note the output and plot the graph for the output.
PROGRAM:
% KAISER WINDOW
clc;
clear all;
close all;
subplot (2,2,1);
plot (b);
subplot (2,2,2);
plot (omega/pi,h);
subplot (2,2,3);
plot(m);
title(magnitude response);
subplot(2,2,4);
plot(ph);
title(phase response);
%RECTANGULAR WINDOW
clc;
clear all;
close all;
w=boxcar(n+1);
b=fir1(n,wc,w);
[h,omega]=freqz(b,1,256);
m=20*log(abs(h));
ph=angle(h*180/pi));
subplot(2,2,1);
plot(b);
title(filter response);
subplot(2,2,2);
plot(omega/pi,h);
title(frequency response);
subplot(2,2,3);
plot(m);
title(magnitude response);
subplot(2,2,4);
plot(ph);
title(phase response);
%BARLETT WINDOW
clc;
clear all;
close all;
w=barlett(n+1);
b=fir1(n,wc,w);
[h,omega]=freqz(b,1,256);
m=20*log(abs(h));
ph=angle(h*(180/pi));
subplot(2,2,1);
plot(b);
title(h(n));
subplot(2,2,2);
plot(omega/pi,h);
title(frequency response);
subplot(2,2,3);
plot(m);
title(magnitude response);
subplot(2,2,4);
plot(ph);
title(phase response);
%BLACKMAN WINDOW
clc;
clear all;
close all;
w=blackman(n+1);
b=fir1(n,wc,w);
[h,omega]=freqz(b,1,256);
m=20*log(abs(n));
ph=angle(h*(180/pi));
subplot(2,2,1);
plot(b);
title(h(n));
subplot(2,2,2);
plot(omega/pi,h);
title(frequency response);
subplot(2,2,3);
plot(m);
title(magnitude response);
subplot(2,2,4);
plot(ph);
title(phase response);
RESULT:
Thus the FIR filter was designed using window technique using MATLAB program for the given order and
cut off frequency.
6. CALCULATION OF FFT OF A SIGNAL
AIM:
APPARATUS REQUIRED:
PC with MATLAB
ALGORITHM:
THEORY:
The FFT is the faster version of the discrete Fourier transform (FFT).The FFT utilizes same algorithm to do
the same thing as DFT, but in much less time. The DFT is extremely imp in the area of frequency analytic
because it takes a discrete signal in time domain and transform that signal into it discrete frequency domain
representation. Without the discrete time, to discrete time freq transform, we could not be able to compute
FFT in DFT based system. It is the speed and discrete nature of the FFT that allows us to analyze the signal
spectrum with MATLAB.
PROCEDURE:
clc;
clear all;
close all;
N=length(x);
z= fft(x,n);
display(input);x
display(output);z
n=1:N;
subplot(3,2,1);
stem(n,x);
xlabel(sequence number);
ylabel(amplitude);
title(input sequence);
subplot(3,2,2);
stem(n,abs(z));
xlabel(sequence number);
ylabel(amplitude);
title(output amplitude);
subplot(3,2,3);
stem(b,real(z));
xlabel(sequence number);
ylabel(real);
subplot(3,2,4);
stem(n,imag(z));
xlabel(sequence number);
ylabel(imaginary);
subplot(3,2,5);
stem(n,(z));
xlabel(sequence number);
ylabel(phase);
title(output phase);
clc;
clear all;
close all;
N=length(x);
z= ifft(x,n);
display(input);x
display(output);z
n=1:N;
subplot(2,2,1);
stem(n,x);
xlabel(sequence number);
ylabel(amplitude);
title(input sequence);
subplot(2,2,2);
stem(n,z);
xlabel(sequence number);
ylabel(amplitude);
title(output sequence);
subplot(2,2,3);
stem(n,floor(real(acos(z))));
xlabel(sequence number);
ylabel(amp);
title(output sequence);
gtext(mnmjec);
RESULT:
Thus the program to perform linear combination and circular convolution using FFT has been processed
and verified successfully.
7. DESIGN OF IIR FILTERS
AIM:
To write MATLAB program for IIR filter for the given order and cut off frequency and stop band
frequency.
APPARATUS REQUIRED:
PC with MATLAB
ALGORITHM:
[b a]=butter (n, w0), n=order of filter and w0=normalized cut off frequency.
STEP4: Chebyshev filter can be designed using cheby1 and cheby2 command.
[b a]=cheby1(n,r,w0)
n=order of filter, r=pass band ripple and w0=normalized cut off frequency.
THEORY:
BUTTERWORTH FILTER:
Butterworth filter approximation concentrates on w=0 (i.e.) maximally flat response at origin.
Hn(w)=wn
|(jw)| =1/(1+c2w2n)
2
As the order of filter is increased the sharpness of cut off increase. The attenuation in pass band is xp(w)
=10log (1+c2).butter worth filter gives a fairly linear response. As order of chebyshev response becomes
higher, phase response become non-linear.
CHEBYSHEV FILTER:
Concentrates over range 0<w<1 rather than w=0.the same characteristics of Butterworth filter can be
achieved using a filter of lesser order. It has ripples in pass band and stop band.
4. Note the output and plot the graph for the output.
PROGRAM:
%CHEBYSHEV 1 FILTER
clc;
close all;
clear all;
subplot(2,2,2);
plot(m);grid
title(magnitude response);
subplot(2,2,1);
plot(omega/pi,h);grid
title(frequency response);
subplot(2,2,3);
plot(ph);grid
title(phase response);
gtext(chebychev1=IIR filter);
%CHEBYSHEV 2 FILTER
clc;
close all;
plot(omega/pi,h);grid
title(frequency response);
subplot(2,2,2);
plot(m);grid
title(magnitude response);
subplot(2,2,3);
plot(ph);grid
title(phase response);
%BUTTERWORTH FILTER
clc;
close all;
subplot(2,2,1);
title(frequency response);
subplot(2,2,2);
plot(m);grid
title(magnitude response);
subplot(2,2,3);
plot(ph);grid
title(phase response);
Thus the programs for IIR filter are designed successfully using MATLAB programs for the given order,
cut off frequency and stop band frequency.
8.STUDY OF TMS320C50 PROCESSOR
ARCHITECTURE:
In a strict Harvard architecture, program and data memory are in two separate spaces, permitting a full
overlap of instruction fetch end execution. The TMS320 familys modification of the Harvard architecture
allows transfer between program and data spaces, thereby increasing the flexibility of the device. The
modification permits coefficients stored in program memory to be read into data RAM, eliminating the
need for a separate coefficient ROM. It also makes available immediate instructions and subroutines based
on computed values.
The TMS320C50 contains a 32 bit ALU and accumulator for support of double- precision, twos
complements arithmetic. The ALU is a general purpose arithmetic unit that operates on 16 bit words
taken from the data RAM or derived from immediate instructions. The accumulator stores the output
from the ALU and is often an input to the ALU. Its word length is 32- bit. The accumulator is divided
into a high order word (bits 31 through 16) and a low order word (bits 15 through 0). Instructions are
provided for storing and loading the high and low order accumulator words to memory.
The multiplier performs a 16x16 bit twos complement multiplication with a 32-bit result in a single
instruction cycle .The multiplier consists of three units: theT-Register, P-Register, and multiplier array.
Multiplier values either come from the data memory or are derived immediately from the MPY (multiply
immediate) instruction word. The fast on-chip multiplier allows the device to perform fundamental
operation such as convolution, correlation and filtering. Two multiply /accumulator instructions in the
instruction set fully utilize the computational bandwidth of the multiplier, allowing both operands to be
processed simultaneously.
SHIFTERS:
A 16-bit scaling shifter is available at the accumulator input. This shifter produces a left shift of 0 to
16 bits on the input data to accumulator .in addition one shifter at the output of P-register, can shift the
product by 1or 4-bits left or 6-bits right, before transferring the product to accumulator.
Since the TMS320C50 use Harvard architecture, data and program memory reside in two separate
spacers. Additionally TMS320C50 has one more memory space called I/O memory space. The total
memory capacity of TMS320C50 is 64KW each of Program, Data and I/O memory. The 64KW of data
memory is divided into 512 pages with each page containing 128 words. Only one page can be active at a
time .TMS320C50 has 1056 words of dual access on chip data memory is divided as three blocks B0, B1,&
B2 of which B0 can be configured as program or data RAM.
The TMS320C50 has three external makeable user interrupts available for external devices that
interrupt the processor .the TMS320C50 contains an eight-level hardware stack for saving the contents of
the program counter during interrupts and subroutine calls.
SERIAL PORT:
A full-duplex on-chip serial port provides direct communication with serial devices such as codecs,
serial A/D converters and other serial systems. The interface signals are compatible with codecs and many
others serial devices with a minimum of external hardware.
The 16-bit parallel data bus can be utilized to perform I/O functions in two cycles. The I/O ports are
addressed by four LSBs on the address lines, allowing 16 input and 16 output ports. In addition, a polling
input for bit test and jump operation (BIO) and three interrupt pins (INT0-INT2) have been incorporated
for multitasking.
EXAMPLES OF ARITHMETIC OPERATIONS USING TMS320C50
PROGRAM:
ADDITION:
.MMREGS
.TEXT
LACC #1111H
ADD #2222H
SACL 0H
HLT: B HLT
SUBTRACTION:
.MMREGS
.TEXT
LACC #2222H
SUB #1111H
SACL 0H
HLT: B HLT
MULTIPLICATION:
.MMREGS
.TEXT
LACC #037AH,0
SACL 0000,0
LACC # 012EH,0
SACL 0001,0
LT 0000
MPY 0001
PAC
SACL 0002,0
SACH 0003,0
HLT: B HLT
RESULT:
Thus the architecture of TMS320C50 was studied with the simple programming examples
9. STUDY OF VARIOUS ADDRESSING MODES OF DSP USING SIMPLE
PROGRAMMING EXAMPLES
AIM:
To study the various addressing modes of DSP processor using simple programming
examples.
APPARATUS REQUIRED:
1. TMS320C5X
2. PC
3. RS232 CABLE
1. Direct addressing
3. Indirect addressing
4. Immediate addressing
6. Circular addressing
PROCEDURE:
.MMREGS
ENTRY
.LACC #1000H
.LACC #1111H,3
LAR AR0,#1000H
LAR AR1,#1100H
ADD #00FFH
ADD #0011H,2
SPLK #10H,0
MPY #0010H
SUB #0022H
SUB #0011H,3
.END
.MMREGS
.ENTRY
LDP #20H
LACC 10H
LACC 5H,2
LDP #22H
LAR AR0,15H
SACL 15H
SACL 20H,3
SAMM AR7
LDP # 12H
ADD 25H
ADD 7H,2
SUB 10H
SUB 12H,2
SPLK #10H,0
MPY 15H
.END
.MMREGS
.PS0A00H
.ENTRY
LAR AR0,#1000H
LACC*
LACC*,4,AR1
LAR AR1,#1010H
SACL*,
SACL*+,2,AR0
LACC*-,2,AR1
LACC*0+
LACC*BR0+
ADD*+,0,AR0
SUB*-,2
SPLK #10H,0
MPY*
.END
.MMREGS
.PS0A00H
.ENTRY
SPLK #1000H,0
SPLK #1003H,1
SPLK #08H,2
LACC*+
LACC*+
LACC*+
LACC*+
.END
RESULT:
Thus the various addressing modes of DSP processor using simple programming
examples are studied and verified.
10. SAMPLING OF INPUT SIGNAL AND DISPLAY
AIM:
To write a program to sample and display an analog signal using TMS320C50 KIT.
APPARATUS REQUIRED:
1. TMS320C5X
2. PC
3. RS232 CABLE
PROCEDURE:
PROGRAM:
DATA .SET 2H
DELAY .SET3H
.MMREGS
.TEXT
START: LDP#100H
LAR AR0,#9000H
LAR AR1,#719H
REP: IN 0,06
RPT #OFH
NOP
IN 0,04
SPLK #00FFH,DELAY
RPT DELAY
NOP
LACC 0
AND #0FFFH
MAR*,AR0
SACL*+,0,AR1
BANZ REP,*-
LAR AR1,#719H
LOOP:MAR*,AR0
RPT #1FFH
NOP
OUT*+,04,AR1
BANZ LOOP,*-
B CONT1
RESULT:
AIM:
To implement a low pass FIR filter using rectangular window using TMS320C50.
APPARATUS REQUIRED:
1. TMS320C5X
2. PC
3. RS232 CABLE
PROCEDURE:
PROGRAM:
.MMREGS
.TEXT
B START
CTABLE:
.WORD 0FFF4H
.WORD 0FFE3H
.WORD 0FFCFH
. WORD 0FEBBH
. WORD 0FFA7H
. WORD 0FF97H
.WORD 0FF8EH
. WORD 0FF8FH
. WORD 0FF9BH
. WORD 0FFB7H
. WORD 0FFE3H
. WORD 022H
. WORD 075H
. WORD 0DCH
. WORD 0157H
. WORD 01E5H
. WORD 0283H
. WORD 032FH
. WORD 03E5H
. WORD 04A0H
. WORD 055CH
. WORD 0614H
. WORD 06C2H
.WORD 0761H
. WORD 076BH
.WORD 085BH
.WORD 085BH
. WORD 07EBH
. WORD 07E1H
. WORD 06C2H
. WORD 0614H
. WORD 055CH
. WORD 04A0H
. WORD 03E5H
. WORD 032FH
. WORD 0283H
. WORD 01E5H
. WORD 0157H
. WORD 0DCH
. WORD 075H
. WORD 022H
. WORD 0FFE3H
. WORD 0FFB7H
. WORD 0FF9BH
. WORD 0FF8FH
. WORD 0FF8EH
. WORD 0FF97H
. WORD 0FFA7H
. WORD 0FFBBH
. WORD 0FFCFH
. WORD 0FFE3H
. WORD 0FFF4H
START: MAR*,AR0
LAR AR0,#0200H
RPT #33H
BLKP CTABLE,*+
SETC CNF
LACC #0
SACL 0
OUT 0,05
IN 0,06H
LAR AR7,#0
MAR*,AR7
BACK:
BANZ BACK,*-
IN 0,4
NOP
NOP
NOP
NOP
MAR*,AR1
LAR AR1,#0300H
LACC0
AND #0FFFH
SUB #800H
SACL*
LAR AR1,#333H
MPY #0
ZAC
RPT #33H
MACD 0FF00H,*-
APAC
LAR AR1,#0300H
SACH*
LACC*
ADD #800H
SFR
SACL*
OUT*,4
LACC #0FFH
SACL 0
OUT0,05
NOP
B ISR
HLT: B HLT
RESULT :
Thus the FIR filter was designed using TMS320C50 DSP Kit.
To perform DIT fast Fourier transform for 4 point sequence using TMS320C50 processor.
APPARATUS REQUIRED:
1. TMS320C50
2. PC
3. RS232 CABLE
ALGORITHM:
STEP5: Store the real part of output and imaginary part of output.
PROCEDURE:
PROGRAM:
IN.SET 8010H
.MMREGS
.TEXT
LAR AR2,#BITREV
SPLR #2H,05H
LMMR INDX,#8005H
MAR*,AR2
RPT #3H
BLDD #IN,*BR0+
FFT1: MAR*,AR2
LACC*+
SACB
LT*+
MPY #1H
APAC
MAR*,AR3
SACL*+
LACB
SPAC
SACL*+,AR0
BANZ FFT1,*-
LAR AR3,#8030H
LAR AR4,#REAL
LAR AR5,#IMG
MAR*,AR3
LACC*
SACB
ADRK#2H
LT*-
MPY #1H
APAC
MAR*,AR4
SACL*
ADRK #2H
LACC #0H
MAR*,AR5
SACL*
ADRK #2H
LACB
SPAC
MAR*,AR4
SACL*-
LACC #0H
MAR*,AR5
SACL*-,AR3
LACL*,AR4
SACL*,AR3
ADRK #2H
LT*
MPY #0FFFFH
MAR*,AR5
SPL8,AR3
LT*
MPY #1H
MAR*,AR5
ADRK #2H
SPL*
HLT: B HLT
INPUTS: OUTPUTS:
RESULT:
Thus the FFT of the inputs were performed successfully using DSP processor.