19
Jawaharlal Nehru Engineering College Laboratory Manual DIGITAL SIGNAL PROCESSING For Third Year Students Author JNEC, Aurangabad

Digital Signal Processing

Embed Size (px)

DESCRIPTION

manual

Citation preview

Page 1: Digital Signal Processing

Jawaharlal Nehru Engineering College

Laboratory Manual

DIGITAL SIGNAL PROCESSING

For

Third Year Students

Author JNEC, Aurangabad

Page 2: Digital Signal Processing

PREFACE

It is my great pleasure to present interactive Digital Signal Processing (DSP) Demonstration modules developed using Matlab for Third year Electronics Engineering students.

DSP deals with the analysis and manipulation of digital signals. The main difficulty in DSP learning for a novice, is a large no. of mathematical equations that needs some intuition to appreciate underlying concepts.

Matlab is the best visualization tool, that accentuate the intuitive aspects of DSP Algorithms. Hence, this manual consists of a ready to use set of demonstrations, illustrating the DSP concepts, that can be beneficial to the students . Students are advised to thoroughly go through this manual rather than only topics mentioned in the syllabus as practical aspects are the key to understanding and conceptual visualization of theoretical aspects covered in the books.

Good Luck for your Enjoyable Laboratory Sessions.

Prof. A. P. Phatale.

Page 3: Digital Signal Processing

SUBJECT INDEX

Title Page no.

1.Do‛s and Don‛ts in Laboratory

2 .Instruction for Laboratory Teachers:

3. Lab Exercises

1. Introduction to matlab 2. Generation of signal 3. To verify the partial fraction expansion of the z-

transform. 4. To verify impulse response. 5. 6. Design of IIR Filter 7. Illustration of interpolation process. 8. Illustration of decimal process 9. Spectral analysis using DFT.

4. Quiz for the subject

5. Conduction of viva voce examination

6. Evaluation and marking scheme

04

04

05 08

Page 4: Digital Signal Processing

1. DOs and DON‛Ts in Laboratory:

1. Do not handle DSP Starter kit without reading the instructions/Instruction manuals. 2. Refer Matlab Help for debugging the program. 3. Go through Matlab Demos of Signal Processing tool box. 4. Strictly observe the instructions given by the teacher/Lab Instructor. .

2 Instruction for Laboratory Teachers::

1. Lab work completed during prior session ,should be corrected during the next lab session.

2. Students should be guided and helped whenever they face difficulties.

3. The promptness of submission should be encouraged by way of marking and evaluation patterns that will benefit the sincere students.

Page 5: Digital Signal Processing

3. Lab Exercises:

Exercise No1: ( 2 Hours) – 1 Practical

Aim: Generation of discrete time signal like a) sinusoidal b) step c) ramp d) impulse e) real valued f) complex valued g) noise

These are the basic discrete signals used in DSP. Plot all the signals .

Step: 1. Generate Sinusoidal signal Discrete sinusoidal signal is represented by the equation x(n) = A Sin ( 2 Π f n) for all n

fs

A = peak amplitude f = signal frequency fs= sampling frequency n = n th sample

function[x,n]=sinusoidal(n1,n2) n=0:100; x=5*sin(2*0.05*pi*n)+ sin(0.01*pi*n); stem(n,x); title ('Sinusoidal sequence'); xlabel ('samples'); ylabel ('magnitude');

Step: 2. Generate Step signal

Discrete step signal is represented by the equation x(n) = 1 for all n>0

= 0 otherwise

function[x,n]=step seq(n0,n1,n2) n=­5:10; x=[(n­4)>=0]; stem(n,x); title('unit step sequence delayed by four samples'); xlabel('samples'); ylabel('step sequence');

Page 6: Digital Signal Processing

Step: 3. Generate ramp signal

Discrete ramp signal is represented by the equation x(n) = n for all n>0

= 0 otherwise

function[x,n]=rampseq(n0,n1) n=0:10; x=n; stem(n,x); title('unit ramp sequence delayed by four samples'); xlabel('samples'); ylabel('ramp sequence');

Steps: 4. Generate complex valued signal

Discrete complex valued signal is represented by the equation x(n) = exp(a+jb) n for all n>0

function[x,n]=compexp(n1,n2) n=­10:50; x=[exp((­0.2+i*2)*n)]; stem(n,x); title('Complex valued exponential sequence'); xlabel('samples'); ylabel('complex valued exponential sequence');

Steps: 5. Generate real valued signal

Discrete real valued signal is represented by the equation x(n) = exp(a) n for all n>0

a<1

function[x,n]=realseq(n1,n2) n=1:10; x(n)=(0.9).^n; stem(n,x); title('Real valued sequence'); xlabel('samples'); ylabel('impulse sequence');

Page 7: Digital Signal Processing

Steps: 5. Generate impulse signal Discrete impulse signal is represented by the equation

x(n) = 1 for all n=0 = 0 otherwise

x=2*impseq(5,0,20); y=3*impseq(1,0,20); a=x+y; stem(a); title('unit impulse sequence '); xlabel('samples'); ylabel('impulse sequence');

Steps: 6. Generate noise signal

n=50; x=rand(n,1); % generate the uncorrupted signal m=0:1:n­1; s=2*m.*(0.9.^m); subplot(2,1,1); stem(m,s); title('Uncorrupted sequence'); xlabel('Time index'); ylabel('Amplitude'); subplot(2,1,2); stem(m,x); title('Noise'); xlabel('Time index'); ylabel('Amplitude');

Page 8: Digital Signal Processing

Exercise No 2 : ( 2 Hours) – 1 Practical

Aim: Verification of Convolution Theorem The input sequence is denoted by x(n) and impulse response h(n) are convoluted and the resultant signal is obtained .This technique illustrates how a filter can be implemented in time domain . The convolution is given by

∞ Y(k) = ∑ x(k) . h(n­k) for all k

n=­∞

Implement the equation on 4_ point (or variety) x(n) & h(n) and display y(n).

%Illustration of convolution x=input('type the input sequence'); h=input('type the impulse response'); y=conv(x,h); m=length(y)­1; n=0:1:m; disp('output sequence'); disp(y); stem(n,y) xlabel('Time index'); ylabel('Amplitude');

Another sample program for convolution where in time reference is also displayed.

%Illustration of convolution nx=[­1:2]; x=input('type the input sequence'); nh=[1:4]; h=input('type the impulse response'); nyb=nx(1)+nh(1); nye=nx(length(x))+nh(length(h)); ny=[nyb:nye]; y=conv(x,h); disp(y); stem(ny,y) xlabel('Time index'); ylabel('Amplitude');

Page 9: Digital Signal Processing

Exercise No 3 : ( 2 Hours) – 1 Practical

Aim: Verification of Auto Correlation and Cross correlation

The cross correlation is given by ∞

Rxy(k) = ∑ x(n) . y(n­k) n=­∞

The auto correlation is given by ∞

Rxy(k) = ∑ x(n) . y(n­k) n=­∞

%computation of cross correlation sequence x=input('type in the reference sequence='); y=input('type in the second sequence='); %compute the correlation sequence n1= length(y)­1; n2= length(x)­1; r=xcorr(x,y);% here the length of x= length of y %r=conv(x,fliplr(y)); %k=(­n1):n2'; stem(r);

%computation of auto correlation of a sequence x=input('type in the reference sequence='); %compute the correlation sequence %r=xcorr(x); r=conv(x,fliplr(x)); stem(r);

Page 10: Digital Signal Processing

Exercise No 4 : ( 2 Hours) – 1 Practical

Aim: Verification of Discrete Fourier Transform

The discrete fourier transform is given by

N­1 X(k) = Σ x(n) exp (­j*2*pi*n/N) k=0,1,…N­1

n=0

for any arbitrary 8_point sequence x(n) of length N plot the frequency response and phase response.

%Illustration of DFT computation %we determine Mpoint DFT of N point u[n]=1 0<=n<=N­1 else 0 %N be the length of the sequence and %M­point dft is calculated N=input('type the length of the sequence '); M=input('type the length of the DFT= '); u=[ones(1,N)]; U=fft(u,M); t=0:1:N­1; stem(t,u); title('Original time domain sequence') xlabel('n') ylabel('amplitude') pause subplot(2,1,1) k=0:1:M­1; stem(k,abs(U)) title('Magnitude of DFT samples') xlabel('frequency index k') ylabel('magnitude') subplot(2,1,2) k=0:1:M­1; stem(k,angle(U)) title('Phase of DFT samples') xlabel('frequency index k') ylabel('phase')

Page 11: Digital Signal Processing

Exercise No 5 : ( 2 Hours) – 1 Practical

Aim: Design of Infinite Impulse Filter

An IIR filter is represented by the equation

Y(n) = ­Σak y(n­k) + Σbk x (n­k )

For N=7 , F1= 500Hz , δ1=­3db ,F2=1000Hz , δ2=40 db Design h(n) either by Butterworth or by Chebyshev method and plot in frequency domain the response of the filter.

%program to design type 1 Chebyshev lowpass filter N=input('type filter order'); fp=input('passband edge frequency in hz= '); Rp=input('passband ripple in db= '); %Determine coefficients of the transfer function [num,den]= cheby1(N,Rp,fp,'s'); %Compute and plot the frequency response omega=[0:200:12000*pi]; h=freqs(num,den,omega); plot(omega/(2*pi),20*log10(abs(h))); xlabel('freq. in Hz'); ylabel('Gain in db');

%program to design Butterworth low pass filter N=input('type filter order'); wn=input('3 db cut off frequency'); [num,den]= butter(N,wn,'s'); omega=[0:200:12000*pi]; h=freqs(num,den,omega); plot(omega/(2*pi),20*log10(abs(h))); xlabel('freq. in Hz'); ylabel('Gain in db');

Page 12: Digital Signal Processing

Exercise No 6 : ( 2 Hours) – 1 Practical

Aim: Design of Finite Impulse Filter.

A FIR filter is represented by the equation

Y(n) = Σbk x (n­k )

Design h(n) by implementing all windowing method. Also apply these response on a signal and observe the filtered output.

%program to design fir by windowing method implementing Bartlett ,Hamming , Blackman window

wp=0.2*pi; ws=0.3*pi; tr_width=ws­wp; M=ceil(6.6*pi/tr_width)+1; n=0:1:M­1; wc=(wp+ws)/2 % ideal LPF cutoff frequency hd=ideal_lp(wc,M); %w_ham=(blackman(M))'; %w_ham=(hamming(M))'; w_ham=(bartlett(M))'; h=hd.*w_ham; [db,mag,pha,grd,w]=freqz_m(h,[1]); delta_w=2*pi/1000; rp=­(min(db(1:1:wp/delta_w+1))); As=­round(max(db(ws/delta_w+1:1:501))) subplot(1,1,1) subplot(2,1,1);stem(n,hd);title('ideal impulse response'); axis([0 M­1 ­0.1 0.3]);xlabel('n');ylabel('hd(n)') subplot(2,2,2);stem(n,w_ham);title('Hamming Window'); axis([0 M­1 0 1.1]);xlabel('n');ylabel('w(n)') subplot(2,2,3);stem(n,h);title('Actual Impulse Response'); axis([0 M­1 ­0.1 0.3]);xlabel('n');ylabel('h(n)') subplot(2,2,4);plot(w/pi,db);title('Magnitude response in db'); axis([0 1 ­100 10]); xlabel('frequency in pi units'); ylabel('Decibels');

Page 13: Digital Signal Processing

Exercise No 7 : ( 2 Hours) – 1 Practical

Aim: Study of DSP Starter Kit

Theory: TMS 32054X DSP Starter Kit has the following ADVANTAGES and KEY FEATURES:

• Enhanced harvard architecture built around one program bus, three data buses and four address buses for increased performance and versatility.

• Adavnced CPU design with a high degree of parallelism and application specific hardware logic for increased performance.

• A highly specialized instruction set for faster algorithm and for optimized high level language operation.

• Modular architectural design for fast development of spin off devices. • Advanced IC processing technology for increased performance and low power consumption. • Low power consumption and increased radiation hardness because of new static design

techniques. CPU: • 40 bit ALU including 40 bit Barrel shifter and two independent 40 bit accumulators. • 17bit X17bit parallel multiplier coupled to a 40 bit dedicated adder for nonpipelined single cycle

multiply/accumulate operation. • Compare ,select, store (CSS)unit for add/compare selection of Viterbi operation. • Exponent encoder to compute the exponent of a 40 bit value in a single cycle. • Two address generators including 8 Auxiliary registers and two auxiliary register arithmetic units. • Dual CPU. MEMORY: • 192 K words by 16 bits addressable memory space. INSTRUCTION SET: • Single instruction repeat and block repeat operations. • Block memory move instructions for better program and data management. • Instructions with a 32 bit long operand. • Instructions with two or three operand simultaneous reads. • Arithmetic instructions with parallel store and parallel load . • Conditional store instruction . • Fast return from interrupt. ON CHIP PERIPHERALS: • Software programmable wait state generator. • Programmable bank switching module. • On chip PLL clock generator . • Programmable timer. • 8 bit enhanced Host port interface. • Multichannel buffered serial port.

Page 14: Digital Signal Processing

Exercise No 8 : ( 2 Hours) – 1 Practical

Aim: Generation of sine wave

Algorithm : 1. Store the value 2 cos(Θ) in a memory. 2. Initialize the value of n . 3. According to the values of n and Θ ,store the initial values of sin[(n­1)Θ] and

Sin[(n­2) Θ] in memory locations A and B respectively . 4. Calculate the value of recursive expression for sine using values in

Memory locations A,B and 2 cos(Θ) and display it. 5. Store the value of sin[(n­1) Θ] in the memory location B. 6. Store the new value of sine in memory location A. 7. Increment n by one. 8. Repeat the steps 4­7.

Procedure : 1. Switch on the DSP board. 2. Open the Code Composer studio. 3. Create a new project from the pull down menu named ‘Project’.

From this pull down menu select ‘New’ and write the name of the File and click ‘open’.

4. After the new file is named , pull down the ‘Project ‘ menu again add all the files sin.c and common.cmd using the option ‘Add files to the project ….’

5. Save the files using proper menu. 6. Connect the speaker jack to the input of the CRO. 7. Build the program . After the program is build the program is automatically

Loaded using the cmd file 8. Run the Program 9. The waveform appears on the screen.

Code for the Non real Time Implementation of Sine wave Generation:

# include <stdio.h> # include <math.h> # include <volume.h>

# define PI 3.1416 # define STEP 2000

int inp_buffer [BUFSIZE]; int out_buffer [BUFSIZE ];

int predict = 0 ; float ar0,ar1,ar2;

Page 15: Digital Signal Processing

float step (PI/180)*6; unsigned int processing load = BASELOAD extern void load(unsigned int load value); static int processing (int*input,int*output); static void dataIO (void);

void main()

int*input =& inp_buffer[0]; int*output= &out_buffer[0];

puts (“volume example started\n”);

/*initialization of Taylor series*/

ar0=cos(step); ar1=sin(­step); ar2=sin(­(2*step));

while (TRUE)

dataIO(); processing(input,output);

Static int processing(int*input,int*output)

int size = BUFSIZE; int data; int error; int delta=2500; float value;

while (size­­)

value = (2*ar0*ar1)­ar2; data = value*16000; ar2 = ar1; ar1 = value; *input++ =data;

Page 16: Digital Signal Processing

error =data­predict;

if(error>0)

predict=delta; else

if(error<0) prdict = delta;

*output++=predict;

load(processing load); return TRUE;

static void dataIO();

return;

Page 17: Digital Signal Processing

4. Quiz on the subject:

1).­­­­­­­­Signals are the signals repeating after specific period.

a] Energy b] Digital c] Periodic

2) The system is said to be ­­­­­­­ or to have memory.

a] Dynamic b] Recursive c] Stable

3) If y(n) = nx(n) then the system is

a] Causual b] Recursive c] dynamic

4) If the signal is infinite duration and both sided then its ROC is

a] an annular ring b] entire z plane except z=0 c] entire z plane except z=∞

5) If the sequence is real and even then the DFT consists of

a] real and even parts b] purely imaginary parts

Page 18: Digital Signal Processing

5. Conduction of Viva­Voce Examinations:

Questions to be prepared for viva voce examinations

1. Define Discrete time Signal . 2. State the advantages of Digital Signal Processing. 3. What do you mean by aliasing? How to overcome? 4. Define LTI system. 5. What is the significance of convolution. 6. State the applications of autocorrelation and cross correlation. 7. Compare IIR with FIR filters. 8.What are linear phase filters ? 9. List different applications of DSP. 10.Explain architectural overview of TMS 3205402 DSK.

6. Evaluation and marking system:

As per JNEC format/University marking scheme.

Page 19: Digital Signal Processing