+ All Categories
Home > Documents > DSP lab manual

DSP lab manual

Date post: 25-Oct-2015
Category:
Upload: lwonders
View: 95 times
Download: 1 times
Share this document with a friend
Description:
matlab tms320c50 ccstudio c6713 programs
Popular Tags:
78
MODULATION TECHNIQUES Ex. No: Date: AIM: To perform digital modulation using MATLAB. (a) ASK (b) FSK (c) PSK (d)AM (e)FM ALGORITHM: 1. Start the program. 2. Get the input bit sequence to be modulated as input 3. Calculate the length of the sequence. 4. Generate the carrier waveform for different values of amplitude, frequency and phase. 5. Generate the carrier waveform for the corresponding binary value. 6. Plot the input and output waveform. 7. Stop
Transcript
Page 1: DSP lab manual

MODULATION TECHNIQUES

Ex. No:

Date:

AIM:

To perform digital modulation using MATLAB. (a) ASK

(b) FSK

(c) PSK

(d)AM

(e)FM

ALGORITHM:

1. Start the program.

2. Get the input bit sequence to be modulated as input

3. Calculate the length of the sequence.

4. Generate the carrier waveform for different values of amplitude, frequency and phase.

5. Generate the carrier waveform for the corresponding binary value.

6. Plot the input and output waveform.

7. Stop

ResultThus the programs for digital modulation techniques(ASK,FSK, PSK,AM & FM) are written and executed using MatLab.

Page 2: DSP lab manual

PROGRAM

% Amplitude Shift Keyingclcclear allclose allx=input('Enter the input bit sequence: ');t=0:length(x) - 1;subplot(2,1,1);stairs(t,x);axis([0 length(x) -2 2]);title('Input');grid on;t1=0:0.01:1;s1=sin(2*pi*6*t1);L=length(t1)*length(x);i=1;for j=1:length(x) if(x(j)==1) for k=1:length(t1) y(i)=s1(k); i=i+1; end else for k=1:length(t1) y(i)=0; i=i+1; end endendt2=0:(length(x)/(L-1)):length(x);subplot(2,1,2);plot(t2,y);title('ASK output');

Page 3: DSP lab manual

OUTPUT

Enter the input bit sequence: [1 0 1 1 0]

Page 4: DSP lab manual

PROGRAM

%Frequency Shift Keyingclc; clear all; close all;x=input('Enter the bits within square brackets:');t=0:length(x)-1;subplot(2,1,1),stairs(t,x);axis([0 length(x) -2 2]);grid on;title('input sequence');t1=0:0.001:1;s1=sin((2*pi*6*t1));s2=sin((2*pi*3*t1));L=length(t1)*length(x);i=1;for j=1:length(x)if (x(j)==0)for k=1:length(s1)y(i)=s1(k);i=i+1;endelsefor k=1:length(s2)y(i)=s2(k);i=i+1;endendendt2=0:(length(x)/(L-1)):length(x);subplot(2,1,2),plot(t2,y);axis([0 length(x) -2 2]);grid on;title('FSK output');

Page 5: DSP lab manual

OUTPUT

Enter the bits within square brackets:[1 0 1 0]

Page 6: DSP lab manual

PROGRAM

%Phase Shift Keyingclc;clear all;close all;x=input('Enter the bits within square brackets:');t=0:length(x)-1;subplot(2,1,1),stairs(t,x);axis([0 length(x) -2 2]);grid on;title('Input sequence');t1=0:0.001:1;s1=sin(2*pi*6*t1);s2=sin((2*pi*6*t1)+pi);L=length(t1)*length(x);i=1;for j=1:length(x)if(x(j)==0)for k=1:length(s1)y(i)=s1(k);i=i+1;endelsefor k=1:length(s2)y(i)=s2(k);i=i+1;endendendt2=0:(length(x)/(L-1)):length(x);subplot(2,1,2),plot(t2,y);axis([0 length(x) -2 2]);grid on;title('PSK Output');

Page 7: DSP lab manual

OUTPUT

Enter the bits within square brackets:[1 1 0 0 1]

Page 8: DSP lab manual

%amplitute modulationclose all;clear all;em = input('enter signal amplitute:');ec = input('enter carrier amplitute:');fm = input('enter signal frequency in khz:');fc = input('enter carrier frequency in khz:');ma = em/ec;disp(ma);w0=(2*pi*fm);w1=(2*pi*fc);wu=w0+w1;wl=w1-w0;t = 0:0.001:2;E=em*cos(w0*t);C=ec*cos(w1*t);U=(ma*ec*cos(wu*t))/2;L=(ma*ec*cos(wl*t))/2;AM=C+L+U;title('message signal');subplot(3,1,1);plot(t,E);grid on;title('carrier signal');subplot(3,1,2);plot(t,C);grid on;title('am signal');subplot(3,1,3);plot(t,AM);grid on;

Page 9: DSP lab manual

%Frequency modulationclcclose all;clear all;fm = input('Enter signal frequency in khz:');fc = input('Enter carrier frequency in khz:');b=input('Enter the frequency deviation: ');t=0:0.001:10;c=cos(2*pi*fc*t);m=cos(2*pi*fm*t);%b=fc-fm;fsig=cos((2*pi*fc*t)+(b/fm)*cos(2*pi*fm*t));subplot(3,1,1)plot(t,m);title('Message Signal');xlabel('time');ylabel('amplitude');subplot(3,1,2)plot(t,c);title('Carrier Signal');xlabel('time');ylabel('amplitude');subplot(3,1,3)plot(t,fsig);title('Frequency Modulated Signal');xlabel('time');ylabel('amplitude');

Page 10: DSP lab manual

OUTPUTEnter signal frequency in khz:1Enter carrier frequency in khz:5Enter the frequency deviation: 2

Page 11: DSP lab manual

Spectrum estimation using Bartlett, Welch and Blackmann-Tukey method

Ex. No:

Date:

AIM:

To estimate the spectrum of the following using MATLAB (a) Welch

(b) Bartlett

(c) Blackmann - Turkey

ALGORITHM:

Welch

1. Start the program.

2. Get the input signal x, whose spectrum is to be estimated

3. Estimate the spectrum for the input x using pwelch[] function

4. If the function parameter ‘noverlap’ is made as zero, it is equivalent to Barlett method of spectrum estimation.

5. Plot the graph.

Bartlett

1. Start the program.

2. Get f1, f2 and the sampling frequency fs.

3. Compute f1 + f2 + random signal.

4. Sample the result of step 3 and perform FFT.

5. Calculate the magnitude and plot the graph.

Page 12: DSP lab manual

Blackmann - Turkey

1. Start the program.

2. Get f1, f2 and the sampling frequency fs.

3. Compute f1 + f2 + random signal.

4. Sample the result of step 3, perform autocorrelation of the signal and perform FFT.

5. Calculate the magnitude and plot the graph.

ResultThus spectrum estimation is done using Welch, Bartlett and Blackmann-Turkey method in MatLab.

Page 13: DSP lab manual

%Spectral analysis using periodogramclc;clear all;close all;f=input('Enter the input frequency: ');fs=input('Enter the sampling frequency: ');t = 0:1/fs:.3;x = sin(2*pi*t*f)+0.1*randn(size(t)); periodogram(x,[],'onesided',length(x),fs)

SAMPLE I/P:enter the input frequency:10enter the sampling frequency:100

PROGRAM%Power spectrum using welch method%Fs=1000;t=0:1/Fs:0.296;%A cosine of 200 Hz plus noisex=cos(2*pi*pi*t*200)+randn(size(t));%Uses default window,overlap & NFFTpwelch(x,[],[],[],Fs,'twosided');title('Powe spectrum using welch');

Page 14: DSP lab manual

PROGRAM

%power spectrum estimation using Barlett methodclc;close all;clear all;n=0:1000;c=sin(2*3.14*0.24*n)+sin(2*3.14*0.36*n)+ randn(size(n));subplot(2,1,1);plot(n,c);title('Signal with noise');nfft=512;noverlap=0;window=hamming(256);

[pxx,f]= psd(c,nfft,2,window,noverlap);subplot(2,1,2);plot(f/2,10*log10(pxx));title('Power Spectral Density');

OUTPUT

Page 15: DSP lab manual

PROGRAM%Power spectrum estimation Blackmann and Turkey Methodclc;clear all;clf;f1=input('Enter the first freq: ');f2=input('Enter the second freq: ');fs=input('Enter the sampling freq: ');t=0:1/fs:1;a=sin(2*3.14*f1*t)+sin(2*3.14*f2*t)+randn(size(t));subplot(2,1,1);plot(t,a);axis([0 1 -4 4]);title('Power spectrum input: ');rxx=xcorr(a);n=length(rxx);w=hanning(n);s=rxx.*w';pxx=fft(s);pxx=fftshift(pxx);mag=10*log10(abs(pxx));subplot(2,1,2);stem((-(n-1)/2:(n-1)/2)/(n/fs),mag);axis([-fs/2 fs/2 45 80]);title('Power spectrum estimation using blackmann turkey method: ');

Page 16: DSP lab manual

OUTPUTEnter the first freq: 500Enter the second freq: 1000Enter the sampling freq: 3000

Page 17: DSP lab manual

Hamming code generation and error correction

Ex. No:

Date:

AIM: To generate Hamming code generation and error correction in the transmitted sequence

using MATLAB.

ALGORITHM:

1. Start the program.

2. Get the input message bit sequence

3. Generate a matrix and parity check matrix for corresponding cross bits using hammgen()

function.

4. Form the decode table to calculate the syndrome.

5. If any error occurred, it is corrected by received code word.

6. Stop.

ResultThus Hamming-code is generated and error correction in the transmitted sequence is done using MatLab.

Page 18: DSP lab manual

PROGRAM

%hamming codeclc;clear all;m=input('Enter the 4 bits to be transmitted: ');g=[1 1 0 1 0 0 0;0 1 1 0 1 0 0;1 1 1 0 0 1 0;1 0 1 0 0 0 1];h=[1 0 0 1 0 1 1;0 1 0 1 1 1 0;0 0 1 0 1 1 1];disp('Generator matrix: ');disp(g);disp('H matrix: ');disp(h);x=m*g;y=mod(x,2);disp('y:');disp(y);ht=h.';cr=input('Enter the corrupted code: ');s=cr*ht;sm=mod(s,2);disp('Syndrome: ');disp(sm);q=[0 0 0;0 0 1; 0 1 0;0 1 1;1 0 0;1 0 1; 1 1 0; 1 1 1];e=[0 0 0 0 0 0 0;1 0 0 0 0 0 0;0 1 0 0 0 0 0;0 0 1 0 0 0 0;0 0 0 1 0 0

0;0 0 0 0 1 0 0;0 0 0 0 0 1 0;0 0 0 0 0 0 1];disp('q:');disp(q);disp('e:');disp(e);for i=1 :7l=0;for j=1 :3if sm(1,j)== q(i,j)l=l+1;endendif l==3p=i-1;break;end endfprintf('Error in the %d position',p );cr(p)=not(cr(p));disp('Corrected Code');disp(cr);

Page 19: DSP lab manual

OUTPUT

Enter the 4 bits to be transmitted: [1 1 1 1]Generator matrix: 1 1 0 1 0 0 0 0 1 1 0 1 0 0 1 1 1 0 0 1 0 1 0 1 0 0 0 1

H matrix: 1 0 0 1 0 1 1 0 1 0 1 1 1 0 0 0 1 0 1 1 1

y: 1 1 1 1 1 1 1

Enter the corrupted code: [1 0 1 1 1 1 1]Syndrome: 0 1 0

q: 0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1

e: 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1

Error in the 2 positionCorrected Code 1 1 1 1 1 1 1

Page 20: DSP lab manual

Discrete Cosine Transform (DCT) and Inverse Discrete Cosine Transform (IDCT).

Ex. No:

Date:

AIM: To perform DCT and IDCT using MATLAB

ALGORITHM:

1. Start

2. Read an image and display the same

3. Find the cosine transform of the image

4. Find the inverse discrete cosine transform

5. Show the resultant Image and reconstructed image

6. Stop.

Result: Thus DCT and IDCT of an image is done using MatLab.

Page 21: DSP lab manual

PROGRAM

%Discrete and inverse Discrete Cosine transforms of an imagea=imread('baboon.jpg');subplot(3,1,1);imshow(a,[]);title('Original Image');b=dct2(a);subplot(3,1,2);imshow(b);title('DCT');c=idct2(b);subplot(3,1,3)imshow(c,[]);title('Inverse DCT');

OUTPUT

Page 22: DSP lab manual

Histogram equalization

Ex. No:

Date:

AIM:

To perform histogram equalization using MATLAB

ALGORITHM:

1. Start

2. Read an image and display the same

3. Find the histogram of the image

4. Find the histogram equalization of the input image

5. Show the resultant Image and reconstructed image

6. Stop.

ResultThus Histogram equalization of the given image is done using MatLab.

Page 23: DSP lab manual

PROGRAM

clc;clear all;close all;subplot(4,1,1);a=imread('baboon.jpg');imshow(a);title('original image');subplot(4,1,2);imhist(a);title('histogram of original image');subplot(4,1,3);b=histeq(a);imshow(b);title('equalization iamge');subplot(4,1,4);imhist(b);title('histogram of equalized image');

Page 24: DSP lab manual

OUTPUT

Page 25: DSP lab manual

BUTTERWORTH FILTER

Ex. No:

Date:

AIM: To design an IIR filter using BUTTERWORTH filter co-efficients.

ALGORITHM:1. Start.2. Get the sampling frequency.3. Get the signal frequency.4. Using the in built function butterworth function, like buttod5. Design the filter by calculating co-efficients and plot the values.

RESULT:Thus program was successfully written and the code was executed using MatLab.

PROGRAM

Page 26: DSP lab manual

%BILEAR TRANSFORMwp=0.355*pi;ws=0.7*pi;ap=-20*log10(0.6);as=-20*log10(0.1);T=0.1;awp=(2/T)*tan(wp/2);aws=(2/T)*tan(ws/2);[n,wc]=buttord(awp,aws,ap,as,'s');disp(n);disp(wc);[b,a]=butter(n,1,'s');display('normalized s domain tf');hs=tf(b,a);[b,a]=butter(n,'w','s');display('unnormalized tf');[num,den]=bilinear(b,a,1/T);display('tf in z domain');hz=tf(num,den);fvtool(num,den);

Page 27: DSP lab manual
Page 28: DSP lab manual

IMPULSE INVARIANCE

Ex. No:

Date:

AIM: To design an IIR filter using Impulse Invariance and to find filter co-efficients.

ALGORITHM:1. Start.2. Get the required parameter like amplitude and frequency etc.3. Convert the required signal parameter into decibel.4. Using the Butterworth function in MatLab, calculate the co-effecients.5. Plot the frequency spectrum.

RESULT: Thus the filter is successfully designed and executed using MatLab.

Page 29: DSP lab manual

PROGRAM:%impulse invariancewp=0.355*pi;ws=0.7*pi;ap=-20*log10(0.6);as=-20*log10(0.1);f=1;T=0.1;awp=(2/T)*tan(wp/2);aws=(2/T)*tan(ws/2);[n,wc]=buttord(awp,aws,ap,as,'s');disp(n);disp(wc);[b,a]=butter(n,1,'s');display('normalized s domain tf');hs=tf(b,a);[b,a]=butter(n,wc,'s');display('unnormailzed tf');hs=tf(b,a);[bz,az]=impinvar(b,a,f);display('tf in z domain');hz=tf(bz,az);fvtool(bz,az);

Page 30: DSP lab manual
Page 31: DSP lab manual

FINITE IMPULSE RESPONSE

Ex. No:

Date:

AIM:

To design FIR filter using windowing method(rectangle).

ALGORITHM:

1. Start

2. Get the sampling frequency.

3. Get the signal frequency.

4. Calculate the N points using boxchar function.

5. Plot the coefficients.

RESULT:

Thus the filter is designed for the windowing using rectangular method and executed using MAtLab.

Page 32: DSP lab manual

PROGRAM:

%fir rectangular window

clear all;wc=0.5*pi;N=25;a=(N-1)/2;aps=0.001;n=0:1:N-1;hd=sin(wc*(n-a+aps))/(pi*(n-a+aps));wr=boxcar(N);hn=hd*wr;w=0:0.01:pi;h=freqz(hn,1,w);plot(w/pi,abs(h));hold on;wn=hamming(N);hd=hd.*wn;w=0:0.01:pi;k=freqz(hn,1,w);plot(w/pi,abs(k));grid;xlabel('Normalized frequency(pi)');ylabel('Magnitude');hold off;

Page 33: DSP lab manual

NOISE ADDITION AND REMOVAL

Ex. No:

Date:

AIM:

To add the random noise and remove in an image.

ALGORITHM:

1. Start 2. Get an image file as an input.3. im2bw use this function to convert the image into b/w.4. Process the image by adding different noises like (Gaussian, salt and pepper,

average).5. Plot the images.

RESULT:Thus the noises were added and removed to the image and successfully

executed using MatLab.

Page 34: DSP lab manual

PROGRAM:%noise cancellerclc;clear all;close all;im1=imread('cameraman.tif');subplot(2,3,1);imshow(im1);im3=im2bw(im1);subplot(2,3,2);imshow(im3);im4=imnoise(im1,'gaussian');subplot(2,3,3);imshow(im4);im5=imnoise(im1,'salt & pepper');subplot(2,3,4);imshow(im5);h=fspecial('average');im6=imfilter(im1,h);subplot(2,3,5);imshow(im6);im7=medfilt2(im5);subplot(2,3,6);imshow(im7)

Page 35: DSP lab manual

Experiments Using TMS320C50 Processor Familiarizing Instructions Related To Different Addressing Modes

Ex. No:

Date:

AIM:

To perform an operation using Immediate, Direct and Indirect addressing modes of TMS320C50 Processor

ALGORITHM:

1. Start

2. Initialize the data and program memory segment

3. Load any value in Accumulator

4. Add another value by either immediate or direct or indirect mode

5. Move the value in accumulator to any data memory address

6. Stop.

Result Thus programs using direct, indirect and immediate addressing modes are done using TMS320C50 processor.

Page 36: DSP lab manual

IMMEDIATE ADDRESSING MODEPROGRAM:.mmregs.ds 1000h.ps 0a00h.entry.lacc #07h.add #05h.end

sample input & output:acc <- o7ho/p: acc<- 07+05=och

DIRECT ADDRESSINGG MODEPROGRAM:.mmregs.ds 1000h.ps 0a00h.entryldp #32lacc 02hadd 04hsacl 20h.end

sample input & output:1002 ->acc -> 02h1004 <- 04hacc <- 06ho/p: 1020 <- 06h

INDIRECT ADDRESSING MODEPROGRAM:.mmregs.ds 1000h.ps 0a00h.entrylar ar2, #1003hlar ar0, #1001hlar ar1, #1002hmar *lacc *mar *, ar1add *mar *,ar2add *sacl *.end

sample input & output:ar0 ->1001h -> 02har1 ->1002h -> 03har2 ->1003h -> 01ho/p: 1003h -> 06h

Page 37: DSP lab manual

MULTIPLICATION

Ex. No:

Date:

AIM: To perform multiplication using TMS320C50 instruction kit.

ALOGRITHM:(i)USING MPY INSTRUCTION:1. Start.2. Load AR's and temprorary registers which contain the 1 st operand.3. Using mpy instruction perform multiplication.4. store the result.5. Stop.

(ii)USING MAC INSTRUCTION:1. Start.2. Load the data in required AR's.3. Using mac instrution to multiply the data in 0a00h & in AR.4. Store the result.5. Stop.

(iii) USING REPEATED ADDITION:1. Start2. Load AR's with one operand & address of another another. 3. Perfrom repeated addition using one AR as counter.4. Stop.

RESULT: Thus multiplication operation is performed using TMS230C50 processor.

Page 38: DSP lab manual

(i) USING MAC INSTRUCTION

PROGRAM:

.mmregs

.ds 1000h

.ps 0a00h

.entrylar ar0,#1000hlacc #05hsamm treg0mpy #06hpacmar *,ar0sacl *.end

sample input & outputacc-< 05h * 06hpreg <- 12hacc <- 12har0 -> 1000h -> 12h

(ii) USING MAC INSTRUCTION

PROGRAM:

.mmregs

.ds 1000h

.ps 0a00h

.word 06h

.entrylar ar0,#1001hlar ar1,#1010hmar *,ar0mac 0a00hpacmar *,ar1sacl *.end

sample input & outputar0 ->1001h -> 06h0a00h -> 06hpreg ->24h ->acc1010h -> 24h

(iii) USING REPEATED ADDITION

PROGRAM:

.mmregs

.ds 1000h

.ps 0a00h

Page 39: DSP lab manual

.entrylar ar0, #1000hlar ar1, #05hlar ar2,#1002hL: mar *,ar0zapadd *mar *,ar1mar *-banz Lmar *,ar2sacl *.end

sample input & output100h <- 05h1002h <- 19h

Page 40: DSP lab manual

Linear Convolution

Ex. No:

Date:

AIM: To perform linear convolution using TMS320C50 instruction set

ALGORITHM:

1. Start

2. Store the input sequence of length n1 in program memory

3. Store the impulse sequence of length n2 in data memory

4. Appended (n1-1) zeros on either side of impulse sequence

5. Point to the last element of n1 sequence and multiply using MAC instruction

6. Next point to the last but one element and perform the same

7. Do this in a loop counter, count=(n1+n2-1)8. If counter ≠ 0 repeat else go to

9. Stop the loop

10. Stop

Result:

Thus linear convolution is done using TMS320C50 instruction set.

Page 41: DSP lab manual

LINEAR CONVOLUTION x(n) ={1,2,3};h(n)= {0,0,3,1,0,0};

PROGRAM:.mmregs.ds 1000h.word 00h,00h,03h, 10h,00h,00h.ps 0a00h.word 10h,02h,03h.entrylar ar0,#1002hlar ar1,#04hlar ar2,#1020hL1: zapmar *, ar0rpt #03hmac 0a00h, *-adrk #05hmar *,ar2sacl *+mar *,ar1mar *-banz L1.end

sample output:00h,00h,03h,07h,03h,03h,00h,00h

Page 42: DSP lab manual

Circular Convolution

Ex. No:

Date:

AIM: To perform circular convolution using TMS320C50 instruction set

ALGORITHM:

1. Start

2. Load CBSR1, CBER1 and CBCR.

3. Load the required AR’s.

4. Multiply using MAC instruction by decrementing AR.

5. Store the result in suitable location.

6. Stop.

RESULT: Thus circular convolution is performed using TMS320C50 processor.

Page 43: DSP lab manual

x(n)= {5,7,9,2,3}h(n)={1,2,3,4,5} 5 3 2 9 7 15 7 3 2 9 29 7 5 3 2 32 9 7 5 3 43 2 9 7 5 5 PROGRAM:.mmregs.ds 1000h.ps 0a00h.word 05h,07h,09h,02h,03h.entrysplk #1004h,cbsr1splk #1000h,cber1splk #ofh,cbcrlar ar7, #1000hlar ar1, #1030hlar ar2, #05hL: zapmar *, ar7rpt #05hmac 0a00h,*-mar *-mar *-mar *-mar *, ar1sacl *+mar *, ar2mar *-banz L.end

sample input & output

1000h- 05h 0a00h- 01h1001h- 07h 0a001h- 02h1002h- 09h 0a002h- 03h1003h- 02h 0a003h- 04h1004h- 03h 0a004h- 05h

o/p:

1030h- 58h 1032h- 3Ch 1034h- 57h 1031h- 4Fh 1033h- 4Ch

Page 44: DSP lab manual

Waveform Generation

Ex. No:

Date:

AIM:

To generate waveforms using TMS320C50 instruction set

ALGORITHM:

1. Initialize memory mapped registers

2. Initialize the data and program memory segment

3. (a) For Square wave Generation

i) Set the Amplitude and ii) Time Period

Positive: 7FFFh

Negative: 9FFFh

Ton: 1000h

T off: 1000h

4. Set the Tone and Toff of the square wave form using Auxiliary Register

5. Load the positive value in Accumulator

6. AND the accumulator value with 0FFCh for primary communication between DSP and AIC

7. Transfer the data from ACC to DXR Using SAMM instruction

8. Repeat step 7 for Ton times

9. Load the negative value in Accumulator

10. AND the Accumulator value with 0FFFCh for primary Communication between DSP and

AIC

11. Repeat step 10 for Toff times

12. Repeat step 5 to step 11 unconditionally.

Page 45: DSP lab manual

b) For Ramp wave Generation

1. i) Set the Amplitude and ii) Step Value

Amplitude: 7FFFh

Step: 00008h

2. Set the interrupt and load PDWSR and CWSR with appropriate value

3. Load Accumulator with amplitude

4. Load ARCR with ACC value using SAMM instruction

5. Load Accumulator and ARn with #0000h

6. Add step value with ACC and ARn content

7. AND the Accumulator value with 0FFFCh for primary Communication between DSP and AIC

8. Transfer the data from ACC to DXR using SAMM instruction

9. Compare ARCR with ARn and Branch conditionally (CM=00)to corresponding step 6

10. Repeat step 5 to step 9 unconditionally

(c) For Triangular wave Generation

1. i) Set the Amplitude and ii) Step Value

Amplitude: 7FFFh

Step: 00008h

2. Load Accumulator with amplitude value

3. Load ARCR with ACC value using SAMM instruction

4. Load Accumulator and ARn with #0000h

5. Add step value with ACC and ARn content

6. AND the Accumulator value with 0FFFCh for primary Communication between DSP and AIC

7. Transfer the data from ACC to DXR using SAMM instruction

8. Compare ARCR with ARn and Branch conditionally (CM=00) to corresponding step 7

9. Load Accumulator with #0000h

10. Load ARCR with ACC value using SAMM instruction

11. Load Accumulator and ARn with amplitude value

12. Subtract step value from ACC and ARn content

13. AND the Accumulator value with 0FFFCh for primary Communication between DSP and AIC

14. Transfer the data from ACC to DXR using SAMM instruction

Page 46: DSP lab manual

15. Compare ARCR with ARn and Branch conditionally (CM=00) to corresponding step 12

16. Branch to step 4 unconditionally

Result: Thus square, ramp and triangular waveforms are generated using TMS320C50 processor.

Page 47: DSP lab manual

SQUARE WAVEFORM

PROGRAM:

.mmregs

.ds 1000h

.ps 0a00hampp .set 7FFFhampn .set 9FFFhton .set 7888htoff .set 7888h.entryL1: lacc #ampp and #0FFCh rpt #ton samm dxr lacc #ampn and #0FFCh rpt #toff samm dxr bL1.end

TRIANGULAR WAVEFORM

PROGRAM:

.mmregs

.ds 1000h

.ps 0a00hamp .set 7FFFhstep .set 0010h.entryL3: lacc #amp

samm arcrlacc #0000hlar ar0, #0000h

L1: add #stepand #offfchsamm dxradrk #stepcmpr1bcnd L1,tcsplk #0000h,arcr

L2: sub #stepand #offfchsamm dxrsbrk #stepcmpr 2bcnd L2,tcbL3

.end

Page 48: DSP lab manual

RAMP WAVEFORM

PROGRAM:

.mmregs

.ds 1000h

.ps 0a00hamp .set 7fffhstep .set 0008h.entrylacc #ampsamm arcrL2: lacc #0000h

samm arcrL1: and offfch

samm dxradd #stepadrk #stepcmpr 1bcnd L1,tcbL2

.end

Page 49: DSP lab manual

Experiments Using TMS320C6713 Processor Design of FIR Filters (i) LPF (ii) HPF

Ex. No:

Date:

AIM:

To design a Low Pass Filter and High Pass Filter using FIR filter design method using TMS320C6713 Code Composer Studio

ALGORITHM:

1. Get the desired frequency response, Hd (ejw)

2. Get the order of the filter, N

3. Store the coefficients of windows (which can be generated through MATLAB) in program/calculate in program using the corresponding window function, w(n) for order N.

4. Calculate the filter coefficients for the desired frequency, hd(n) for order N.

5. Calculate the filter coefficient using window, h(n)= hd(n)* w(n)

6. Calculate the frequency response of h(n), H (ejw)

7. Find the magnitude response of H (ejw) and plot it.

Result: Thus lowpass and highpass FIR filters are designed using TMS320C6713

Page 50: DSP lab manual

Design of IIR Filters (i) LPF (ii) HPF

Ex. No:

Date:

AIM:

To design a Low Pass Filter and High Pass Filter using IIR filter design method using TMS320C6713 Code Composer Studio

ALGORITHM:

1. Get the passband cut –off frequency, stopband cut-off frequency, passband ripple and stopband ripple as input for desired filter response

2. Calculate the order using Butterworth method/Chebyshev method as specified, N

3. Find the transfer function of the analog filter according to N

4. Convert the analog filter to digital filter using Bilinear transformation method

Result:Thus low pass and high pass FIR filter are designed using TMS320C6713.

Page 51: DSP lab manual

LOW PASS FILTER#include<stdio.h>#include<math.h>main(){ float wc,hd[9],h[9],w[9];int n,x,I;printf(“enter the order”);scanf(“%d: ,& n);printf(“enter cutoff”);scanf(“ %f “, &wc);x = (n-1)/2;for(i=0;i<n-1;i++){

w[i]= 0.54 + (0.46 * cos(2*pi*i)/(n-x)); if(i==x)

hd[i]=wc/3.14;elsehd[i]=sin(wc * (i-x) )/ (3.14 * (i-x));h[i]= hd[i] * w[i];

}for(i=0;i<n-1;i++){

printf(“%f”,h[i]);}}

Page 52: DSP lab manual

HIGH PASS FILTER #include<stdio.h>#include<math.h>main(){ float wc,hd[9],w[9]; int n,x,I;printf(“enter the order”);scanf(“%d: ,& n);printf(“enter cutoff”);scanf(“ %f “, &wc);x = (n-1)/2;for(i=0;i<n-1;i++){

w[i]= 0.54 + (0.46 * cos(2*pi*i)/(n-x)); if(i==x) hd[i]=1-(wc/3.14)

elsehd[i]=-sin(wc * (i-x) / (3.14 * (i-x));h[i]=hd[i] * w[i];

}for(i=0;i<n-1;i++)printf(“%f”, h[i]);}

SAMPLE INPUT AND OUTPUT

a=[0.107503, -0.046953, -0.079272, 0.229496, 0.381976, 0.229496, -0.008522, 0.002205, -0.0085]

b=[0.167503, -0.04693, -0.079272, 0.256706, 0.381972, 0.256706, -0.008522, 0.002205, -0.008522]

Page 53: DSP lab manual

LINEAR CONVOLUTION USING C6713 PROCESSOR

Ex. No:

Date:

AIM: To perform linear convolution using C6713 code composer studio

ALGORITHM:

1. Start.2. Get the two sequences x and h.3. Perform padding of zeros.4. Run a for loop for j=0 to m+n-1.5. Assign y[i]=0.6. Run another for loop from i=0 to j.7. y[j] = y[j] + (x[i] * h[j-1]);8. display y.9. stop.

RESULT:Thus linear convolution is implemented using CCS.

Page 54: DSP lab manual

PROGRAM:/* prg to implement linear convolution */

#include<stdio.h>#include<math.h>int y[20];main(){ int m=6; /*Lenght of i/p samples sequence*/int n=6; /*Lenght of impulse response Co-efficients */int i=0,j;int x[15]={1,2,3,4,5,6,0,0,0,0,0,0}; /*Input Signal Samples*/int h[15]={1,2,3,4,5,6,0,0,0,0,0,0}; /*Impulse Response Co-efficients*/for(i=0;i<m+n-1;i++){

y[i]=0;for(j=0;j<=i;j++)

y[i]+=x[j]*h[i-j];}for(i=0;i<m+n-1;i++)printf("%d\n",y[i]);}

Page 55: DSP lab manual

CIRCULAR CONVOLUTION USING C6713 PROCESSOR

Ex. No:

Date:

AIM: To perform circular convolution using C6713 code composer studio

ALGORITHM:

1. Start.2. Get the two sequences m and n.3. Get the two sequences x and h.4. If length of both sequence are not equal pad the smaller sequence with zeros5. Fold h[n] to h[-n].6. Perform circular convolution. y[0] = x[i]*a[i].7. Perform circular shift.8. Display the result.

RESULT:Thus circular convolution was performed using C6713 code composer studio

Page 56: DSP lab manual

PROGRAM:

#include<stdio.h>#include<math.h>int m,n,x[30],h[30],y[30],i,j,temp[30],k,x2[30],a[30];void main(){printf(" enter the length of the first sequence\n");scanf("%d",&m);printf(" enter the length of the second sequence\n");scanf("%d",&n);printf(" enter the first sequence\n");for(i=0;i<m;i++)scanf("%d",&x[i]);printf(" enter the second sequence\n");for(j=0;j<n;j++)scanf("%d",&h[j]);if(m-n!=0) /*If length of both sequences are not equal*/{if(m>n) /* Pad the smaller sequence with zero*/{for(i=n;i<m;i++)h[i]=0;n=m;}for(i=m;i<n;i++)x[i]=0;m=n;}y[0]=0;a[0]=h[0];for(j=1;j<n;j++) /*folding h(n) to h(-n)*/a[j]=h[n-j];/*Circular convolution*/for(i=0;i<n;i++)y[0]+=x[i]*a[i];for(k=1;k<n;k++){y[k]=0;/*circular shift*/for(j=1;j<n;j++)x2[j]=a[j-1];x2[0]=a[n-1];for(i=0;i<n;i++){a[i]=x2[i];y[k]+=x[i]*x2[i];}}/*displaying the result*/printf(" the circular convolution is\n");for(i=0;i<n;i++)printf("%d \t",y[i]);}

Page 57: DSP lab manual

INPUT:Eg: x[4]={1, 2, 3,4}h[4]={1, 2, 3,4}

OUT PUT :y[4]={26, 28, 26,20}

Page 58: DSP lab manual

FIR FILTER USING HAMMING WINDOW

Ex. No:

Date:

AIM:

To implement FIR bandpass filter using hamming window in C6713 code composer studio.

ALGORITHM:

1. Start.2. Get the filter specifications wc1,wc2,N.3. Calculate the window coeffecients w(n).4. Calculate the filter coeffecients hd(n).5. Convolve th e two sequence to get the FIR filter coeffecients.

h(n)=w(n)*hd(n).6. Stop.

RESULT:Thus the FIR band pass filter using hamming window has been implemented successfully in code composer studio

Page 59: DSP lab manual

PROGRAM:

#include<stdio.h>#include<conio.h>int N=11;a=1000;float w[7],hd[7],h[7],pi=3.14,x(1000);wc1=0.4*pi;wc2=0.65*pi;

void main(){float t1=0.4*pi,t2=0.65*pi;int n=0;for(n=0;n<N;n++){w(n)=0.5-(0.5*cos(2*pi*n/N-1));hd(n)=(sin(t2*(n-3)))-(sin(t1*(n-3)))/(pi*(n-3)));h(n)=w(n)*hd(n);printf(“%f”,h(n)));for(i=0;i<a;i++){x(i)=0.25-((0.0296)*cos(i*pi/6))-((0.112)*cos(2*i*pi/6));printf(“%f”,x(i)));}}

OUTPUT

Page 60: DSP lab manual

DISCRETE FOURIER TRANSFORM

Ex. No:

Date:

AIM: To implement discrete fourier transform in C6713 using code composer studio.

ALGORITHM:1. Get the length of the sequence and the sequence.2. Calculate the real term and imaginary term separately.

f ( x )=∑n=0

N

(x (n )∗cos2∗π∗k∗n

w−x (n )∗sin

2∗π∗k∗nw )

3.Print the real and imaginary term separately.

RESULT:

Hence the discrete fourier transform(DFT) was implemented successfully in code composer studio.

Page 61: DSP lab manual

PROGRAM:

#include<stdio.h>#include<math.h>int N,k,n,I;float pi=3.1416,sumre=0;sumin=0;float out_real(8)=0.03, out_imag[8]={0.03};int x[32];void main(){printf(“Enter the length of sequence \n”);scanf(“%d”,&N);printf(“Enter the sequence \n”);for(i=0;i<n;i++)scanf(“%d”,&x[i]);for(k=0;k<n;k++){sumre=0;sum in>0;}for(n=0;n<N;n++){sumre=sumre+x(n)*cos(2*pi*k*n/w);sumim=sumim-x(n)*sin(2*pi*k*n/w);}out_real(k)=sumre;out_imag[k]=sumim;printf(“%d= \t %f \t%f”,k,out_real(k),out_imag(k));}}

Page 62: DSP lab manual

Recommended