Dsp Manual

55
Department of ECE EC2306 Digital Signal Processing Lab LAB MANUAL VEL TECH HIGH TECH Dr.RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE ( ISO 9001: 2000 Certified Institution & NBA Accredited ) (Owned by VEL Sree R.Rangarajan Dr. Sagunthala Rangarajan Educational Academy) Approved by AICTE, New Delhi & Affiliated to Anna University No 42, Alamathi Road, Near Avadi Chennai – 600 062 DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING 1

description

DSP ece 5th sem lab manual

Transcript of Dsp Manual

Page 1: Dsp Manual

Department of ECE EC2306 Digital Signal Processing Lab

LAB MANUAL

VEL TECH HIGH TECH Dr.RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE

( ISO 9001: 2000 Certified Institution & NBA Accredited )(Owned by VEL Sree R.Rangarajan Dr. Sagunthala Rangarajan

Educational Academy)Approved by AICTE, New Delhi & Affiliated to Anna University

No 42, Alamathi Road, Near Avadi Chennai – 600 062

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

EC2306 - DIGITAL SIGNAL PROCESSING LAB

III YEAR V SEM ECE

1

Page 2: Dsp Manual

Department of ECE EC2306 Digital Signal Processing LabPrepared By HOD/ECE

FACULTY OF INFORMATION AND COMMUNICATION ENGINEERING

V SEMESTER B. E. – ELECTRONICS AND COMMUNICATION ENGINEERING

(R 2008)

EC2306 – DIGITAL SIGNAL PROCESSING LABORATORY

REQUIREMENT FOR A BATCH OF 30 STUDENTS

S.No. Description of EquipmentQuantity required

Quantity available

Deficiency %

1.PCs with Fixed / Floating point DSP

Processors (Kit / Add-on Cards)

15 Units (2 students per system)

2.List of software required:

MATLAB with Simulink and Signal Processing Tool Box

10 Users license

3. Function Generators (1MHz) 15

4. CRO (20MHz) 15

2

Page 3: Dsp Manual

Department of ECE EC2306 Digital Signal Processing Lab

EC2306 - DIGITAL SIGNAL PROCESSING LAB

AIM

To introduce the student to various digital Signal Processing techniques using TMS 320c5x family

processors and MATLAB.

OBJECTIVES

To implement the processing techniques using the instructions of TMS320C5X/TMS320C

67XX/ADSP 218X/219X/BS531/532/561

To implement the IIR and FIR filter using MATLAB.

LIST OF EXPERIMENTS

USING TMS320C5X/TMS320C 67XX/ADSP 218X/219X/BS531/532/561

1. Study of various addressing modes of DSP using simple programming examples

2. Implementation of Linear and Circular Convolution

3. Sampling of input signal and display

4. Waveform generation

5. Implementation of FIR filter

USING MATLAB

1. Generation of Signals

2. Linear and circular convolution of two sequences

3. Sampling and effect of aliasing

4. Design of FIR filters

5. Design of IIR filters

6. Calculation of FFT of a signal

7. Decimation by polyphase decomposition.

3

Page 4: Dsp Manual

Department of ECE EC2306 Digital Signal Processing Lab

S.NO NAME OF THE EXPERIMENT PAGE NO

USING MATLAB

1. Generation of Signals. 5

2. Linear and circular convolution of two sequences. 10

3. Sampling and effect of aliasing. 13

4. Design of Butterworth / Chebyshev IIR filters. 16

5 Design of FIR filters. 20

6. Calculation of FFT of a signal. 22

7. Decimation by polyphase decomposition. 24

USING TMS320C5X

8.STUDY OF VARIOUS ADDRESSING OF DSP USING SIMPLE

PROGRAMMING EXAMPLES.27-29

9. WAVEFORM GENERATION

1. Generation of square wave by using TMS320C50. 27

2. Generation of saw tooth wave by using TMS320C50. 28

3. Generation of Triangular wave by using TMS320C50. 29

10. Perform linear and circular convolution of two sequences. 30

11. Sampling of input signal and display 35

12. Implementation of FIR filters. 40

4

Page 5: Dsp Manual

Department of ECE EC2306 Digital Signal Processing Lab

GENERATION OF INPUT SIGNALSAIM To generate a continuous time signal (Unit Step , Unit Ramp, Sine, Cosine, Square, and Saw tooth ) and

discrete time signal (Unit Step , Unit Ramp, Sine, Cosine, Exponential and Unit impulse) using

MATLAB function.

ALGORITHM 1. Get the length of different input sequence. 2. To plot the different input sequence.

A) PROGRAM FOR CONTINUOUS TIME SIGNALS%program for unit step signalclc;t=0:1:10;y=ones(1,11);subplot(3,2,1);plot(t,y,'k');xlabel('Time');ylabel('Amplitude');title('Unit Step Signal');

%Program for unit ramp signalt1=0:1:10;y1=t1;subplot(3,2,2);plot(t1,y1,'k');xlabel('Time');ylabel('Amplitude');title('Unit Ramp Signal');

%Program for sine wavet=0:0.1:10;y=sin(2*pi*t);subplot(3,2,3);plot(t,y,'k');xlabel('Time');ylabel('Amplitude');title('Sine wave');

%Program for cosine wavet=0:0.1:10;y=cos(2*pi*t);subplot(3,2,4);plot(t,y,'k');xlabel('Time');

5

Page 6: Dsp Manual

Department of ECE EC2306 Digital Signal Processing Lab

ylabel('Amplitude');title('Cosine wave');

%Program for square wavet=0:0.001:10;y=square(t);subplot(3,2,5);plot(t,y,'k');xlabel('Time');ylabel('Amplitude');title('Square wave');

%Program for sawtooth wavet=0:0.1:10;y=sawtooth(t);subplot(3,2,6);plot(t,y,'k');xlabel('Time');ylabel('Amplitude');title('Sawtooth wave');

%program for impulse wavet=-3:1:3;y=[zeros(1,3),ones(1,1),zeros(1,3)];subplot(3,2,7);plot (n,y,'k');xlabel('Time');ylabel('Amplitude');title('Unit impulse');

%Program for exponential sequenceN=input('Enter the length of the exponential sequence(N)= ');n=0:1:N-1;a=input('Enter the value of the exponential sequence(a)= ');y=exp(a*n);subplot(3,2,1);plot (n,y,'k');xlabel('Time');ylabel('Amplitude');title('Exponential sequence');

OUTPUT RESPONSE

6

Page 7: Dsp Manual

Department of ECE EC2306 Digital Signal Processing Lab

B) PROGRAM FOR DISCRETE TIME SIGNALS%Program for unit step sequenceclc;N=input('Enter the lenght of unit step sequence(N)= ');n=0:1:N-1;y=ones(1,N);subplot(3,2,1);stem(n,y,'k');xlabel('Time')ylabel('Amplitude')title('Unit step sequence');

%Program for unit ramp sequenceN1=input('Enter the length of unit ramp sequence(N1)= ');n1=0:1:N1-1;y1=n1;subplot(3,2,2);stem(n1,y1,'k');xlabel('Time');ylabel('Amplitude');title('Unit ramp sequence');

7

Page 8: Dsp Manual

Department of ECE EC2306 Digital Signal Processing Lab%Program for sinusoidal sequenceN2=input('Enter the length of sinusoidal sequence(N2)= ');n2=0:0.1:N2-1;y2=sin(2*pi*n2);subplot(3,2,3);stem(n2,y2,'k');xlabel('Time');ylabel('Amplitude');title('Sinusoidal sequence');

%Program for cosine sequenceN3=input('Enter the length of the cosine sequence(N3)= ');n3=0:0.1:N3-1;y3=cos(2*pi*n3);subplot(3,2,4);stem(n3,y3,'k');xlabel('Time');ylabel('Amplitude');title('Cosine sequence');

%Program for exponential sequenceN4=input('Enter the length of the exponential sequence(N4)= ');n4=0:1:N4-1;a=input('Enter the value of the exponential sequence(a)= ');y4=exp(a*n4);subplot(3,2,5);stem(n4,y4,'k');xlabel('Time');ylabel('Amplitude');title('Exponential sequence');

%Program for unit impulsen=-3:1:3;y=[zeros(1,3),ones(1,1),zeros(1,3)];subplot(3,2,6);stem(n,y,'k');xlabel('Time');ylabel('Amplitude');title('Unit impulse');

INPUT DATAEnter the lenght of unit step sequence(N)= 10Enter the length of unit ramp sequence(N1)= 10Enter the length of sinusoidal sequence(N2)= 2Enter the length of the cosine sequence(N3)= 2Enter the length of the exponential sequence(N4)= 10Enter the value of the exponential sequence(a)= 0.5

8

Page 9: Dsp Manual

Department of ECE EC2306 Digital Signal Processing Lab

OUTPUT RESPONSE

9

Page 10: Dsp Manual

Department of ECE EC2306 Digital Signal Processing Lab

RESULT

Thus the continuous time signal and discrete time signal using MATLAB program was generated.

PERFORM LINEAR AND CIRCULAR CONVOLUTION OF TWO SEQUENCES

AIM To perform Linear and Circular convolution of the two sequences using MATLAB function.

ALGORITHM 1. Get the two sequence x(n) and h(n) in matrix form. 2. The convolution of the two sequences is given by

; For Linear Convolution

; For Linear Convolution

3. Stop the program.

PROGRAM A) PROGRAM FOR LINEAR CONVOLUTION%Program for linear convolution%input sequenceclc;x=input('Enter the input sequence x(n)= ');N1=length(x);n=0:1:(N1-1);subplot(3,1,1);stem(n,x,'k');xlabel('n----->');ylabel('Amplitude');

10

Page 11: Dsp Manual

Department of ECE EC2306 Digital Signal Processing Labtitle('input sequence x(n)');

%impulse sequenceh=input('Enter the impulse sequence h(n)= ');N2=length(h);n1=0:1:(N2-1);subplot(3,1,2);stem(n1,h,'k');xlabel('n----->');ylabel('Amplitude');title('Impulse sequence h(n)');%Output Convolutiony=conv(x,h)n2=0:1:(N1+N2-2);subplot(3,1,3)stem(n2,y,'k');xlabel('n----->');ylabel('Amplitude');title('Linear convolution of two sequences');

INPUT SEQUENCEEnter the input sequence x(n)= [1 2 3 4]Enter the impulse sequence h(n)= [4 3 2 1]

y =

4 11 20 30 20 11 4

OUPUT RESPONSE

11

Page 12: Dsp Manual

Department of ECE EC2306 Digital Signal Processing Lab

B) PROGRAM FOR CIRCULAR CONVOLUTION%Program for circular convolution%FIRST SEQUENCEclc;x1=input('Enter the first input sequence x1(n)= ');N1=length(x1);%SECOND SEQUENCE

x2=input('Enter the second input sequence x2(n)= ');N2=length(x2);

N=max(N1,N2);N3=N1-N2;

%LOOP FOR GETTING EQUAL LENGTH SEQUENCEif(N3==0) x1=[x1,zeros(1,N3)] x2=[x2,zeros(1,N3)]endif(N1>N2) x2=[x2,zeros(1,N3)]endif(N1<N2) x1=[x1,zeros(1,-N3)]

12

Page 13: Dsp Manual

Department of ECE EC2306 Digital Signal Processing Labend

%CIRCULAR CONVOLUTIONdisp('The output of circular convolution is')for m=1:N %This 'for' loop is for circular shifting sum=0; for k=1:N %This 'for' loop is for summation if((m-k)>=0) %This 'if' loop is for circular folding n=m-k+1; else n=m-k+N+1; end sum=sum+x1(k)*x2(n); end disp(sum) %display the result of circular convolutionend

INPUT AND OUTPUT SEQUENCEEnter the first input sequence x1(n)= [1 -1 2 3]Enter the second input sequence x2(n)= [0 1 2]

x2 =

0 1 2 0

The output of circular convolution is 7

7

1

0RESULT

Thus the Linear and Circular convolution of the two sequences using MATLAB program was performed.

SAMPLING AND EFFECT OF ALIASING.

AIM To study the effect of sampling on the frequency domain quantities at different sampling frequencies.

a) Sample at samples/sec to obtain .Determine and plot .

b) Sample at samples/sec to obtain .Determine and plot .

ALGORITHM1. Determine the analog value with respect to variation of time.

13

Page 14: Dsp Manual

Department of ECE EC2306 Digital Signal Processing Lab2. Get the sampling frequency.3. Determine the discrete value with respect to variation of frequency.4. Determine the Omega range from to .5. Determine the magnitude of the signal.6. Draw the discrete time signal and discrete Fourier transform.

PROGRAMSAMPLING AND EFFECT OF ALIASINGclc;%Analog signalt=-0.005:0.00005:0.005;xa=exp(-1000*abs(t));

%Discrete time signalFs=input('Enter the sampling frequency(Fs)= ');Ts=1/Fs;n=-25:1:25;xn=exp(-1000*abs(n*Ts));

%Discrete time fourier transformN=500;k=0:1:N;w=(2*pi*k/N);X=xn*exp(-j*n'*w);X=abs(X);

%omega range from -Wmax to WmaxW=[-fliplr(w),w(2:N+1)];

%X over -Wmax to Wmax intervalX=[fliplr(X),X(2:N+1)];

subplot(2,1,1);plot(t*1000,xa,'k');grid;hold on;

stem(n*Ts*1000,xn,'k');xlabel('time in sec');

ylabel('x(n)');title('discrete time signal');gtext('Ts=1msec');hold off;

subplot(2,1,2);plot(W/pi,X,'k');

14

Page 15: Dsp Manual

Department of ECE EC2306 Digital Signal Processing Labgrid;xlabel('normalised frequency in rad/sec');ylabel('|X(W)|');title('discrete time fourier transform');

OUTPUT RESPONSE(a) Enter the sampling frequency (Fs) =5000The maximum frequecy of analog signal (Wm) =1000rad/sec. i.e. sampling frequency is greater than twice the maximum frequecy. i.e.Ws >2Wm i.e.5000>2000Therefore it satisfies the above condition hence there is no aliasing effect.

(b) Enter the sampling frequency (Fs)=1000The maximum frequecy of analog signal (Wm)=1000rad/sec. i.e. sampling frequency is greater than twice the maximum frequecy. i.e.Ws >2Wm i.e.1000>2000Therefore it dose not satsify the above condition hence there is aliasing effect.

15

Page 16: Dsp Manual

Department of ECE EC2306 Digital Signal Processing Lab

RESULT

Thus the effect of sampling on the frequency domain quantities at different sampling frequencies was studied MATLAB program.

DESIGN OF IIR DIGITAL FILTERS

AIMTo design a digital Butterworth and chebyshev Low pass IIR Filter from the given specification

using MATLAB Function.ALGORITHM

16

Page 17: Dsp Manual

Department of ECE EC2306 Digital Signal Processing Lab1. Get the pass band and stop band attenuation.2. Get the pass band and stop band frequencies.3 Get the sampling frequency4. Calculate the order and cut off frequency.5. Find out the filter co-efficient both numerator and denominator.6. Draw the magnitude and phase response.

A) PROGRAM FOR DESIGN OF BUTTERWORTH DIGITAL IIR FILTERclc;alphap=input('Enter the passband attenuation in dB (alphap)= ');alphas=input('Enter the stopband attenuation in dB (alphas)= ');omp=input('Enter the stopband frequency in rad/sec (omp)= ');oms=input('Enter the stopband frequency in rad/sec (oms)= ');T=input('Enter the sampling time in sec(T)= ');

%Calculate the order of filter and cut-off frequency[N,omc]=buttord(omp,oms,alphap,alphas)%Tofind out coefficient of analog filter[b,a]=butter(N,omc);%To find out the analog filter transfer functionHs=tf(b,a)%To find out the coefficient of digital filter[bz,az]=bilinear(b,a,1/T);%To find out the digital filter transfeer functionHz=tf(bz,az,T)%Draw the magnitude and phase responsew=0:0.001:pi;h=freqz(b,a,w);subplot(2,1,1);plot(w/pi,20*log10(abs(h)),'k');grid;xlabel('Normalised frequency');ylabel('Gain in dB');title('Magnitude response');subplot(2,1,1);plot(w/pi,angle(h),'k');grid;xlabel('Normalised frequency');ylabel('Angle in radians');title('Phase response');

INPUT AND OUTPUT DATAEnter the passband attenuation in dB (alphap)= 3Enter the stopband attenuation in dB (alphas)= 16Enter the stopband frequency in rad/sec (omp)= 0.02Enter the stopband frequency in rad/sec (oms)= 0.9Enter the sampling time in sec(T)= 1

17

Page 18: Dsp Manual

Department of ECE EC2306 Digital Signal Processing LabN = 1

omc =

0.5043

Transfer function:0.5033 s + 0.5033----------------- s + 0.006691

Transfer function:0.7525 z - 0.2508----------------- z - 0.9933 Sampling time: 1

OUTPUT RESPONSE

B) PROGRAM FOR DESIGN OF CHEBYSHEV DIGITAL IIR FILTERclc;alphap=input('Enter the passband attenuation in dB (alphap)= ');alphas=input('Enter the stopband attenuation in dB (alphas)= ');omp=input('enter the passband frequency in rad/sec(omp)=');oms=input('enter the stopband frequency in rad/sec(oms)=');T=input('enter the sampling time in sec(T)=');

18

Page 19: Dsp Manual

Department of ECE EC2306 Digital Signal Processing Lab

%Calculate the order of filter and cut-off frequency[N,omc]=cheb1ord(omp,oms,alphap,alphas);

%Tofind out coefficient of analog filter[b,a]=cheby1(N,0.5,omc);

%To find out the analog filter transfer functionHs=tf(b,a)

%To find out the coefficient of digital filter[bz,az]=bilinear(b,a,1/T);

%To find out the digital filter transfeer functionHz=tf(bz,az,T)

%Draw the magnitude and phase responsew=0:0.001:pi;h=freqz(b,a,w);

subplot(2,1,1);plot(w/pi,20*log10(abs(h)),'k');grid;xlabel('Normalised frequency');ylabel('Gain in dB');title('Magnitude response');

subplot(2,1,2);plot(w/pi,angle(h),'k');grid;xlabel('Normalised frequency');ylabel('Angle in radians');title('Phase response');

INPUT AND OUTPUT DATAEnter the passband attenuation in dB (alphap)= 3Enter the stopband attenuation in dB (alphas)= 16enter the passband frequency in rad/sec(omp)=0.02enter the stopband frequency in rad/sec(oms)=0.9enter the sampling time in sec(T)=1

N = 1

omc =

0.5043

19

Page 20: Dsp Manual

Department of ECE EC2306 Digital Signal Processing LabTransfer function:0.08254 s + 0.08254------------------- s - 0.8349 Transfer function:0.2125 z - 0.07085------------------ z - 2.433 Sampling time: 1

OUTPUT RESPONSE

RESULT

Thus the digital Butterworth and chebyshev Low Pass IIR Filter from the given specification was designed using MATLAB program.

DESIGN OF LINEAR PHASE FIR DIGITAL FILTERS

AIMTo design a linear phase digital FIR Filter (LPF and HPF) using different window sequences in

MATLAB Function.

20

Page 21: Dsp Manual

Department of ECE EC2306 Digital Signal Processing LabALGORITHM1. Get the number of samples of impulse response.2. Get the cut off frequency.3. Determine the value of infinite impulse response.4. Choose the window sequence.5. Determine the filter co-efficient of finite impulse response.6. Draw the magnitude and phase response.

PROGRAM%DESIGN OF DIGITAL FIR (LPF & HPF) FILTER USING RECTENGULAR WINDOWclc;rp=input('Enter the ripple of pass band (rp)=');rs=input('Enter the ripple of stop band (rs)=');fp=input('Enter the frequency of pass band (fp)=');fs=input('Enter the frequency of stop band (fs)=');f=input('Enter the Sampling Frequency (f)=');wp=(2*pi*fp)/f;ws=(2*pi*fs)/f;num=-20*log10(sqrt(rp*rs))-13;den=14.6*(fs-fp)/f;n=ceil(num/den);n1=n+1;y=boxcar(n1);%DESIGN OF LOW PASS FILTERb=fir1(n,wp,y);[h,o]=freqz(b,1,256);m=20*log10(abs(h));subplot(1,2,1);plot(o/pi,m,'k');title('LPF FREQUENCY RESPONSE');

%DESIGN OF HIGH PASS FILTERb=fir1(n,wp,'high',y); [h,o]=freqz(b,1,256);m=20*log10(abs(h));

subplot(1,2,2);plot(o/pi,m,'k');title('HPF FREQUENCY RESPONSE');

INPUT DATA

Enter the ripple of pass band (rp) =.04Enter the ripple of stop band (rs) =.05Enter the frequency of pass band (fp) =1500Enter the frequency of stop band (fs) =2000Enter the Sampling Frequency (f) =25000

21

Page 22: Dsp Manual

Department of ECE EC2306 Digital Signal Processing Lab

OUTPUT RESPONSE FOR LPF & HPF

RESULT

Thus the linear phase Low Pass digital FIR Filter using different window was designed in MATLAB program.

COMPUTATION OF DFT AND IDFT USING FFT ALGORITHMAIMTo compute the DFT and IDFT of the given sequence using FFT Algorithm in MATLAB program.

ALGORITHM 1. Get the length of input sequence N. 2. Get the input sequence x(n) of length N in matrix form.

22

Page 23: Dsp Manual

Department of ECE EC2306 Digital Signal Processing Lab

2. DFT and IDFT of sequences is given by

Where

3. Stop the program.

PROGRAM FOR COMPUTATION OF DFT AND IDFT USING FFT ALGORITHMclc;N=input('Enter the length of the sequence(N)= ');x=input('Enter the input sequence x(n)= ');n=0:1:(N-1);subplot(2,2,1);stem(n,x,'k');xlabel('n---->');ylabel('Amplitude');title('Input sequence');

%Computation of DFT using FFTk=0:1:(N-1);X=fft(x,N)subplot(2,2,2);stem(k,abs(X),'k');xlabel('k---->');ylabel('Amplitude');title('Magnitude plot (DFT)');subplot(2,2,3);stem(k,angle(X),'k');xlabel('k---->');ylabel('Angle');title('Phase plot (DFT)');

%Computation of IDFT using FFTn=0:1:(N-1);x=ifft(X,N)subplot(2,2,4);stem(n,abs(x),'k');xlabel('n---->');ylabel('Amplitude');title('Magnitude plot (IDFT)');

INPUT AND OUTPUT SEQUENCEEnter the length of the sequence(N)= 8Enter the input sequence x(n)= [1 2 3 4 4 3 2 1]

23

Page 24: Dsp Manual

Department of ECE EC2306 Digital Signal Processing LabX =

Columns 1 through 6

20.0000 -5.8284 - 2.4142i 0 -0.1716 - 0.4142i 0 -0.1716 + 0.4142i

Columns 7 through 8

0 -5.8284 + 2.4142i

x =

1 2 3 4 4 3 2 1

OUTPUT RESPONSE

RESULT

Thus the DFT and IDFT of the given sequence using FFT Algorithm in MATLAB program were performed.

DECIMATION BY POLYPHASE DECOMPOSITION

AIM To study the effect of sampling on the frequency domain quantities at different sampling frequencies.

b) Sample at samples/sec to obtain .Determine and plot .

b) Sample at samples/sec to obtain .Determine and plot .

24

Page 25: Dsp Manual

Department of ECE EC2306 Digital Signal Processing LabALGORITHM1. Determine the analog value with respect to variation of time.2. Get the sampling frequency.3. Determine the discrete value with respect to variation of frequency.4. Determine the Omega range from to .5. Determine the magnitude of the signal.6. Draw the discrete time signal and discrete Fourier transform.

PROGRAMDECIMATION BY POLYPHASE DECOMPOSITION

clc;%Analog signalt=-0.005:0.00005:0.005;xa=exp(-1000*abs(t));

%Discrete time signalFs=input('Enter the sampling frequency(Fs)= ');Ts=1/Fs;n=-25:1:25;xn=exp(-1000*abs(n*Ts));

%Discrete time fourier transformN=500;k=0:1:N;w=(2*pi*k/N);X=xn*exp(-j*n'*w);X=abs(X);

%omega range from -Wmax to WmaxW=[-fliplr(w),w(2:N+1)];

%X over -Wmax to Wmax intervalX=[fliplr(X),X(2:N+1)];

subplot(2,1,1);plot(t*1000,xa,'k');grid;hold on;

stem(n*Ts*1000,xn,'k');xlabel('time in sec');

ylabel('x(n)');title('discrete time signal');gtext('Ts=1msec');hold off;

25

Page 26: Dsp Manual

Department of ECE EC2306 Digital Signal Processing Labsubplot(2,1,2);plot(W/pi,X,'k');grid;xlabel('normalised frequency in rad/sec');ylabel('|X(W)|');title('discrete time fourier transform');

OUTPUT RESPONSE(a) Enter the sampling frequency (Fs) =5000The maximum frequecy of analog signal (Wm) =1000rad/sec. i.e. sampling frequency is greater than twice the maximum frequecy. i.e.Ws >2Wm i.e.5000>2000Therefore it satisfies the above condition hence there is no aliasing effect.

(b) Enter the sampling frequency (Fs)=1000The maximum frequecy of analog signal (Wm)=1000rad/sec. i.e. sampling frequency is greater than twice the maximum frequecy. i.e.Ws >2Wm i.e.1000>2000Therefore it dose not satsify the above condition hence there is aliasing effect.

26

Page 27: Dsp Manual

Department of ECE EC2306 Digital Signal Processing Lab

RESULT

Thus the Decimation by polyphase decomposition at different sampling frequencies was studied

MATLAB program.

GENERATION OF SQUARE WAVE USING TMS320C50 AIM

To generate a square wave with amplitude of 2 volts by using

TMS320C50 DSP processor. 27

Page 28: Dsp Manual

Department of ECE EC2306 Digital Signal Processing Lab

APPARATUS REQUIRED

TMS320C50 DSP processor kit, PC, CRO with probe.

ALGORITHM

1. Start the program.

2. Load the amplitude of the square signal of 5 volts.

3. Load the frequency of the square signal.

4. Observe the square waveform by using CRO.

5. Stop the program.

.END PROGRAM FOR GENERATION OF SQUARE WAVEFORM USING TMS320C50

.MMREGS .TEXTSTART: LDP #100H LACC #0FFFH ;change this value for amplitude.LOOP: SACL 0 RPT #0FFH ;change this value for frequency. OUT 0,04H ;address for dac. CMPL B LOOP

OBSERVATION

S.No TIME PERIOD

(msec)AMPLITUDE (volts)

28

Page 29: Dsp Manual

Department of ECE EC2306 Digital Signal Processing Lab

1 1.6 * 2 = 3.2mse 2.5 * 2 = 5 V

RESULT

Thus the square wave was generated using TMS320C50 DSP

Processor.

GENERATION OF SAWTOOTH WAVE USING TMS320C50 AIMTo generate a saw tooth wave with amplitude of 4 volts by using TMS320C50

DSP processor.

APPARATUS REQUIRED

TMS320C50 DSP processor kit, PC, CRO with probe.

ALGORITHM1. Start the program.

2. Load the amplitude of the saw tooth signal of 5 volts.

3. Load the frequency of the saw tooth signal.

4. Observe the saw tooth waveform by using CRO and stop the program.

PROGRAM FOR GENERATION OF SAWTOOTH WAVEFORM USING TMS320C50 .MMREGS .TEXTSTART: LDP #120H LACC #0H ;change lower amplitude SACL 0

29

Page 30: Dsp Manual

Department of ECE EC2306 Digital Signal Processing Lab

OUT 0,04HLOOP: LACC 0 OUT 0,04H ADD #05H ;change frequency SACL 0 SUB #0FFFH ;change upper amplitude BCND LOOP,LEQ B START .END

OBSERVATION

S.No TIME PERIOD

(msec)AMPLITUDE (volts)

1 1.6 * 2 = 3.2mse 2.5 * 2 = 5 V

RESULT

Thus the saw tooth wave was generated using TMS320C50 DSP

Processor.

GENERATION OF TRIANGULAR WAVE USING TMS320C50 AIMTo generate a triangular wave with amplitude of 4 volts by using TMS320C50 DSP processor.

APPARATUS REQUIRED

TMS320C50 DSP processor kit, PC, CRO with probe.

ALGORITHM1. Start the program.

2. Load the amplitude of the saw tooth signal of 5 volts.

3. Load the frequency of the saw tooth signal.

4. Observe the saw tooth waveform by using CRO and stop the program. 30

Page 31: Dsp Manual

Department of ECE EC2306 Digital Signal Processing LabPROGRAM FOR GENERATION OF TRIANGULAR WAVEFORM USING TMS320C50 PROCESSOR

.MMREGS .TEXTSTART: LDP #100H

SPLK #0,00HCONT1: LAR AR2,#85H CONT: OUT 0,04 LACC 0 ADD #8H SACL 0 MAR *,AR2 BANZ CONT,*- LAR AR2,#85HCONTx: OUT 0,04 LACC 0 SUB #8H SACL 0 MAR *,AR2 BANZ CONTx B CONT1

OBSERVATION

S.No TIME PERIOD (msec) AMPLITUDE (volts)

1 1.6 * 2 = 3.2mse 2.5 * 2 = 5 V

RESULT

Thus the triangular wave was generated using TMS320C50 DSP Processor.

PERFORM LINEAR CONVOLUTION OF TWO SEQUENCES

AIM To perform the linear convolution of the two sequences using TMS320C50 DSP Processor.ALGORITHM 1. Get the two sequence x(n) and h(n) in matrix form. 2. The convolution of the two sequences is given by

For Linear Convolution

31

Page 32: Dsp Manual

Department of ECE EC2306 Digital Signal Processing Lab

For Linear Convolution

3. Stop the program.

A) PROGRAM TO PERFORM LINEAR CONVOLUTION OF TWO SEQUENCES USING TMS320C50

.MMREGS .TEXTSTART: LDP #02H LAR AR1,#8100H ; x(n) datas LAR AR0,#8200H ;h(n) datas LAR AR3,#8300H ;y(n) starting LAR AR4,#0007 ;N1+N2-1;to fold the h(n) values LAR AR0,#08203H LACC #0C100H MAR *,AR0 RPT #3 TBLW *-;padding of zerros for x(n) values LAR AR6,#8104H MAR *,ar6 LACC #0H RPT #3H SACL *+;convalution operation startsLOP: MAR *,AR1 LACC *+ SACL 050H ;starting of the scope of multiplication LAR AR2,#0153H ; end of the array, to be multiplied with h(n) {150+N1-1} MAR *,AR2 ZAP RPT #03H ;N1-1 times so that N1 times

32

Page 33: Dsp Manual

Department of ECE EC2306 Digital Signal Processing Lab

MACD 0C100H,*- APAC ;to accmulate the final product sample MAR *,AR3 SACL *+ MAR *,AR4 BANZ LOP,*-

H: B H

INPUT AND OUTPUT SEQUENCE

;INPUT ( x(n) )

;8100 - 1;8101 - 3;8102 - 1;8103 - 3

;INPUT ( h(n) )

; 8200 - 0; 8201 - 1; 8202 - 2; 8203 - 1

;OUTPUT ( y(n) )

; 8300 - 0; 8301 - 1; 8302 - 5; 8303 - 8; 8304 - 8; 8305 - 7; 8306 - 3

33

Page 34: Dsp Manual

Department of ECE EC2306 Digital Signal Processing Lab

B) PROGRAM TO PERFORM CIRCULAR CONVOLUTION OF TWO SEQUENCES USING TMS320C50

.MMREGS .TEXTSTART: LDP #100H LACC 0H ;length of the input is given in 8000 SUB #1H SACL 1H LAR AR0,1H LAR AR1,#8060H; LAR AR2,#8100HCOPYX2: MAR *,AR1 LACC *+ MAR *,AR2 SACL *+ MAR *,AR0 BANZ COPYX2,*- LAR AR0,1H LAR AR2,#8010HLOOP3: LAR AR1,#8060H ;give the inputs x1[n] & h2[n] in AR1 & AR3 LAR AR3,#8050H LAR AR4,1H ZAPLOOP: MAR *,AR3 ;multiply x1[n] & X2[n] and add the;multiplication LT *+ MAR *,AR1 ;output

34

Page 35: Dsp Manual

Department of ECE EC2306 Digital Signal Processing Lab MPY *+ SPL 5H ;store the partial result at location 8005 ADD 5H ; add the partial result with accumulator MAR *,AR4 BANZ LOOP,*- MAR *,AR2 ;outputs of correlation are stored in AR2 SACL *+ CALL ROTATELOOP2: MAR *,AR0 BANZ LOOP3,*002D`jhmgjmh B H

ROTATE: LDP #100H ;rotate the values of X1[n] LACC 1H SUB #1H SACL 2H LACC 0050H SACB ; 8050 DATA MOVED TO THE ACCUMULATOR TO THE ACCUMULATOR BUFFER LAR AR3,#8051H LAR AR5,#8070H LAR AR6,2HLOOP1: MAR *,AR3 LACC *+ MAR *,AR5 SACL *+ MAR *,AR6 BANZ LOOP1,*-; DATA FROM 8051-8053 TO 8070-8072 LACB ;MOVE THE DATA ACCUMULATOR BUFFER TO ACCUMULATOR AS LAST DATA MAR *,AR5 SACL *+ LACC #8070H SAMM BMAR LAR AR3,#8050H MAR *,AR3 RPT #3H ;ROTATE 4 TIMES BLDD BMAR,*+ ;BMAR AUTOMATICALLY INCREMENTED ,TO COPY SHIFTED DATA TO 8050 RET

35

Page 36: Dsp Manual

Department of ECE EC2306 Digital Signal Processing Lab

INPUT AND OUTPUT SEQUENCE

;INPUT:; 8000-0004;

;X1(n) = 8050 - 0002; 8051 - 0001; 8052 - 0002; 8053 - 0001;

;H2(n ) = 8060 - 0001; 8061 - 0002; 8062 - 0003; 8063 - 0004

;OUTPUT:; 8010-000E; 8011-0010; 8012-000E; 8013-0010;

RESULT

Thus the linear convolution of the two sequences was performed using TMS320C50 DSP Processor.

36

Page 37: Dsp Manual

Department of ECE EC2306 Digital Signal Processing Lab

SAMPLING OF INPUT SIGNAL AND DISPLAY

AIM To perform the sampling of the given input signal using TMS320C50 DSP Processor and plot its wave

form.

ALGORITHM1. Start the program.

2. Switch off the trainer kit.

3. Connect the function generator in the corresponding terminals.

4. Download the program to the trainer kit using Xtalk.exe

5. Quit from the Xtalk.

6. Enter into the basic TB.exe

7. Load and run the program "sample50.bas" which executes the ASM program and plots the samples

on the screen.

SAMPLING THEOREM

;PROGRAM DESCRIPTION:In this program the samples are taken from the ADC with the desired sampling rate and the sample values are stored in the memory locations from the data memory 9000H. After taking 720 samples from the ADC the samples are sent through the serial port which is received by the basic program named "sample50.bas",and plots the samples in the pc screen.In this program the sampling rate is varied by varying the number in the address named DELAY. The delay value is also sent to the basic programas a first data. The distance between the samples in the basic program varies according to the delay value which it receives as a first data.

;Note:

37

Page 38: Dsp Manual

Department of ECE EC2306 Digital Signal Processing Lab;1. Swith off the trainer kit.;2. Connect the function generator in the corresponding terminals.;3. Download the program to the trainer kit using Xtalk.exe;4. Quit from the Xtalk.;5. Enter into the basic TB.exe;6. Load and run the program "sample50.bas" which executes the asm program; and plots the samples on the screen.;TXD .SET 0HSTS .SET 1HDATA .SET 2H

DELAY .SET 3H

B3 .SET 0F000HB2 .SET 0F00HB1 .SET 00F0HB0 .SET 000FH .mmregs .textSTART: LDP #100H LAR AR0,#9000H LAR AR1,#719REP: IN 0,06 RPT #0FH NOP IN 0,04 SPLK #5FFH,DELAY RPT DELAY NOP LACC 0 AND #0FFFH MAR *,AR0 SACL *+,0,AR1 BANZ REP,*-

LACC DELAY SACL DATA CALL SERIALREPSER: LAR AR2,#9000H LAR AR0,#719REPSAMP: MAR *,AR2 LACC *+ SACL DATA CALL SERIAL

38

Page 39: Dsp Manual

Department of ECE EC2306 Digital Signal Processing Lab MAR *,AR0 BANZ REPSAMP,*- B REPSER

;routine to send each digit of DATA individually to the serial port;first send the start of character "%";seperate and send each digits of DATA from MSB;send end of character "$"SERIAL SPLK #25H,TXD ;start of character "%" CALL TXDATA RPT #0FFFH

NOP LACC DATA AND #B3 ;1st digit (from msb) BSAR 12 SACL TXD CALL HEXASC CALL TXDATA RPT #0FFFH NOP

LACC DATA AND #B2 ;second digit BSAR 8 SACL TXD CALL HEXASC CALL TXDATA RPT #0FFFH NOP

LACC DATA AND #B1 ;3rd digit BSAR 4 SACL TXD CALL HEXASC CALL TXDATA RPT #0FFFH NOP

LACC DATA AND #B0 ;4th digit SACL TXD CALL HEXASC CALL TXDATA RPT #0FFFH

39

Page 40: Dsp Manual

Department of ECE EC2306 Digital Signal Processing Lab NOP

SPLK #24H,TXD ;end of character "$" CALL TXDATA RPT #0FFFH NOP RET

;loop to conver hex data to ascii;input is in address TXD;output is also in TXD;subtracts 9 from input hex data;if >0 add 37h to input hex data

;Otherwise add 30h to input hex dataHEXASC: LACC TXD SUB #9H BCND GRT9,GT LACC TXD ADD #30H SACL TXD RETGRT9: LACC TXD ADD #37H SACL TXD RET

;loop to send a character to the serial port;checks the status of the serial port(TXREADY-bit2).;if not 0, send that character. Otherwise checks it repeatedly.TXDATA:REPCHK: IN STS,9 LACC STS AND #04H BCND REPCHK,EQ

OUT TXD,8 RET

OUTPUT RESPONSE(a) Enter the sampling frequency (Fs) =5000The maximum frequecy of analog signal (Wm) =1000rad/sec. i.e. sampling frequency is greater than twice the maximum frequecy. i.e.Ws >2Wm i.e.5000>2000

40

Page 41: Dsp Manual

Department of ECE EC2306 Digital Signal Processing LabTherefore it satisfies the above condition hence there is no aliasing effect.

RESULT

Thus the sampling of the given input signal was performed using TMS320C50 DSP Processor.

41

Page 42: Dsp Manual

Department of ECE EC2306 Digital Signal Processing Lab

IMPLEMENTATION OF FIR FILTERS

AIMTo implementation digital FIR Filter (LPF and HPF) using TMS320C50 DSP Processor.

ALGORITHM1. Get the pass band and stop band ripples.2. Get the pass band and stop band frequency.3 Get the sampling frequency4. Calculate the order the filter by using the formula,

5. Find the filter co-efficient.6. Draw the magnitude and phase response.

PROGRAM%DESIGN OF DIGITAL FIR (LPF & HPF) FILTER USING RECTENGULAR WINDOWclc;rp=input('Enter the ripple of pass band (rp)=');rs=input('Enter the ripple of stop band (rs)=');fp=input('Enter the frequency of pass band (fp)=');fs=input('Enter the frequency of stop band (fs)=');f=input('Enter the Sampling Frequency (f)=');wp=(2*pi*fp)/f;ws=(2*pi*fs)/f;num=-20*log10(sqrt(rp*rs))-13;den=14.6*(fs-fp)/f;n=ceil(num/den);n1=n+1;y=boxcar(n1);%DESIGN OF LOW PASS FILTERb=fir1(n,wp,y);[h,o]=freqz(b,1,256);m=20*log10(abs(h));subplot(1,2,1);plot(o/pi,m,'k');title('LPF FREQUENCY RESPONSE');

42

Page 43: Dsp Manual

Department of ECE EC2306 Digital Signal Processing Lab

%DESIGN OF HIGH PASS FILTERb=fir1(n,wp,'high',y); [h,o]=freqz(b,1,256);m=20*log10(abs(h));

subplot(1,2,2);plot(o/pi,m,'k');title('HPF FREQUENCY RESPONSE');

INPUT DATA

Enter the ripple of pass band (rp) =.04Enter the ripple of stop band (rs) =.05Enter the frequency of pass band (fp) =1500Enter the frequency of stop band (fs) =2000Enter the Sampling Frequency (f) =25000

OUTPUT RESPONSE FOR LPF & HPF

RESULT

Thus the digital FIR Filter (LPF and HPF) was implemented using TMS320C50 DSP Processor.

43

Page 44: Dsp Manual

Department of ECE EC2306 Digital Signal Processing Lab

44