Top Banner
VICKRAM COLLEGE OF ENGINEERING,ENATHI-630561 Affiliated to Anna University,Trichy 2011-2012 EC1359-DIGITAL SIGNAL PROCESSING LABORATORY VI SEMESTER B.Tech-INFORMATION TECHNOLOGY PREPARED BY: APPROVED BY: Mr.Prithivirajan
102
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: DSP Manual

VICKRAM

COLLEGE OF ENGINEERING,ENATHI-630561Affiliated to Anna University,Trichy

2011-2012

EC1359-DIGITAL SIGNAL PROCESSING LABORATORY

VI SEMESTER

B.Tech-INFORMATION TECHNOLOGY

PREPARED BY: APPROVED BY: Mr.Prithivirajan

(SR.LECTURER/ECE) Mr.Antony Joe Christo Dr.VenkataKrishanan

(LECTURER/ECE) (HOD/ECE)

Page 2: DSP Manual

LIST OF EXPERIMENTS

S.NoName of the Experiments

Page Number Signature

1 Generation of Signals using MATLAB 1

2Linear Convolution of Two Sequences using MATLAB

3

3Circular Convolution of Two Sequences using MATLAB

5

4(A)Design of IIR Filters using MATLABButterworth Lowpass Filter

7

4(B)Butterworth Highpass filter 9

4(C)Butterworth Bandpass filter 11

4(D)Butterworth Bandstop filter 13

4(E)Chebyshev type-I filter 15

4(F)Chebyshev Type –II filter 17

5(A)Design of FIR Filters using MATLABBlackman Window

19

5(B)Rectangular Window 21

5(C)Hamming window 23

5(D)Hanning window 25

5(E)Kaiser window 27

6Calculation of FFT using MATLAB 29

7Sampling and effect of aliasing 31

8

USING TMS320C5416 PROCESSOR:Study of various Addressing Modes of DSP using Simple Programming Examples

34

9Calculation of FFT 37

10Implementation of FIR Filter 41

11Sampling of Input Signal and Display 43

Page 3: DSP Manual

12IIR Filter Implementation 45

GENERATION OF BASIC SEQUENCES

AIM:To write a program for generation of sine wave, Cosine wave, Unit impulse,

Unit step, Unit ramp and Exponential sequence.

ALGORTHIM:

1. Clear2. Clear all3. Close all4. Initialize the values of n.5. Apply the inputs to the following sequences.

i) Sine wave signal = sin ( 0.2* pi* n)

ii) Cosine wave signal = cos (0.2* pi* n)

iii) Unit impulse = 1 for n=0 0, otherwise

iv) Unit step = 1 for n≥0 0, otherwise

v) Unit ramp = n , for n≥0 0, otherwise

vi) Exponential sequence = an

6. Plot the graphs7. Label the graphs8. Stop

Page 4: DSP Manual
Page 5: DSP Manual

%%%%%%%%%GENERATION OF SIGNALS%%%%%%%%%%

%CLEAR THE SCREENclc;clear all;close all;

%INITIALIZATIONn=0:15;pi=3.14;

%SINE WAVE SIGNALx=sin(0.2*pi*n);

%PLOT THE SINE WAVEsubplot(2,3,1);stem(x);

%LABEL THE SINEWAVEtitle('SINE WAVE SEQUENCE');xlabel('time-->');ylabel('amplitude-->');

%COSINE WAVE SIGNALx=cos(0.2*pi*n);

%PLOT THE COSINE WAVEsubplot(2,3,2);stem(x);

%LABEL THE COSINEWAVEtitle('COSINE WAVE SEQUENCE');xlabel('time-->');ylabel('amplitude-->');

%EXPONENTIAL SIGNALx=0.8.^(-n);

%PLOT EXPONENTIAL SIGNALsubplot(2,3,3);stem(x);

%LABEL EXPONENTIAL SEQUENCEtitle('EXPONENTIAL SEQUENCE');xlabel('time-->');

Page 6: DSP Manual

ylabel('amplitude-->');

%RAMP SEQUENCEx=n;

%PLOT RAMP SEQUENCEsubplot(2,3,4);stem(x);

%LABEL RAMP SEQUENCEtitle('RAMP SEQUENCE');xlabel('time-->');ylabel('amplitude-->');

%STEP SEQUENCEa=length(n);x=ones(a);

%PLOT STEP SEQUENCEsubplot(2,3,5);stem(x);

%LABEL STEP SEQUENCEtitle('STEP SEQUENCE');xlabel('time-->');ylabel('amplitude-->');

%IMPULSE SEQUENCEx=1;

%PLOT IMPULSE SEQUENCEsubplot(2,3,6);stem(0,x);

%LABEL IMPULSE SEQUENCEtitle('IMPULSE SEQUENCE');xlabel('time-->');ylabel('amplitude-->');

RESULT:

Page 7: DSP Manual

Thus the program for generation of basic sequences have been done and verified.

LINEAR CONVOLUTION

AIM:

To write a program to convolute the two input sequences using linear convolution.

ALGORTHIM:

9. Clear10. Clear all11. Close all12. Enter the first sequence x(n)13. Enter the second sequence h(n)14. The convoluted signal is denoted as

y(n) = Σ x(m) h(n-m)15. Plot the graphs16. Label the graphs17. Stop

Page 8: DSP Manual

ENTER THE FIRST SEQUENCE[1 2 3 4]

ENTER THE SECOND SEQUENCE[3 4 5]

OUTPUT IS:

z =

3 10 22 34 31 20

Page 9: DSP Manual

%%%%%%%%LINEAR CONVOLUTION%%%%%%%%%

%CLEAR THE SCREENclc;clear all;x=input('ENTER THE FIRST SEQUENCE');y=input('ENTER THE SECOND SEQUENCE');z=conv(x,y);

%PLOT THE FIRST SEQUENCEsubplot(3,1,1);stem(x);

%LABEL THE FIRST SEQUENCEtitle('FIRST SEQUENCE');xlabel('time-->');ylabel('amplitude-->');

%PLOT THE SECOND SEQUENCEsubplot(3,1,2);stem(y);

%LABEL THE SECOND SEQUENCEtitle('SECOND SEQUENCE');xlabel('time-->');ylabel('amplitude-->');

%PLOT THE OUTPUT SEQUENCEsubplot(3,1,3);stem(z);

%LABEL THE OUTPUT SEQUENCEtitle('OUTPUT SEQUENCE');xlabel('time-->');ylabel('amplitude-->');

%DISPLAY THE OUTPUTdisp('THE OUTPUT IS:');z

Page 10: DSP Manual

RESULT:

Thus the program for linear convolution was verified and the output was obtained.

CIRCULAR CONVOLUTION

AIM:

To write a program to convolute the two input sequences using circular convolution.

ALGORTHIM:

1. Clear2. Clear all3. Close all4. Get the two input sequences g(n) and h(n)5. Find the length of two input sequences.6. Determine their value of K by using the formula

K = mod( n-m , 1 ) +1

7. Find the value of y by using the formulaY= y+ g(m) * h(k)

8. Plot the graphs9. Label the graphs10. Stop

Page 11: DSP Manual

1

z =

1 4

z =

1 4 8

z =

1 4 8 8

n =

0 1 2 3

THE RESULTANT OUTPUT IS:

z =

1 4 8 8

Page 12: DSP Manual

%%%%%%%%%CIRCULAR CONVOLUTION%%%%%%

%CLEAR THE SCREENclc;clear all;close all;

%INPUTg=[1 2 4 0]h=[1 2]

%LENGTH OF THE INPUTL=length(g);M=length(h);

%ZERO PADDINGif L>Mh=[h zeros(1,L-M)];elseg=[g zeros(1,M-L)];L=M;end;

%OUTPUTfor n=1:Ly=0;

Page 13: DSP Manual

for M=1:Lk=mod(n-M,L)+1;y=y+g(M)*h(k);endz(n)=yend

%PLOT THE INPUTn=0:L-1figure(1);subplot(3,1,1);stem(n,g,'.');

%TITLEtitle('CIRCULAR CONVOLUTION');%PLOT THE INPUTsubplot(3,1,2);stem(n,h,'*');

%LABELylabel('amplitude-->');

%PLOT THE OUTPUTsubplot(3,1,3);stem(n,z,'r.');

%LABELxlabel('time-->')

%DISPLAY THE OUTPUTdisp('THE RESULTANT OUTPUT IS:');z

Page 14: DSP Manual

RESULT:

Thus the program for circular convolution was verified and the output was obtained.

BUTTERWORTH LOWPASS FILTER

AIM:

To write a program to design a Butterworth lowpass filter

ALGORTHIM:

1. Clear2. Clear all3. Close all4. Get the pass band and stop band ripples5. Get the pass band and stop band frequencies.6. Get the sampling frequency.7. Calculate the order of the filter

i. N ≥ log( λ/ ξ ) / log (1/ k)8. Find the filter co- efficient.9. Plot the phase and magnitude responses.10. Label the graphs11. Stop

Page 15: DSP Manual

Enter the passband ripple0.5Enter the stopband ripple40Enter the passband frequency1200Enter the stopband frequency2400Enter the sampling frequency10000

>> 1 4 8 8

Page 16: DSP Manual

%%%%%%%%%BUTTER WORTH LOW PASS FILTER%%%%%%%%

%CLEAR THE SCREENclc;clear all;close all;format long;

%INPUTrp=input('Enter the passband ripple');rs=input('Enter the stopband ripple');wp=input('Enter the passband frequency');ws=input('Enter the stopband frequency');

Page 17: DSP Manual

fs=input('Enter the sampling frequency');

%OUTPUTw1=2*wp/fs;w2=2*ws/fs;[n,wn]=buttord(w1,w2,rp,rs);[b,a]=butter(n,wn);w=0:0.01:pi;[h,om]=freqz(b,a,w);m=20*log10(abs(h));an=angle(h);

%PLOT THE GAINsubplot(2,1,1);plot(om/pi,m);

%TITLEtitle('BUTTER WORTH LOW PASS FILTER');

%LABEL THE OUTPUTylabel('gain in db-->');xlabel('(a)normalized frequency-->');

%PLOT THE PHASEsubplot(2,1,2);plot(om/pi,an);

%LABEL THE OUTPUTxlabel('(b)normalized frequency-->');ylabel('phase in radians-->');

RESULT:

Thus the design of Butterworth lowpass filter has been done and verified.

BUTTERWORTH HIGHPASS FILTER

AIM:

To write a program to design a Butterworth highpass filter

ALGORTHIM:

1. Clear2. Clear all3. Close all4. Get the pass band and stop band ripples5. Get the pass band and stop band frequencies.

Page 18: DSP Manual

6. Get the sampling frequency.7. Calculate the order of the filter

i. N ≥ log( λ/ ξ ) / log (1/ k)8. Find the filter co- efficient.9. Plot the phase and magnitude responses.10. Label the graphs11. Stop

Enter the passband ripple0.5Enter the stopband ripple40Enter the passband frequency1200Enter the stopband frequency2500Enter the sampling frequency10000

Page 19: DSP Manual

%%%%%%%%BUTTER WORTH HIGH PASS FILTER%%%%%%

%CLEAR THE SCREENclc;clear all;close all;format long;

%INPUTrp=input('Enter the passband ripple');

Page 20: DSP Manual

rs=input('Enter the stopband ripple');wp=input('Enter the passband frequency');ws=input('Enter the stopband frequency');fs=input('Enter the sampling frequency');

%OUTPUTw1=2*wp/fs;w2=2*ws/fs;[n,wn]=buttord(w1,w2,rp,rs);[b,a]=butter(n,wn,'high');w=0:0.01:pi;[h,om]=freqz(b,a,w);m=20*log10(abs(h));an=angle(h);

%PLOT THE GAINsubplot(2,1,1);plot(om/pi,m);

%TITLEtitle('BUTTER WORTH HIGH PASS FILTER');

%LABEL THE OUTPUTylabel('gain in db-->');xlabel('(a)normalized frequency-->');

%PLOT THE PHASEsubplot(2,1,2);plot(om/pi,an);

%LABEL THE OUTPUTxlabel('(b)normalized frequency-->');ylabel('phase in radians-->');

RESULT:

Thus the design of Butterworth highpass filter has been done and verified.

BUTTERWORTH BANDPASS FILTER

AIM:

To write a program to design a Butterworth bandpass filter

ALGORTHIM:

1. Clear2. Clear all

Page 21: DSP Manual

3. Close all4. Get the pass band and stop band ripple5. Get the pass band and stop band frequency6. Get the sampling frequency7. Calculate the order of the filter

i. N ≥ log ( λ/ ξ ) / log (1/ k)8. Find the filter co- efficients9. Plot the phase and magnitude responses.10. Label the graphs11. Stop

Enter the passband ripple0.5Enter the stopband ripple40Enter the passband frequency1200Enter the stopband frequency2400Enter the sampling frequency10000

wn =

0.24000000000000 0.48000000000000

Page 22: DSP Manual

>>

%%%%%%BUTTER WORTH BAND PASS FILTER%%%%%%

%CLEAR THE SCREENclc;clear all;close all;format long;

%INPUT

Page 23: DSP Manual

rp=input('enter the passband ripple');rs=input('Enter the stopband ripple');wp=input('Enter the passband frequency');ws=input('Enter the stopband frequency');fs=input('Enter the sampling frequency');%OUTPUTw1=2*wp/fs;w2=2*ws/fs;[n,wn]=buttord(w1,w2,rp,rs);wn=[w1,w2][b,a]=butter(n,wn,'bandpass'); w=0:0.01:pi;[h,om]=freqz(b,a,w);m=20*log10(abs(h));an=angle(h);

%PLOT THE GAINsubplot(2,1,1);plot(om/pi,m);

%TITLEtitle('BUTTER WORTH BAND PASS FILTER');

%LABEL THE OUTPUTylabel('gain in db-->');xlabel('(a)normalized frequency-->');

%PLOT THE PHASEsubplot(2,1,2);plot(om/pi,an);

%LABEL THE OUTPUTxlabel('(b)normalized frequency-->');ylabel('phase in radians-->');

RESULT:

Thus the design of Butterworth bandpass filter has been done and verified.

BUTTERWORTH BANDSTOP FILTER

AIM:

To write a program to design a Butterworth bandstop filter

ALGORTHIM:

1. Clear2. Clear all

Page 24: DSP Manual

3. Close all4. Get the pass band and stop band ripples5. Get the pass band and stop band frequencies.6. Get the sampling frequency.7. Calculate the order of the filter

i. N ≥ log ( λ/ ξ ) / log (1/ k)8. Find the filter co- efficient.9. Plot the phase and magnitude responses.10. Label the graphs11. Stop

Enter the passband ripple0.5Enter the stopband ripple40Enter the passband frequency1200Enter the stopband frequency2400Enter the sampling frequency10000

wn =

Page 25: DSP Manual

0.24000000000000 0.48000000000000

%%%%%%%BUTTER WORTH BAND STOP FILTER%%%%%%%%

%CLEAR THE SCREENclc;clear all;close all;format long;

%INPUTrp=input('Enter the passband ripple');rs=input('Enter the stopband ripple');

Page 26: DSP Manual

wp=input('Enter the passband frequency');ws=input('Enter the stopband frequency');fs=input('Enter the sampling frequency');

%OUTPUTw1=2*wp/fs;w2=2*ws/fs;[n,wn]=buttord(w1,w2,rp,rs);wn=[w1,w2][b,a]=butter(n,wn,'stop');w=0:0.01:pi;[h,om]=freqz(b,a,w);m=20*log10(abs(h));an=angle(h);

%PLOT THE GAINsubplot(2,1,1);plot(om/pi,m);

%TITLEtitle('BUTTER WORTH BAND STOP FILTER');

%LABEL THE OUTPUTylabel('gain in db-->');xlabel('(a)normalized frequency-->');

%PLOT THE PHASEsubplot(2,1,2);plot(om/pi,an);

%LABEL THE OUTPUTxlabel('(b)normalized frequency-->');ylabel('phase in radians-->');

RESULT:

Thus the design of Butterworth bandstop filter has been done and verified.

CHEBYSHEV TYPE-I FILTER

AIM:

To write a program to design a chebyshev type-I filter

ALGORTHIM:

1. Clear2. Clear all3. Close all

Page 27: DSP Manual

4. Initialize the pass band, stop band attenuation and frequency.5. Find the order and cut off frequency.6. Find the filter co- efficient.7. Plot the phase and magnitude responses.8. Label the graphs9. Stop

>> astop =

15

Page 28: DSP Manual

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-200

-150

-100

-50

0chebyshev type 1 filter

gain

-->

frequency-->

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-4

-2

0

2

4

gain

-->

frequency-->

%%%%%%%%%%CHEBYSHEV TYPE-I FILTER%%%%%%%%

%CLEAR THE SCREENclc;clear all;close all;

%PASS BAND AND STOP BAND ATTENUATION AND FREQUENCY

Page 29: DSP Manual

apass=1;astop=15wp=2*pi;ws=3*pi;

%ORDER AND CUTOFF FREQUENCY[n,wn]=cheb1ord(wp\pi,ws\pi,apass,astop);

%OUTPUT[b,a]=cheby1(n,apass,wn);w=0:.01:pi;[h,ph]=freqz(b,a,w);m=20*log10(abs(h));an=angle(h);

%PLOT THE GAINsubplot(2,1,1);plot(ph/pi,m);grid;title('chebyshev type 1 filter');

%LABEL THE GRAPHylabel('gain-->');xlabel('frequency-->');

%PLOT THE PHASEsubplot(2,1,2);plot(ph/pi,an);grid;

%LABEL THE GRAPHylabel('gain-->');xlabel('frequency-->');

[b,a]=cheby1(n,apass,wn);

RESULT:

Thus the design of chebyshev type- I filter has been done and verified.

CHEBYSHEV TYPE-II FILTER

AIM:

To write a program to design a chebyshev type-II filter

ALGORTHIM:

Page 30: DSP Manual

1. Clear2. Clear all3. Close all4. Initialize the pass band, stop band attenuation and frequency.5. Find the order and cut off frequency.6. Find the filter co- efficient.7. Plot the phase and magnitude responses.8. Label the graphs9. Stop

>> astop =

15

Page 31: DSP Manual

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-60

-40

-20

0

20chebyshev type 2 filter

gain

-->

frequency-->

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-2

-1

0

1

2

gain

-->

frequency-->

%%%%%%%%%CHEBYSHEV TYPE-II FILTER%%%%%%%%%

%CLEAR THE SCREENclc;clear all;close all;

%PASS BAND AND STOP BAND ATTENUATION AND FREQUENCYapass=1;

Page 32: DSP Manual

astop=15wp=2*pi;ws=3*pi;

%ORDER AND CUTOFF FREQUENCY[n,wn]=cheb1ord(wp\pi,ws\pi,apass,astop);

%OUTPUT[b,a]=cheby2(n,apass,wn);w=0:.01:pi;[h,ph]=freqz(b,a,w);m=20*log10(abs(h));an=angle(h);

%PLOT THE GAINsubplot(2,1,1);plot(ph/pi,m);grid;title('chebyshev type 2 filter');

%LABEL THE GRAPHylabel('gain-->');xlabel('frequency-->');

%PLOT THE PHASEsubplot(2,1,2);plot(ph/pi,an);grid;

%LABEL THE GRAPHylabel('gain-->');xlabel('frequency-->');

[b,a]=cheby2(n,apass,wn);

RESULT:

Thus the design of chebyshev type- II filter has been done and verified.

BLACKMAN WINDOW

AIM:

To write a program to design a Blackman window sequence.

ALGORTHIM:

1. Clear

Page 33: DSP Manual

2. Clear all3. Close all4. Get the pass band and stop band ripples.5. Get the pass band and stop band frequencies.6. Get the sampling frequency.7. Find the filter co – efficient.8. Calculate the values of the Blackman window sequence for each low

pass, high pass, band pass and band stop filter.9. Plot the graphs.10. Label the graphs.11. Stop.

Enter the passband ripple0.05Enter the stopband ripple0.04Enter the passband frequency1500Enter the stopband frequency2000Enter the sampling frequency9000>>

Page 34: DSP Manual

%%%%%%%%%BLACKMAN WINDOW%%%%%%%

%CLEAR THE SCREENclcclear all;close all;

%inputrp=input('Enter the passband ripple');rs=input('Enter the stopband ripple');

Page 35: DSP Manual

fp=input('Enter the passband frequency');fs=input('Enter the stopband frequency');f=input('Enter the sampling frequency');

%outputwp=2*fp/f;ws=2*fs/f;num=-20*log(sqrt(rp*rs))-13;dem=14.6*(fs-fp)/f;n=ceil(num/dem);n1=n+1;if(rem(n,2)~=0);n1=n;n=n-1;endy=blackman(n1);

%Low pass filterb=fir1(n,wp,y);[h,o]=freqz(b,1,256);m=20*log10(abs(h));subplot(2,2,1);plot(o/pi,m);title('low pass filter');ylabel('gain in db--->');xlabel('(a) normalized frequency--->');

%High pass filterb=fir1(n,wp,'high',y);[h,o]=freqz(b,1,256);m=20*log10(abs(h));subplot(2,2,2);plot(o/pi,m);title('high pass filter');ylabel('gain in db--->');xlabel('(b) normalized frequency--->');

%Band pass filterwn=[wp,ws];b=fir1(n,wn,y);[h,o]=freqz(b,1,256);m=20*log10(abs(h));subplot(2,2,3);plot(o/pi,m);title('band pass filter');ylabel('gain in db--->');xlabel('(c) normalized frequency--->');

Page 36: DSP Manual

%Band stop filterb=fir1(n,wn,'stop',y);[h,o]=freqz(b,1,256);m=20*log10(abs(h));subplot(2,2,4);plot(o/pi,m);title('band stop filter');ylabel('gain in db--->');xlabel('(d) normalized frequency--->');

RESULT:

Thus the design of Blackman window has been done and verified.

RECTANGULAR WINDOW

AIM:

To write a program to design a Rectangular window sequence.

ALGORTHIM:

1. Clear2. Clear all

Page 37: DSP Manual

3. Close all4. Get the pass band and stop band ripples.5. Get the pass band and stop band frequencies.6. Get the sampling frequency.7. Find the filter co – efficient.8. Calculate the values of the rectangular window sequence for each low

pass, high pass, band pass and band stop filter.9. Plot the graphs.10. Label the graphs.11. Stop.

Enter the passband ripple0.05Enter the stopband ripple0.04Enter the passband frequency1400Enter the stopband frequency2500Enter the sampling frequency9000

Page 38: DSP Manual

%%%%%%%%%RECTANGULAR WINDOW%%%%%%%%%%

%CLEAR THE SCREENclcclear all;close all;

%inputrp=input('enter the passband ripple');rs=input('enter the stopband ripple');

Page 39: DSP Manual

fp=input('enter the passband frequency');fs=input('enter the stopband frequency');f=input('enter the sampling frequency');

%outputwp=2*fp/f;ws=2*fs/f;num=-20*log(sqrt(rp*rs))-13;dem=14.6*(fs-fp)/f;n=ceil(num/dem);n1=n+1;if(rem(n,2)~=0);n1=n;n=n-1;endy=boxcar(n1);

%Low pass filterb=fir1(n,wp,y);[h,o]=freqz(b,1,256);m=20*log10(abs(h));subplot(2,2,1);plot(o/pi,m);title('low pass filter');ylabel('gain in db--->');xlabel('(a) normalized frequency--->');

%High pass filterb=fir1(n,wp,'high',y);[h,o]=freqz(b,1,256);m=20*log10(abs(h));subplot(2,2,2);plot(o/pi,m);title('high pass filter');ylabel('gain in db--->');xlabel('(b) normalized frequency--->');

%Band pass filterwn=[wp,ws];b=fir1(n,wn,y);[h,o]=freqz(b,1,256);m=20*log10(abs(h));subplot(2,2,3);plot(o/pi,m);title('band pass filter');ylabel('gain in db--->');

Page 40: DSP Manual

xlabel('(c) normalized frequency--->');

%Band stop filterb=fir1(n,wn,'stop',y);[h,o]=freqz(b,1,256);m=20*log10(abs(h));subplot(2,2,4);plot(o/pi,m);title('band stop filter');ylabel('gain in db--->');xlabel('(d) normalized frequency--->');

RESULT:

Thus the design of rectangular window has been done and verified.

HAMMING WINDOW

AIM:

To write a program to design a Hamming window sequence.

ALGORTHIM:

1. Clear2. Clear all3. Close all4. Get the pass band and stop band ripples.

Page 41: DSP Manual

5. Get the pass band and stop band frequencies.6. Get the sampling frequency.7. Find the filter co – efficient.8. Calculate the values of the hamming window sequence for each low

pass, high pass, band pass and band stop filter.9. Plot the graphs.10. Label the graphs.11. Stop.

Enter the passband ripple0.05Enter the stopband ripple0.04Enter the passband frequency1200Enter the stopband frequency2400Enter the sampling frequency9000>>

Page 42: DSP Manual

0 0.5 1-80

-60

-40

-20

0

20low pass filter

gain

in d

b---

>

(a) normalized frequency--->0 0.5 1

-100

-50

0

50high pass filter

gain

in d

b---

>

(b) normalized frequency--->

0 0.5 1-100

-80

-60

-40

-20

0band pass filter

gain

in d

b---

>

(c) normalized frequency--->0 0.5 1

-60

-40

-20

0

20band stop filter

gain

in d

b---

>

(d) normalized frequency--->

%%%%%%%%%%HAMMING WINDOW%%%%%%%%%

%CLEAR THE SCREENclc;clear all;close all;

Page 43: DSP Manual

%inputrp=input('Enter the passband ripple');rs=input('Enter the stopband ripple');fp=input('Enter the passband frequency');fs=input('Enter the stopband frequency');f=input('Enter the sampling frequency');

%outputwp=2*fp/f;ws=2*fs/f;num=-20*log(sqrt(rp*rs))-13;dem=14.6*(fs-fp)/f;n=ceil(num/dem);n1=n+1;if(rem(n,2)~=0);n1=n;n=n-1;endy=hamming(n1);

%low pass filterb=fir1(n,wp,y);[h,o]=freqz(b,1,256);m=20*log10(abs(h));subplot(2,2,1);plot(o/pi,m);title('low pass filter');ylabel('gain in db--->');xlabel('(a) normalized frequency--->');

%high pass filterb=fir1(n,wp,'high',y);[h,o]=freqz(b,1,256);m=20*log10(abs(h));subplot(2,2,2);plot(o/pi,m);title('high pass filter');ylabel('gain in db--->');xlabel('(b) normalized frequency--->');

%band pass filterwn=[wp,ws];b=fir1(n,wn,y);[h,o]=freqz(b,1,256);m=20*log10(abs(h));subplot(2,2,3);

Page 44: DSP Manual

plot(o/pi,m);title('band pass filter');ylabel('gain in db--->');xlabel('(c) normalized frequency--->');

%band stop filterb=fir1(n,wn,'stop',y);[h,o]=freqz(b,1,256);m=20*log10(abs(h));subplot(2,2,4);plot(o/pi,m);title('band stop filter');ylabel('gain in db--->');xlabel('(d) normalized frequency--->');

RESULT:

Thus the design of hamming window has been done and verified.

HANNING WINDOW

AIM:

To write a program to design a Hanning window sequence.

ALGORTHIM:

1. Clear2. Clear all3. Close all

Page 45: DSP Manual

4. Get the pass band and stop band ripples.5. Get the pass band and stop band frequencies.6. Get the sampling frequency.7. Find the filter co – efficient.8. Calculate the values of the hanning window sequence for each low

pass, high pass, band pass and band stop filter.9. Plot the graphs.10. Label the graphs.11. Stop.

Enter the passband ripple0.05Enter the stopband ripple0.04Enter the passband frequency1200Enter the stopband frequency2400Enter the sampling frequency9000>>

Page 46: DSP Manual

0 0.5 1-150

-100

-50

0

50low pass filter

gain

in d

b---

>

(a) normalized frequency--->0 0.5 1

-100

-50

0

50high pass filter

gain

in d

b---

>

(b) normalized frequency--->

0 0.5 1-150

-100

-50

0band pass filter

gain

in d

b---

>

(c) normalized frequency--->0 0.5 1

-80

-60

-40

-20

0

20band stop filter

gain

in d

b---

>

(d) normalized frequency--->

%%%%%%%%%HANNING WINDOW%%%%%%%%%%%

%CLEAR THE SCREENclcclear all;close all;

%inputrp=input('Enter the passband ripple');rs=input('Enter the stopband ripple');fp=input('Enter the passband frequency');

Page 47: DSP Manual

fs=input('Enter the stopband frequency');f=input('Enter the sampling frequency');

%outputwp=2*fp/f;ws=2*fs/f;num=-20*log(sqrt(rp*rs))-13;dem=14.6*(fs-fp)/f;n=ceil(num/dem);n1=n+1;if(rem(n,2)~=0);n1=n;n=n-1;endy=hanning(n1);

%low pass filterb=fir1(n,wp,y);[h,o]=freqz(b,1,256);m=20*log10(abs(h));subplot(2,2,1);plot(o/pi,m);title('low pass filter');ylabel('gain in db--->');xlabel('(a) normalized frequency--->');

%high pass filterb=fir1(n,wp,'high',y);[h,o]=freqz(b,1,256);m=20*log10(abs(h));subplot(2,2,2);plot(o/pi,m);title('high pass filter');ylabel('gain in db--->');xlabel('(b) normalized frequency--->');

%band pass filterwn=[wp,ws];b=fir1(n,wn,y);[h,o]=freqz(b,1,256);m=20*log10(abs(h));subplot(2,2,3);plot(o/pi,m);title('band pass filter');ylabel('gain in db--->');xlabel('(c) normalized frequency--->');

Page 48: DSP Manual

%band stop filterb=fir1(n,wn,'stop',y);[h,o]=freqz(b,1,256);m=20*log10(abs(h));subplot(2,2,4);plot(o/pi,m);title('band stop filter');ylabel('gain in db--->');xlabel('(d) normalized frequency--->');

RESULT:

Thus the design of hanning window has been done and verified.

KAISER WINDOW

AIM:

To write a program to design a Kaiser window sequence.

ALGORTHIM:

1. Clear2. Clear all3. Close all

Page 49: DSP Manual

4. Get the pass band and stop band ripples.5. Get the pass band and stop band frequencies.6. Get the sampling frequency.7. Find the filter co – efficient.8. Calculate the values of the Kaiser window sequence for each low pass,

high pass, band pass and band stop filter.9. Plot the graphs.10. Label the graphs.11. Stop.

Enter the passband ripple0.05Enter the stopband ripple0.04Enter the passband frequency1200Enter the stopband frequency2400Enter the sampling frequency9000Enter the beta value6

Page 50: DSP Manual

0 0.5 1-150

-100

-50

0

50low pass filter

gain

in d

b---

>

(a) normalized frequency--->0 0.5 1

-100

-50

0

50high pass filter

gain

in d

b---

>

(b) normalized frequency--->

0 0.5 1-150

-100

-50

0band pass filter

gain

in d

b---

>

(c) normalized frequency--->0 0.5 1

-40

-30

-20

-10

0

10band stop filter

gain

in d

b---

>

(d) normalized frequency--->

%%%%%%%%%%%%KAISER WINDOW%%%%%%%%%%

%CLEAR THE SCREENclc;clear all;close all;

%inputrp=input('enter the passband ripple');rs=input('enter the stopband ripple');fp=input('enter the passband frequency');

Page 51: DSP Manual

fs=input('enter the stopband frequency');f=input('enter the sampling frequency');beta=input('enter the beta value');

%outputwp=2*fp/f;ws=2*fs/f;num=-20*log(sqrt(rp*rs))-13;dem=14.6*(fs-fp)/f;n=ceil(num/dem);n1=n+1;if(rem(n,2)~=0);n1=n;n=n-1;endy=kaiser(n1,beta);

%low pass filterb=fir1(n,wp,y);[h,o]=freqz(b,1,256);m=20*log10(abs(h));subplot(2,2,1);plot(o/pi,m);title('low pass filter');ylabel('gain in db--->');xlabel('(a) normalized frequency--->');

%high pass filterb=fir1(n,wp,'high',y);[h,o]=freqz(b,1,256);m=20*log10(abs(h));subplot(2,2,2);plot(o/pi,m);title('high pass filter');ylabel('gain in db--->');xlabel('(b) normalized frequency--->');

%band pass filterwn=[wp,ws];b=fir1(n,wn,y);[h,o]=freqz(b,1,256);m=20*log10(abs(h));subplot(2,2,3);plot(o/pi,m);title('band pass filter');ylabel('gain in db--->');xlabel('(c) normalized frequency--->');

Page 52: DSP Manual

%band stop filterb=fir1(n,wn,'stop',y);[h,o]=freqz(b,1,256);m=20*log10(abs(h));subplot(2,2,4);plot(o/pi,m);title('band stop filter');ylabel('gain in db--->');xlabel('(d) normalized frequency--->');

RESULT:

Thus the design of Kaiser window has been done and verified.

FAST FOURIER TRANSFORM

AIM:

To write a program for finding fast fourier transform.

ALGORTHIM:

1. Clear2. Clear all3. Close all4. Get the input sequences in matrix form.

Page 53: DSP Manual

5. Calculate the length.6. Apply the inputs in the given formula

1. X(k) = Σ x(n) e –jл2nk / N

7. Plot the graphs.8. Label the graphs.9. Stop.

Enter the sequence[1 2 3 4 5 6]enter the length of fft 6the resultant output is

y =

21.0000 -3.0000 + 5.1962i -3.0000 + 1.7321i -3.0000 -3.0000 - 1.7321i -3.0000 - 5.1962i

>>

Page 54: DSP Manual

-5 0 5 10 15 20 25-6

-4

-2

0

2

4

6

Imag

inar

y ax

is--

>

Real axis-->

%%%%%%%%%FAST FOURIER TRANSFORM%%%%%%%%%%

%CLEAR THE SCREEN

clc;close all;clear all;

%INPUTx=input('enter the sequence');n=input('enter the length of fft');

Page 55: DSP Manual

%OUTPUTy=fft(x,n);

%PLOT THE GRAPHstem(y);

%LABEL THE GRAPHylabel('Imaginary axis-->');xlabel('Real axis-->');

disp('the resultant output is');y

RESULT:

Thus the program for fast fourier transform has been done and verified.

SAMPLING OF SIGNALS

AIM:

To write a program for sampling of signals.

ALGORTHIM:

1. Clear2. Clear all3. Close all4. Compute the signal modulated, carrier, and amplitude modulated

signal.

Page 56: DSP Manual

5. Compute the 128 point DFT computation of the signal.6. Plot the signals7. Label the signals.8. Stop

Page 57: DSP Manual

0 100 200 300-2

-1

0

1

2Modulated Signal x(n)

n-->

ampl

itude

0 100 200 300-1

-0.5

0

0.5

1Carrier Signal xa(n)

n-->

ampl

itude

0 100 200 300-2

-1

0

1

2Amplitude modulated Signal xam(n)

n-->

ampl

itude

Page 58: DSP Manual

0 20 40 60 80 100 120 140-5

0

5

10

15

20

25

30

35128 point DFT of the signal for 0 ? n ? 127 xamp(n)

n-->

ampl

itude

0 20 40 60 80 100 120 140-15

-10

-5

0

5

10

15

20

25

30128 point DFT of the signal for 0 ? n ? 99 xam(n)

n-->

ampl

itude

%%%%%%%%%%SAMPLING OF SIGNALS%%%%%%%%

Page 59: DSP Manual

clc;close all;clear all;f1=1/128;f2=5/128;n=0:255;fc=50/128;x=cos(2*pi*f1*n)+cos(2*pi*f2*n);xa=cos(2*pi*fc*n);xamp=x.*xa;subplot(2,2,1);plot(n,x);title('Modulated Signal x(n)');xlabel('n-->');ylabel('amplitude');

subplot(2,2,2);plot(n,xa);title('Carrier Signal xa(n)');xlabel('n-->');ylabel('amplitude');

subplot(2,2,3);plot(n,xamp);title('Amplitude modulated Signal xam(n)')xlabel('n-->');ylabel('amplitude');

%128 point DFT of the signal for 0 ≤ n ≤ 127n=0:127;figure;n1=128;f1=1/128;f2=5/128;fc=50/128;x=cos(2*pi*f1*n)+cos(2*pi*f2*n);xc=cos(2*pi*fc*n);xa=cos(2*pi*fc*n);xamp=x.*xa;xam=fft(xamp,n1);stem(n,xam);title('128 point DFT of the signal for 0 ≤ n ≤ 127 xamp(n)');xlabel('n-->');ylabel('amplitude');

%128 point DFT of the signal for 0 ≤ n ≤ 99n=0:99;figure;n2=0:n1-1;

Page 60: DSP Manual

f1=1/128;f2=5/128;fc=50/128;x=cos(2*pi*f1*n)+cos(2*pi*f2*n);xc=cos(2*pi*fc*n);xa=cos(2*pi*fc*n);xamp=x.*xa;for i=1:100;xamp1(i)=xamp(i);endxam=fft(xamp1,n1);stem(n2,xam);title('128 point DFT of the signal for 0 ≤ n ≤ 99 xam(n)');xlabel('n-->');ylabel('amplitude');

RESULT:

Thus the program for sampling of signals has been done and verified.

Page 61: DSP Manual

STUDY OF VARIOUS ADDRESSING MODES OF DSP USING SIMPLE PROGRAMMING EXAMPLES

AIM:

To write a program to perform addition, Subtraction, Multiplication and division operations using TMS320c5416 Processor.

1.ADDITIONALGORTHIM:

1. Initialize the memory for input & output.2. Load the memory with data pointer.3. Perform the addition operation.4. Store the result.5. End.

PROGRAM:INP1 .SET 0HINP2 .SET 1HOUT .SET 2H

.mmregs

.textSTART:

LD #140H , DPRSBX CPLNOPNOPNOPNOPLD INP1,AADD INP2,ASTL A,OUT

HLT: B HLT

OUTPUT :

SD A000 Substitute Data A000:05C0-0003 Substitute Data A001:0003-0003 Substitute Data A002:1000-.

#GO 0000Executing.... Vi Microsystems Pvt. Ltd. Chennai - 96 Micro5416 Serial Monitor#SD A002

Substitute Data A002:0006-2.SUBTRACTION

Page 62: DSP Manual

ALGORTHIM:

1. Initialize the memory for input & output.2. Load the memory with data pointer.3. Perform the Subtraction operation.4. Store the result.5. End.

PROGRAM:INP1 .SET 0HINP2 .SET 1HOUT .SET 2H

.mmregs

.text

START:LD #140H , DPRSBX CPLNOPNOPNOPNOPLD INP1,ASUB INP2,ASTL A,OUT

HLT: B HLT

OUTPUT:

SD A000

Substitute Data A000:0003-0006 Substitute Data A001:0003-0002 Substitute Data A002:0006-.

#GO 0000Executing....

Vi Microsystems Pvt. Ltd. Chennai - 96

Micro5416 Serial Monitor

#SD A002

Substitute Data A002:0004-

3. MULTIPLICATION

Page 63: DSP Manual

ALGORTHIM:

1. Initialize the memory for input & output.2. Load the memory with data pointer.3. Perform the multiplication operation.4. Store the result.5. End.

PROGRAM:

.mmregs

.text

START:

STM #140H,ST0STM #40H, PMSTSTM #0A000H,AR0ST #2H,*AR0LD *AR0+,TST #4H,*AR0MPY *AR0+,ASTL A,*AR0

HLT: B HLT

OUTPUT:GO 0000Executing....

Vi Microsystems Pvt. Ltd. Chennai - 96

Micro5416 Serial Monitor

#SD A002

Substitute Data A002:0008-

4.DIVISIONALGORTHIM:

Page 64: DSP Manual

1. Initialize the memory for input & output.2. Load the memory with data pointer.3. Perform the division operation.4. Store the result.5. End.

PROGRAM:

DIVID .SET 0HDIVIS .SET 1HOUT .SET 2H

.mmregs

.textSTART:

STM #140H,ST0RSBX CPLRSBX FRCTNOPNOPNOPNOPLD DIVID,ARPT #0FHSUBC DIVIS,ASTL A, OUT

HLT: B HLT

OUTPUT:SD A000

Substitute Data A000:0002-0004 Substitute Data A001:0004-0002 Substitute Data A002:0008-.

#GO 0000Executing.... Vi Microsystems Pvt. Ltd. Chennai - 96 Micro5416 Serial Monitor#SD A002

Substitute Data A002:0002-

RESULT:

Thus the programs for addition, subtraction, multiplication and division operations are executed successfully using DSP processor

TRIANGULAR WAVE GENERATIONAIM:

Page 65: DSP Manual

To write a program for triangular wave generation using TMs320C5416 processor.

ALGORTHIM:

1. Initialize the value.2. Generate the loop to increment the value.3. Generate the loop to decrement the value.4. Store the data in the required memory place.5. End

PROGRAM:

DATA .SET 0H.mmREGS.text

START:STM #140H,ST0RSBX CPLNOPNOPNOPNOPNOP

REP:ST #0H,DATA

INC:LD DATA,AADD #1H,ASTL A, DATAPORTW DATA, #04HCMPM DATA, #0FFFFHBC INC,NTC

DEC:LD DATA,ASUB #1H,ASTL A,DATAPORTW DATA, #04HCMPM DATA,#00HBC DEC,NTCB REP

RESULT:

Thus the program for triangular wave generation was executed successfully.

8-POINT FAST FOURIER TRANSFORM

Page 66: DSP Manual

AIM:To write a program for 8-point FFT using TMS320C5416 processor.

ALGORTHIM:

1. Initialize the memory for input and output.2. Get the inputs in the memory location A200.3. Perform FFT operation.4. Store the results in A400 memory location.5. End

PROGRAM:

INPUT .SET 9200HREV .SET 9300HINC .SET 9400HTWIDC .SET 9500HTWIDS .SET 9550HBFY .SET 0HBFYC .SET 1HDNS .SET 2HDNSC .SET 3HGRP .SET 4HGRPC .SET 5HSTG .SET 6HSTGC .SET 7HK .SET 8HINCTF .SET 9HAX .SET 0AHBX .SET 0BHCX .SET 0CHDX .SET 0DHACMBD .SET 0EHADPBC .SET 0FHAR10 .SET 10HAR11 .SET 11HAR12 .SET 12HAR13 .SET 13HAR14 .SET 14HATEMP .SET 15HBTEMP .SET 16H

.mmregs .textSTART: STM #40H,PMST RSBX CPL STM #120H,ST0 RSBX FRCT NOP

Page 67: DSP Manual

NOP CALL BIT_REV CALL INCLUDE ST #1H,BFY ST #4H,GRP ST #2H,DNS ST #3H,STG LD STG,A SUB #1H,A STL A,STGC

STM #TWIDC,AR0 RPT #3H MVPD TABCOS,*AR0+

STM #TWIDS,AR0 RPT #3H MVPD TABSIN,*AR0+ STM #2H,AR5 ;AR5 = STAGE LOOPSTGLOP: ST #0H,K LD BFY,A SUB #1H,A STL A,BFYC LD GRP,A SUB #1H,A STL A,GRPC LD DNS,A STLM A,AR0 SUB #1H,A STL A,DNSC LD DNSC,A LD GRP,A CMPM GRP,#4H ;N/2=8/2=4H BC NO_CHG,NTC LD #0H,ANO_CHG: STL A,INCTF LD GRPC,A STLM A,AR3 ;AR3 = GROUP LOOP STM #INC,AR1GRPLOP: ST #0H,K ;k is initially 0 in all groups LD BFYC,A STLM A,AR4 ;AR4 = BFLY LOOPBFYLOP: LD *AR1+0,A CALL MUL LD DNS,A STLM A,AR0

Page 68: DSP Manual

LD *AR1-0,A CALL ADDSUB LD K,A ADD INCTF,A STL A,K BANZ BFYLOP,*AR4- LD DNS,A STLM A,AR0 LD *AR1+0,A BANZ GRPLOP,*AR3- MPY BFY,#2,A ;BFY * 2 = BFY STL A,BFY MPY DNS,#2,A ;DNS * 2 = DNS STL A,DNS STLM A,AR0 LD GRP,A STL A,-1,GRP ;GRP / 2 = GRP BANZ STGLOP,*AR5-HLT: B HLT

MUL: STM #TWIDC,AR2 LD K,A STLM A,AR0 NOP NOP LD *AR2+0,A LD *AR2,A STL A,CX STM #TWIDS,AR2 LD K,A STLM A,AR0 LD *AR2+0,A LD *AR2,A STL A,DX LD *AR1+,A STL A,AX LD *AR1-,A STL A,BX LD AX,A STLM A,T MPY CX,A ;A*C LD BX,B STLM B,T MPY DX,B ;B*D SUB B,A ;AC-BD -> A STL A,-8,ACMBD LD AX,A STLM A,T MPY DX,A ;A*D

Page 69: DSP Manual

LD BX,B STLM B,T MPY CX,B ;B*C ADD A,B ;AD+BC -> B STL B,-8,ADPBC LD ACMBD,A STL A,*AR1+ LD ADPBC,A STL A,*AR1- LD DNS,A STLM A,AR0 RET

ADDSUB: LD *AR1+0,A STL A,ATEMP LD *AR1-0,B STL B,BTEMP ADD A,B STL B,*AR1 LD ATEMP,A SUB BTEMP,A LD *AR1+0,B STL A,*AR1-0 LD *AR1+,A LD *AR1+0,A STL A,ATEMP LD *AR1-0,B STL B,BTEMP ADD A,B STL B,*AR1 LD ATEMP,A SUB BTEMP,A LD *AR1+0,B STL A,*AR1-0 LD *AR1-,A LD *+AR1(2),A LDM AR1,A STL A,AR10 RETBIT_REV: STM #INPUT,AR4 STM #REV,AR5 STM #4H,AR0 ;N/2 STM #7H,BRC ;N-1 RPTB REPREV LD *AR4+0B,A

REPREV: STL A,*AR5+ RET

Page 70: DSP Manual

INCLUDE: STM #REV,AR1 STM #INC,AR2 STM #7H,BRC RPTB REPINC LD *AR1+,A STL A,*AR2+ LD #0H,AREPINC: STL A,*AR2+ RET TABCOS: .word 00100H .word 000B5H .word 00000H .word 0FF4BHTABSIN: .word 00000H .word 0FF4BH .word 0FF00H .word 0FF4BH

RESULT:

Thus the program for 8-point FFT was executed successfully.

Page 71: DSP Manual

OUTPUT:

SD 0A200

Substitute Data A200:E055-0700 Substitute Data A201:EBAA-0B00 Substitute Data A202:B055-0F00 Substitute Data A203:F7AA-0B00 Substitute Data A204:8055-0700 Substitute Data A205:FBAA-0300 Substitute Data A206:9255-0000 Substitute Data A207:AFAA-0300 Substitute Data A208:DFAA-.

#GO 0000Executing.... Vi Microsystems Pvt. Ltd. Chennai - 96

Micro5416 Serial Monitor

#SD A400

Substitute Data A400:3900- Substitute Data A401:0000- Substitute Data A402:0000- Substitute Data A403:E5B0- Substitute Data A404:FF00- Substitute Data A405:0000- Substitute Data A406:0000- Substitute Data A407:03B0- Substitute Data A408:0100- Substitute Data A409:0000- Substitute Data A40A:0000- Substitute Data A40B:FC50- Substitute Data A40C:FF00- Substitute Data A40D:0000- Substitute Data A40E:0000-.

FIR FILTER DESIGN(HIGH PASS FIR FILTER)

Page 72: DSP Manual

AIM:

To write a program to design a FIR high pass filter using TMS320C5416 processor with the following specifications.

Sampling freq : 43khzCut-off freq : 2khzN : 52Filter type : High pass filterWindow type : Rectangular

ALGORTHIM:

1. Make all the x(n) zero initially2. Read the data from the adc.3. Store the adc data in x(0)4. Make the pointer to point the x(n_end)5. Perform the convolution of x(n) and the coefficients h(n) using MACD instruction.6. Send the convolution output to the dac7. Repeat from step 2.

PROGRAM:

.mmregs .textSTART: STM #01h,ST0 ;intialize the data page pointer RSBX CPL ;Make the processor to work using DP RSBX FRCT ;reset the fractional mode bit NOP NOP;*****loop to make all x(n) zero initially***** STM #150H,AR1 ;initialize ar1 to point to x(n) LD #0H,A ;make acc zero RPT #34H STL A,*AR1+ ;make all x(n) zero

;*****to read the adc data and store it in x(0)*****LOOP: PORTR 06,0 ;start of conversion

CHK_BUSY: PORTR 07,0 ;check for busy BITF 0,#20H BC CHK_BUSY,TC PORTR 04,0 ;read the adc data LD 0,A AND #0FFFH,A ;AND adc data with 0fffh for 12 bit adc XOR #0800H,A ;recorrect the 2's complement adc data

Page 73: DSP Manual

SUB #800H,A ;remove the dc shift STM #150H,AR1 ;initialize ar1 with x(0) STL A,*AR1 ;store adc data in x(0) STM #183H,AR2 ;initialize ar2 with x(n_end);*****start of convolution***** LD #0H,A ;sum is 0 initially RPT #33H MACD *AR2-,TABLE,A ;convolution process STH A,1,0H LD 0H,A ADD #800H,A ;add the dc shift to the convolution output STL A,1H PORTW 1H,04H ;send the output to the dac B LOOP

TABLE: .word 0FCEFH .word 62H .word 0FD50H .word 14AH .word 0FE1BH .word 28FH .word 0FF11H .word 3E5H .word 0FFD1H .word 4ECH .word 0FFF5H .word 54FH .word 0FF28H .word 4DAH .word 0FD38H .word 398H .word 0FA2EH .word 1DDH .word 0F627H .word 55H .word 0F131H .word 4BH .word 0EA6DH .word 568H .word 0D950H .word 459EH .word 459EH .word 0D950H .word 568H .word 0EA6DH .word 4BH .word 0F131H .word 55H .word 0F627H

Page 74: DSP Manual

.word 1DDH .word 0FA2EH .word 398H .word 0FD38H .word 4DAH .word 0FF28H .word 54FH .word 0FFF5H .word 4ECH .word 0FFD1H .word 3E5H .word 0FF11H .word 28FH .word 0FE1BH .word 14AH .word 0FD50H .word 62H .word 0FCEFH

RESULT:

Thus the program for FIR high pass filter was executed successfully.

Page 75: DSP Manual

SAMPLING OF SIGNALS

AIM:

To write a program for sampling of signals using TMS320C5416 processor.

PROGRAM:

B3 .SET 0F000HB2 .SET 0F00HB1 .SET 00F0HB0 .SET 000FHDATA .SET 0HTXD .SET 1HFS .SET 2H

.mmregs .textSTART: STM #0140h,ST0 RSBX CPL RSBX FRCT NOP NOP NOP NOP STM #9200H,AR1 STM #360,AR2 ST #01H,10H PORTW 10H,0AHLOOP: PORTR 06,0CHK_BUSY: ST #02H,10H PORTW 10H,0AH PORTR 07,0 BITF 0,#20H BC CHK_BUSY,TC ST #04H,10H PORTW 10H,0AH PORTR 04,0 LD 0,A AND #0FFFH,A XOR #0800H,A STL A,*AR1+ ST #1000H,FS RPT FS NOP BANZ LOOP,*AR2-

Page 76: DSP Manual

REPSER: LD #25H,A CALL TXDATA STM #0140h,ST0 RSBX CPL NOP NOP NOP NOP LD FS,A STL A,DATA CALL SERIAL STM #259,AR7 STM #9200H,AR6REPYN: ST #55H,10H PORTW 10H,0AH LD *AR6+,A STL A,DATA CALL SERIAL BANZ REPYN,*AR7- LD #40H,A CALL TXDATA STM #0140h,ST0 RSBX CPL NOP NOP NOP NOP ; CALL DELAY B REPSERSERIAL: LD DATA,A AND #B3,A ;1st digit (from msb) SFTL A,-12 CALL HEXASC CALL TXDATA STM #0140h,ST0 RSBX CPL NOP NOP NOP NOP ; CALL DELAY LD DATA,A AND #B2,A ;1st digit (from msb) SFTL A,-8 CALL HEXASC CALL TXDATA STM #0140h,ST0

Page 77: DSP Manual

RSBX CPL NOP NOP NOP NOP ; CALL DELAY LD DATA,A AND #B1,A ;1st digit (from msb) SFTL A,-4 CALL HEXASC CALL TXDATA STM #0140h,ST0 RSBX CPL NOP NOP NOP NOP ; CALL DELAY LD DATA,A AND #B0,A ;1st digit (from msb) CALL HEXASC CALL TXDATA STM #0140h,ST0 RSBX CPL NOP NOP NOP NOP ; CALL DELAY RETHEXASC: ADD #30H,A LD A,B SUB #3AH,B BC LESS9,BLT ADD #7H,ALESS9: RETTXDATA: CALL 8C41H ; 8C38H for 5416 mode 1 SSBX INTM rpt #2ffh ;delay nop RETDELAY: STM #0H,AR3DEL1: STM #02FFFH,AR2DEL: LD #0H,A ADD #1H,A BANZ DEL,*AR2-

Page 78: DSP Manual

BANZ DEL1,*AR3- RET

RESULT:

Thus the program for Sampling of signals was executed successfully.

IIR FILTER DESIGN(HIGH PASS FIR FILTER)

Page 79: DSP Manual

AIM:

To write a program to design an IIR butterworth filter using TMS320C5416 processor with the following specifications.

Filter type : High pass filterFilter order : 2Filter design type : ButterworthPass band attenuation : 3dbFirst corner freq : 0.2Second corner freq : 0.24Sampling freq : 50KhzCut-off freq : 10Khz

ALGORTHIM:

1. Make all the x(n) zero initially2. Read the data from the adc.3. Store the adc data.4. Make the pointer to point the x(n_end)5. Perform the convolution of x(n) and the coefficients h(n) 6. Send the convolution output to the dac7. End

PROGRAM:

;FROM PCDSP COEFFICIENTS

XN .SET 0HXNM1 .SET 1HXNM2 .SET 2HYN .SET 3HYNM1 .SET 4HYNM2 .SET 5HXN1 .SET 6HXN1M1 .SET 7HXN1M2 .SET 8HYN1 .SET 9HYN1M1 .SET 0AHYN1M2 .SET 0BHTEMP .SET 0CHA10 .SET 0100HA11 .SET 0FFEDHA12 .SET 002CHB10 .SET 0100HB11 .SET 0FE00HB12 .SET 0100H .mmregs

Page 80: DSP Manual

.textSTART: STM #40H,PMST RSBX CPL STM #01H,ST0 RSBX FRCT NOP NOP NOP;initialize xn,x(n-1),x(n-2),yn,y(n-1),y(n-2) ST #0H,XN ST #0H,XNM1 ST #0H,XNM2 ST #0H,YN ST #0H,YNM1 ST #0H,YNM2 ST #0H,XN1 ST #0H,XN1M1 ST #0H,XN1M2 ST #0H,YN1 ST #0H,YN1M1 ST #0H,YN1M2REPEAT:;to read data from ADC PORTR 06,20 ;start of conversionCHK_BUSY: ;check status PORTR 07,20 BITF 20,#20H BC CHK_BUSY,TC PORTR 04,20 ;read ADC data LD 20,A AND #0FFFH,A XOR #0800H,A ;to correct 2's complement SUB #800H,A STL A,XN ;xn STL A,TEMP; LD #0H,B ;sum = B = 0 LD #B10,A ;b0 = T STLM A,T MPY XN,A ;b0*xn = A SFTL A,-8 ADD A,B ;b0*xn =B

LD #B11,A ;b0 = T STLM A,T MPY XNM1,A ;b0*xn = A SFTL A,-8 ADD A,B ;b0*xn =B

Page 81: DSP Manual

LD #B12,A ;b0 = T STLM A,T MPY XNM2,A ;b0*xn = A SFTL A,-8 ADD A,B ;b0*xn =B

LD #A11,A ;b0 = T STLM A,T MPY YNM1,A ;b0*xn = A SFTL A,-8 SUB A,B ;b0*xn =B

LD #A12,A ;b0 = T STLM A,T MPY YNM2,A ;b0*xn = A SFTL A,-8 SUB A,B ;b0*xn =B STL B,YN STL B,XN1

LD YNM1,A STL A,YNM2 LD YN,A STL A,YNM1 LD XNM1,A STL A,XNM2 LD XN,A STL A,XNM1

LD YN,A ADD #800H,A STL A,YN PORTW YN,04H B REPEAT

RESULT:

Thus the program for IIR butterworth filter was executed successfully.

Page 82: DSP Manual
Page 83: DSP Manual
Page 84: DSP Manual