You are on page 1of 122

1.

OPERATIONS ON MATRICES

AIM : To Perform Different Operations on Matrices SOFTWARE : PC Equipped with MATLAB 7.0 PROGRAM :
%CREATING A MATRIX a=[1 10 0; 5 15 8; 3 5 9] a= 1 5 3 10 15 5 0 8 9

% TRANSPOSE OF A MATRIX b=a' b= 1 5 3 10 15 5 0 8 9 % MULTIPLICATION OF A MATRIX c=a*b c= 101 155 53 155 314 162 53 162 115 %ROW BY ROW MULTIPLICATION d=a.*b d= 1 50 0 50 225 40 0 40 81 %TRANSPOSE OF A MATRIX e=inv(a) e= -0.8261 0.7826 -0.6957 0.1826 -0.0783 0.0696 0.1739 -0.2174 0.3043 % CREATING A MATRIX inv(a)*a ans = 1

1 0 0

0 1 0

0 0 1

%EIGEN VALUE OF THE MATRIX f=eig(a) f= 21.5506 -1.1582 4.6075 %SINGULAR VALUE DECOMPOSITION g=svd(a) g= 21.7831 7.4155 0.7119 %COEFFICIENTS OF CHARACTERISTIC POLYNOMIAL h=poly(a) h= 1.0000 -25.0000 69.0000 115.0000 %TO ROUND THE RESULT i=round(poly(a)) i= 1 -25 69 115 %ROOTS OF CHARACTERISTIC POLYNOMIAL l=roots(h) l= 21.5506 4.6075 -1.1582 %RANK OF A MATRIX m=rank(a) m= 3 %ACCESING A SPECIFIC OR PARTICULAR ELEMENT OF THE MATRIX a(3,2) ans = 5

%READING A SPECIFIC ROW IN THE MATRIX a(3,:) ans = 3 5 9

%READING A SPECIFIC COLUMN IN THE MATRIX a(:,1) ans = 1 5 3 %ACCESSING SUBMATRICES n=a(1:2,1:2) n= 1 5 10 15

%CREATING A COLUMN o=[2 ; 5 ; 10] o= 2 5 10 %CONCATINATING WITH A COLUMN P=[a o] P= 1 5 3 10 15 5 0 2 8 5 9 10

%GENERATING SERIES OF NUMBERS R=1:10 R= 1 2 3 4 5 6 7 8 9 10

%GENERATING SERIES OF NUMBERS WITH SPECIFIED STEP S=1:9:100 S= 1 10 19 28 37 46 55 64 73 82 91 100 %ADDING A SCALAR TO EVERY ELEMENT OF THE MATRIX t=a+2 t= 3 7 5 12 2 17 10 7 11

%DETERMINATION OF A MATRIX u=det(a) u= -115 %SIZE OF THE MATRIX v=size(a) v= 3 3

2. SIGNAL GENERATIONS

2.1 IMPULSE SEQUENCE


AIM : To Generate Impulse Sequence SOFTWARE : PC Equipped with MATLAB 7.0 PROGRAM : a=[zeros(1,50) 1 zeros(1,50)]; t=-50:1:50; k=input('Enter the Amplitude'); b=k*a; subplot(211); plot(t,b); title('Sample Sequence'); ylabel('Amplitude'); subplot(212); stem(t,b); xlabel('Time Axis'); ylabel('Amplitude'); O/P Wave Forms :

2.2 STEP SEQUENCE


AIM : To Generate Step Sequence SOFTWARE : PC Equipped with MATLAB 7.0 PROGRAM: t=-50:1:50; a=4*ones(1,101); stem(t,a); title('step response'); xlabel('time sequence') ylabel('amplitude'); Output Waveform:

2.3 RAMP WAVEFORM


AIM : To Generate Ramp Wave SOFTWARE : PC Equipped with MATLAB 7.0 PROGRAM : t=1:1:50; for n=1:50 x(n)=n end; plot(t,x); title('ramp sequence'); xlabel('time sequence'); ylabel('x'); Output Waveform:

2.4.1 SAWTOOTH WAVEFORM


AIM : To Generate Saw tooth Waveform SOFTWARE : PC Equipped with MATLAB 7.0 PROGRAM :

P=100; t=1:1:P*10; for n=1:(P/2) a(n)=n; end for n=(P/2)+1:P a(n)=n-P; end a1=a; for i=1:9 a1=[a1 a]; end plot(a1); axis([-100 1000 -100 100]); title('sawtooth sequence'); xlabel('time sequence'); ylabel('amplitude'); Output Waveform:

2.4.2 SAWTOOTH WAVEFORM


AIM : To Generate Sawtooth Waveform SOFTWARE : PC Equipped with MATLAB 7.0 PROGRAM : clear all; l=0; for n=1:30 x(n)=l; if(l==6) l=0; else l=l+1; end plot(x); title('sawtooth sequence'); xlabel('time sequence'); ylabel('amplitude'); end Output Waveform:

10

2.5.1 SQUARE WAVEFORM


AIM : To Generate Square Wave SOFTWARE : PC Equipped with MATLAB 7.0 PROGRAM : fs=0.0125; T=(1/fs); t=1:1:T*10; a=[ones(1,T/4) -1*ones(1,T/4) -2*ones(1,T/4) -1*ones(1,T/4) ones(1,T/4) ]; %a1=a; %for n=1:9 % a1=[a1 a]; %end plot(a); title('square wave'); xlabel('time sequence'); ylabel('Amplitude'); axis([1 100 -3 2]) Output waveform:

11

2.5.2 SQUARE WAVEFORM


AIM : To Generate Square Wave SOFTWARE : PC Equipped with MATLAB 7.0 PROGRAM : fs=.0125 T=1/fs t=1:1:T*10 a=[ones(1,T/2) -1*ones(1,T/2)] a1=a for n=1:9 a1=[a1 a] end plot(t,a1) title('square wave'); xlabel('time sequence'); ylabel('Amplitude'); axis([0 1000 0 2]) Output Waveform:

12

2.6.1 TRIANGULAR WAVEFORM


AIM : To Generate Triangular Wave. SOFTWARE : PC Equipped with MATLAB 7.0 PROGRAM : for n=0:6; for a=1:5; x(n*8+a)=a; end for i=1:5; a=a+1; x(n*8+a)=5-i; end end plot(x) title('triangular waveform'); xlabel('time sequence'); ylabel('Amplitude'); axis([1 20 1 10])
Output waveform:

13

2.6.2 TRIANGULAR WAVEFORM


AIM : To Generate Triangular Wave SOFTWARE : PC Equipped with MATLAB 7.0 PROGRAM : P=20; t=1:1:P*10; for n=1:(P/4) a(n)=n; end for n=(P/4)+1:(3*P/4) a(n)=(P/2)-n; end for n=(3*P/4)+1:P a(n)=n-P; end a1=a; for i=1:9 a1=[a1 a]; end plot(t,a1); title('triangular waveform'); xlabel('time sequence'); ylabel('Amplitude'); axis([0 200 -10 10]); Output Waveform:

14

2.7.1 SINEWAVE
AIM : To Generate Sinewave SOFTWARE : PC Equipped with MATLAB 7.0 PROGRAM : f=1000; T=1/f; t=0:T:50*T; y=sin(2*pi*50*t); plot(t,y); title('sinewave'); xlabel('time sequence'); ylabel('Amplitude'); %stem(y); Output Waveform:

15

2.7.2 SINUSOIDAL SEQUENCE


AIM : To Generate Sinusoidal Sequence for the given Specifications SOFTWARE: PC Equipped with MATLAB 7.0 PROGRAM: %Generation of sinusoidal sequence Clear; A=input('enter the value of gain constant'); N=input('enter the number of samples'); w=input('enter the radian frequency'); phy=input('enter the initial phase in rad'); for n=0:N-1 x(n+1)=A*cos(w*n+phy); t(n+1)=n; end stem(t,x); title('sinusoidal sequence'); xlabel('time index'); ylabel('amplitude'); pause;

16

Simulation Results: Type in the Gain constant : 5 Enter the number of samples : 40 Enter the radian frequency : 0 Enter the initial Phase in rad : 0 Output Waveforms:

17

Simulation Results: Type in the Gain constant : 5 Enter the number of samples : 40 Enter the radian frequency : pi/8 Enter the initial Phase in rad : 0 Output Waveforms:

18

Simulation Results:

Type in the Gain constant : 5 Enter the number of samples : 40 Enter the radian frequency : pi/4 Enter the initial Phase in rad : 0
Output Waveforms:

19

Simulation Results: Type in the Gain constant : 5 Enter the number of samples : 40 Enter the radian frequency : pi Enter the initial Phase in rad : 0 Output Waveforms:

20

3. SUM OF SINUSOIDAL SEQUENCES


AIM : To Generate Sum of Two Sinusoidal Sequences

SOFTWARE : PC Equipped with MATLAB 7.0 PROGRAM: % sum of sinusoidal a=input('enter the frequency of first sinusoidal'); k1=input('enter the gain of first sinusoidal'); b=input('enter the frequency of second sinusoidal' ); k2=input('enter the gain of second sinusoidal'); N=input('enter the number of samples'); for n=0:N-1 S1(n+1)=k1*sin(a*n); S2(n+1)=k2*sin(b*n); S3(n+1)=S1(n+1)+S2(n+1); t(n+1)=n end subplot(311) stem(t,S1); title('first sinusoidal'); subplot(312) stem(t,S2); title('second sinusoidal'); subplot(313); stem(t,S3); title('sum of two sinusoidals');

21

Simulation Results: enter the frequency of first sinusoidal 50 enter the gain of first sinusoidal 0.2 enter the frequency of second sinusoidal 50 enter the gain of second sinusoidal 0.2 enter the number of samples 50 Output Waveform:

22

4.1 COMPLEX EXPONENTIAL SEQUENCE


AIM : To Generate the Complex Exponential Sequence for the given Specifications SOFTWARE : PC Equipped with MATLAB 7.0 PROGRAM : %Generation of complex exponential sequence clear; j=sqrt(-1); kreal=input('enter the real part of gain constant'); kimag=input('enter the imaginary part of gain constant'); areal=input('enter the real part of a'); aimag=input('enter the imaginary part of a'); k=kreal+j*kimag; a=areal+j*aimag; N=input('enter the number of samples'); for n=1:N-1 x(n)=k*(a.^n); t(n)=n; end stem(t,real(x)); title(Complex exponential) xlabel('time index'); ylabel('amplitude'); pause; stem(t,imag(x)); title(Complex exponential) xlabel('time index'); ylabel('amplitude');

23

Simulation Results: Enter the Real Part of Gain constant : 5 Enter the Image Part of Gain constant : 0 Enter the Real Part of a : 0.8 Enter the Imaginary Part of a : 0.45 Enter the number of samples : 40 Output Waveform:

24

Simulation Results: Enter the Real Part of Gain constant : 5 Enter the Image Part of Gain constant : 0 Enter the Real Part of a : 0.85 Enter the Imaginary Part of a : 0.65 Enter the number of samples : 40 Output Waveform:

25

4.2 REAL EXPONENTIAL SEQUENCE


AIM : To Generate the Real Exponential Sequence for the given Specifications SOFTWARE: PC Equipped with MATLAB 7.0 PROGRAM: clear; K=input('type the value of gain constant'); N=input('enter the number of samples'); a=input('enter the value of a'); for n=0:N-1 x(n+1)=K.*(a.^n); t(n+1)=n; end stem(t,x); title('real exponential sequence'); xlabel('discrete time variable'); ylabel('amplitude'); Simulation Results: Type in the Gain Constant : 5 Enter the Number of Samples : 20 Enter the Value of a : 0.8 Output Waveform:

26

Simulation Results: Type in the Gain Constant : 5 Enter the Number of Samples : 20 Enter the Value of a : 1.2 Output Waveform:

27

28

Simulation Results: Type in the Gain Constant : 5 Enter the Number of Samples : 20 Enter the Value of a : -0.8 Output Waveform:

29

Simulation Results:

Type in the Gain Constant : 5 Enter the Number of Samples : 20 Enter the Value of a : -1.2 Output Waveform:

30

5.1.1 LINEAR CONVOLUTION


AIM : To Perform Convolution of Two Sequences SOFTWARE : PC Equipped with MATLAB 7.0 PROGRAM : a=[1,1,1,1]; b=[2,2,2,2]; t=1:8; a1=[a zeros(1,(length(b)-1))]; b1=[b zeros(1,(length(a)-1))]; b2=fliplr(b1); for n=1:7 b2=[b2(end) b2(1:end-1)]; c(n)=a1*b2'; end subplot(311); stem(a1); title('first sequence'); subplot(312); stem(b2); title('second sequence'); ylabel('amplituide'); subplot(313); stem(c) title('convolution of two discrete sequences '); xlabel('discrete time index');

31

Output Waveform:

32

5.1.2 LINEAR CONVOLUTION


AIM : To Perform Convolution on given Two Sequences SOFTWARE : PROGRAM: a=input('enter the samples of first sequence'); b=input('enter the samples of second sequence'); a1=a; b1=b; M=length(a); N=length(b); a=fliplr(a); a=[a zeros(1,N-1)]; b=[zeros(1,M-1) b]; I=a; for i=1:M+N-1 if i==1 c(i)=a*b'; else for j=1:i-1 a=[a(M+N-1) a(1:(M+N-2))]; end c(i)=a*b'; a=I; end end subplot(311); stem(a1); title('first sequence'); subplot(312); stem(b1); title('second sequence'); ylabel('amplituide'); subplot(313); stem(c) title('convolution of two discrete sequences '); xlabel('discrete time index'); PC Equipped with MATLAB 7.0

33

Output Waveform:

34

5.2.1 CIRCULAR CONVOLUTION


AIM : To Perform Circular Convolution of Two Sequences SOFTWARE : PC Equipped with MATLAB 7.0 PROGRAM : a=[1,2,3,4]; b=[5,6,7,8]; t=1:1:4; b1=fliplr(b); for n=1:4 b1=[b1(end) b1(1:end-1)]; x(n)=a*b1'; end subplot(311); stem(a1); title('first sequence'); subplot(312); stem(b2); title('second sequence'); ylabel('amplituide'); subplot(313); stem(c) title('convolution of two discrete sequences '); xlabel('discrete time index')

35

Output Waveforms:

36

6.1 AUTO CORRELATION


AIM : To Perform Auto Correlation of Two Sequences SOFTWARE : PC Equipped with MATLAB 7.0 PROGRAM : a=[1,1,1,1]; t=1:7; a1=[a zeros(1,(length(a)-1))]; b1=[zeros(1,(length(a)-1)) a]; for n=1:7 b1=[b1(end) b1(1:end-1)]; z(n)=a1*b1'; end subplot(211); stem(a1); title('input sequence'); ylabel('amplitude'); subplot(212); stem(z); title('Auto Correlation'); xlabel('time index'); ylabel('amplitude')-

37

Output Waveform :

38

6.2 CROSS CORRELATION


AIM : To Perform Cross Correlation of Two Sequences SOFTWARE : PC Equipped with MATLAB 7.0 PROGRAM :

a=input('a is '); b=input('b is '); t=1:8; a1=[a zeros(1,(length(b)-1))]; b1=[b zeros(1,(length(a)-1))]; for n=5:7 b1=[b1(end) b1(1:end-1)]; c(n)=a1*b1'; end for n=1:4 b1=[b1(end) b1(1:end-1)]; c(n)=a1*b1'; end c subplot(311); stem(a1); title('First sequence') subplot(312); stem(b1); title(second sequence) ylabel(Amplitude) subplot(313); stem(c); title(Cross correlation) xlabel(Tme index) SIMULATION RESULTS : a is [1 2 3] b is [3 4 5] c = 14 26 18 9 18 9 5

39

Output Waveform:

40

7.1 DISCRETE FOURIER TRANSFORM


AIM: To determine the Discrete Fourier Transform Coefficients of the given Input Sequence SOFTWARE : PC Equipped with MATLAB 7.0 PROGRAM: %discrete fourier transform clear; N=input('enter the length of the sequence'); M=input('type the length of dft'); u=[ones(1,N)]; U=fft(u,M); t=0:N-1; stem(t,u); title('original time domain sequence'); xlabel('time index'); ylabel('amplitude'); pause; subplot(2,1,1); k=0:1:M-1; stem(k,abs(U)); title('magnitude of the DFT samples'); xlabel('frequency index'); ylabel('magnitude'); subplot(2,1,2); stem(k,angle(U)); title('phase of DFT samples'); xlabel('frequncy index k'); ylabel('phase'); pause;

41

SIMULATION RESULTS:
enter the length of the sequence 10 type the length of dft 20

Output Waveform:

42

7.2 DISCRETE FOURIER TRANSFORM


AIM : To Perform Discrete Fourier Transform of the given Sequence SOFTWARE : PC Equipped with MATLAB 7.0
PROGRAM :

x=[1 2 3 4] N=input('enter no. of points'); z=[zeros(N)] for k=1:1:N for n1=1:1:N y=i*2*pi*k*n1/N; p=exp(-y); g=z(k)+(x(n1)*p); z(k)=g; end; end; z subplot(211); stem(x); title('Input sequence') ylabel('amplitude'); subplot(212); stem(abs(z)); title('Discrete Fourier transform'); ylabel('amplitude'); xlabel('Samples')

43

Output Waveform

44

8.1 POWER DENSITY SPECTRUM


AIM : To Compute and Plot Power Density Spectrum of the given Signals SOFTWARE : PC Equipped with MATLAB 7.0 PROGRAM :
Clear ;

fs=1000; f1=400; f2=200; t=0:1/fs:10/fs; s=sin(2*pi*f1*t)+sin(2*pi*f2*t); subplot(211); plot(t,s); title('input signal'); ylabel('amplitude') xlabel('time index') a1=xcorr(s,s); psd1=fft(a1,1024); %plot(psd1); %title('psd1'); %figure; psd2=psd1.*conj(psd1)/1024; subplot(212); plot(psd2); title('psd2'); ylabel('Normalized magnitude') xlabel('Frequency') f=1:1024

45

Output Waveform:

46

8.2 POWER DENSITY SPECTRUM


AIM : To Compute and Plot Power Density Spectrum of the given Signals SOFTWARE : PC Equipped with MATLAB 7.0 PROGRAM : t = 0: .0000001: .000001; x = sin(2*pi*50*t) + sin(2*pi*120*t); y = x + 2*randn(size(t)); subplot(311) plot(y) title('Noisy time domain signal') Y = fft(y,256); Pyy = Y.*conj(Y)/256; f = 1000/256*(0:127); subplot(312) plot(f, Pyy(1:128)) title('Power density spectrum') xlabel('Frequency (Hz)') ylabel(Amplitude) subplot(313) plot(f(1:50),Pyy(1:50)) title('Power density spectrum') xlabel('Frequency (Hz)') ylabel(Amplitude) Output Waveforms:

47

48

9.1.1 ANALOG LOWPASS FILTER (BUTTERWORTH)


AIM : To Design an Analog Lowpass Butterworth Filter for the given Specifications SOFTWARE : PC Equipped with MATLAB 7.0 PROGRAM: wp=input('Enter value of passband edge'); ws=input('Enter value of stopband edge'); rp=input('Enter value of passband attenuation'); rs=input('Enter value of stopband attenuation'); fs=input('Enter value of sampling freq'); wp=wp/fs/2; ws=ws/fs/2; [n,wn]=buttord(wp,ws,rp,rs); [b,a]=butter(n,wn,'s'); [h,w]=freqs(b,a,512); w=w/(2*pi); y=abs(h); plot(w,20*log10(y)); title('Analog LPF Butterworth'); ylabel('magnitude'); xlabel('frequency') SIMULATION RESULTS : Enter value of passband edge 5000 Enter value of stopband edge 8000 Enter value of passband attenuation 0.1 Enter value of stopband attenuation 30 Enter value of sampling freq8000 OUTPUT WAVEFORM :

49

9. 1.2 ANALOG LOWPASS FILTER (BUTTERWORTH)


AIM : To Design an Analog Lowpass Butterworth Filter for the given Specifications SOFTWARE : PC Equipped with MATLAB 7.0 PROGRAM: N=input('enter the order of filter'); wn=input('enter the value of cutoff frequency in Hz'); [num,den]=butter(N,wn,'s'); omega=0:200:12000*pi; h=freqs(num,den,omega); plot(omega/2*pi,20*log10(abs(h))); title('Butterworth LPF'); xlabel('Normalized Frequency'); ylabel('Magnitude in db');

50

SIMULATION RESULTS : Enter the order of filter6 Enter the value of cutoff frequency in Hz 10000 OUTPUT WAVEFORM :

51

9.2 ANALOG HIGH PASS FILTER (BUTTERWORTH)


AIM : To Design an Analog High pass Butterworth Filter for the given Specifications SOFTWARE: PC Equipped with MATLAB 7.0 PROGRAM: N=input('enter the order of filter'); wn=input('enter the value of cutoff frequency in Hz'); [num,den]=butter(N,wn,'high','s'); omega=0:200:12000*pi; h=freqs(num,den,omega); plot(omega/2*pi,20*log10(abs(h))); title('Butterworth HPF'); xlabel('Normalized Frequency'); ylabel('Magnitude');

52

SIMULATION RESULTS : Enter the order of filter6 Enter the value of cutoff frequency in Hz 10000 OUTPUT WAVEFORM :

53

10.1 FIR LOWPASS FILTER USING RECTANGULAR WINDOW


AIM : To Design a FIR LowPass Filter using Rectangular Window for the given Specifications

SOFTWARE: PC Equipped with MATLAB 7.0 PROGRAM:


N=input('enter the order of filter'); Fs=input('enter the value of sampling frequency'); Fc=input('enter the value of cutoff frequency'); Wn=2*Fc/Fs; Hw=rectwin (N+1); b=fir1(N,Wn,Hw); [h,omega]=freqz(b,1,512); mag=20*log10(abs(h)); plot(omega/pi,mag); grid; title('FIR LPF using Rectangular Window'); xlabel('normalized frequency'); ylabel('magnitude');

SIMULATION RESULTS :
enter the order of filter 6 enter the value of sampling frequency 10000 enter the value of cutoff frequency 1000

OUTPUT WAVEFORM :

54

10.2
AIM :

FIR LOWPASS FILTER USING TRIANGULAR WINDOW


To Design a FIR LowPass Filter using Triangular Window for the given Specifications

SOFTWARE: PC Equipped with MATLAB 7.0 PROGRAM: clear; N=input('enter the order of filter'); Fs=input('enter the value of sampling frequency'); Fc=input('enter the value of cutoff frequency'); Wn=2*Fc/Fs; Hw=triang(N+1); b=fir1(N,Wn,Hw,); [h,omega]=freqz(b,1,512); mag=20*log10(abs(h)); plot(omega/pi,mag); grid; xlabel('normalized frequency'); title('FIR LPF using Triangular window'); ylabel(' Magnitude)

55

SIMULATION RESULTS :
Enter the order of filter6 Enter the value of sampling frequency10000 Enter the value of cutoff frequency1000

OUTPUT WAVEFORM :

56

10.3.
AIM :

FIR LOWPASS FILTER USING KAISER WINDOW


To Design a FIR LowPass Filter using Kaiser Window for the given Specifications

SOFTWARE: PC Equipped with MATLAB 7.0 PROGRAM: N=input('enter the order of filter'); Fs=input('enter the value of sampling frequency'); Fc=input('enter the value of cutoff frequency'); Wn=2*Fc/Fs; Hw=kaiser(N+1,2); b=fir1(N,Wn,Hw); [h,omega]=freqz(b,1,512); mag=20*log10(abs(h)); plot(omega/pi,mag); grid; title('FIR LPF using kaiser Window'); xlabel('normalized frequency'); ylabel('magnitude');

57

SIMULATION RESULTS :
Enter the order of filter6 Enter the value of sampling frequency10000 Enter the value of cutoff frequency1000

OUTPUT WAVEFORM

58

10.4 FIR HIGHPASS FILTER USING RECTANGULAR WINDOW


AIM : To Design a FIR HighPass Filter using Rectangular Window for the given Specifications

SOFTWARE: PC Equipped with MATLAB 7.0 PROGRAM: N=input('enter the order of filter'); Fs=input('enter the value of sampling frequency'); Fc=input('enter the value of cutoff frequency'); Wn=2*Fc/Fs; Hw=rectwin(N+1); b=fir1(N,Wn,'high',Hw); [h,omega]=freqz(b,1,512); mag=20*log10(abs(h)); plot(omega/pi,mag); grid; title('FIR HPF using Rectangular Window'); xlabel('normalized frequency'); ylabel('magnitude');

59

SIMULATION RESULTS :
Enter the order of filter22 Enter the value of sampling frequency100000 Enter the value of cutoff frequency5000

OUTPUT WAVEFORM

60

10.4 FIR BANDPASS FILTER USING HAMMING WINDOW


AIM : To Design a FIR BandPass Filter using Hamming Window for the given Specifications

SOFTWARE: PC Equipped with MATLAB 7.0 PROGRAM: N=input('enter the order of filter'); wn1=input('enter the value of Lower cutoff frequency'); wn2=input('enter the value of Upper cutoff frequency'); fs=input('enter the value of sampling frequency'); Wn1=wn1/(fs/2); wn2=wn2/(fs/2); wn=[wn1 wn2]; Hw=hamming(N+1); b=fir1(N,Wn,'bandpass',Hw); [h,omega]=freqz(b,1,512); mag=20*log10(abs(h)); plot(omega/pi,mag); grid; title('FIR Bandpass filter using hamming Window'); xlabel('normalized frequency'); ylabel('magnitude');

61

SIMULATION RESULTS : enter the order of filter6 enter the value of Lower cutoff frequency500 enter the value of Upper cutoff frequency700 enter the value of sampling frequency10000 OUTPUT WAVEFORM

62

IIR BSF USING CHEBYSHEV APPROXIMATION


AIM : To design a infinite impulse response band stop filter using chebyshev approximation SOFTWARE: PC Equipped with MATLAB 7.0 PROGRAM: %IIR bandstop filter using Chebyshev Approximation clear; N=input('enter the value of order '); Fs=input('entrer the value of sampling frequency'); Fc1=input('Enter the value of Lower cutoff frequncy'); Fc2=input('Enter the value of HIGHER cutoff frequncy'); r=input('enter the value of allowable ripple'); Wn(1)=2*Fc1/Fs; Wn(2)=2*Fc2/Fs; [B,A]=cheby1(N,r,Wn,'stop'); [H,omega]=freqz(B,A,N); mag=20*log10(abs(H)); plot(omega/pi,mag); grid; xlabel('Normalized frequency'); ylabel('Gain in db'); title('IIR BANDSTOP FILTER'); pause; SIMULATION RESULTS: Enter the value of order : 20 Enter the value Sampling Frequency : 10000 Enter the value of Lower Cutoff Frequency : 1000 Enter the value of Upper Cutoff Frequency : 2000 Enter the value of passband Ripple in dB : 1

63

64

DSP PROCESSORS

65

1. 1. ARCHITECTURE OF TMS320C67XX AND INSTRUCTION SET

CONTENTS

TMS320C6000 CPU Architecture Addressing Modes Instruction Set Overview

66

67

TMS320C67x Block Diagram

68

TMS320C6713 ARCHITECTURE

69

Highest-Performance Floating-Point Digital Signal Processor TMS320C6713


Eight 32-Bit Instructions/Cycle 32/64-Bit Data Word 4.4-, 6.7-ns Instruction Cycle Time 1800 MIPS/1350 MFLOPS Rich Peripheral Set, Optimized for Audio Highly Optimized C/C++ Compiler

Functional Units and Operations Performed:

70

Addressing Modes: Immediate Addressing Mode Register Direct Addressing Mode Register Indirect Addressing Mode Register relative Addressing mode Circular Addressing Mode Instructions Set: Absolute Value Instructions Addition/Subtraction Instructions Load/Store/Move Instructions Multiplication Instructions Compare Instructions Bit Manipulation Instructions Shift Instructions Logical Operation Instructions Program Control Instructions Conversion Instructions Special Instructions Miscellaneous Instructions

71

C67x Instruction Set

72

ABS (Integer Absolute Value With Saturation):

ADD(U) (Signed or Unsigned Integer Addition Without Saturation):

ADDAB/ADDAH/ADDAW (Integer Addition Using Addressing Mode):

AMR Register

AMR Register:

73

AMR Register:

CMPEQ (Integer Compare for Equality):

74

LDB(U)/LDH(U)/LDW :
LDB .D2 *+B14[36],B1

MPY(U/US/SU):

75

MVKH/MVKLH (Move 16-Bit Constant Into the Upper Bits of a Register):

SHL (Arithmetic Shift Left):

76

77

SUB(U) (Signed or Unsigned Integer Subtraction Without Saturation):

Floating-Point Instruction Set


ABSDP (Double-Precision Floating-Point Absolute Value):
ABSDP .S1 A1:A0,A3:A2

78

CMPGTDP (Double-Precision Floating-Point Compare for Greater Than):


CMPGTDP (.unit) src1, src2, dst CMPGTDP .S1 A1:A0,A3:A2,A4

MPYDP (Double-Precision Floating-Point Multiply):


MPYDP .M1 A1:A0,A3:A2,A5:A4

79

Constraints on Cross Paths (1X and 2X):


The following execute packet is invalid: ADD.L1X A0,B1,A1 ; \1X cross path is used || MPY.M1X A4,B4,A5 ; for both instructions The following execute packet is valid: ADD.L1X A0,B1,A1 ; Instructions use the 1X || MPY.M2X B4,A4,B2 ; and 2X cross paths

Constraints on Loads and Stores:


The following execute packet is invalid: LDW.D1 *A0,A1 ; .D2 unit must use the address || LDW.D2 *A2,B2 ; register from the B register file The following execute packet is valid: LDW.D1 *A0,A1 ; Address registers from correct || LDW.D2 *B0,B2 ; register files The following execute packet is invalid: LDW.D1 *A4,A5 ; Loading to and storing ||STW.D2 A6,*B4; from the same register file The following execute packets are valid: LDW.D1 *A4,B5 ; Loading to, and storing ||STW.D2 A6,*B4 ; from different register files

Constraints on Register Reads:


The following code sequences are invalid: MPY .M1 A1,A1,A4 ; five reads of register A1 || ADD .L1 A1,A1,A5 || SUB .D1 A1,A2,A3 This code sequence is valid: MPY .M1 A1,A1,A4 ; only four reads of A1 || ADD .L1 A0,A1,A5 || SUB .D1 A1,A2,A3

80

Conditionals Cross Paths:


If conditional register comes from the opposite side, it does NOT use a data or address cross-path Examples: [B2] ADD .L1x A2,B0,A4 [A1] LDW .D2 *B0,A5

Data Destination register - same side as unit Source register - up to one crosspath per execute packet per side C64x - 1 cycle delay slot Address Pointer must be on same side as unit Data can be transferred to/from either side Parallel accesses: both cross or neither cross Conditional Unlimited

81

CODE COMPOSER STUDIO STEPS


1. Start CCS setup by double clicking on the setup CCS desktop icon 2. Click the clear button in the import configuration dialog box to remove any previously defined configuration [My System (Uninstall all) ] 3. Select the standard configuration Family Platform Endianness C67XX Simulator Little

C6711 device simulation, little endian Click the import button close Click on Install device driver Select Tisim C6XXX .dvr (For dsktixds6000.dvr) and open OK 6. Click the File and Save , Exit YES
4. 5.

The CCS Setup closes and the CCS IDE automatically opens using the configuration you just created. Creating a New Project The information for a project is stored in a single project file ( * . Pjt) 1. From the Project menu, choose NEW The Project creation Wizard window displays Project Name : Enter the Project name Location: D:\ti\myprojects Finish 2. In File Option select NEW source file. Type your source code in that file. File NEW Source file 3. After writing the source file save that file as .asm file 4. Add Source file to the Project Project add files to project select your .asm file click open To add Library Files Project add files to project D:\ti C6000 Cgtools Lib(Object & Library files) rst6700.lib OPEN

82

To add Command Files Project Add files to project D:\ti Tutorial (dsk6711 / sim62XX) hello1 (linker command file) hello . cmd (for real time lnk.cmd) OPEN

TO Compile Project Compile File Project Build If there are any errors it will specify If building is successful it creates .out file. Loading the Program File Load Program Debug Select .out file OPEN Debug RUN View Registers Core Registers According to the Program select the core Register and load the address of the Core Register as Memory address For ex : A5 8000 0000 View Memory Address 8000 0000

Select Format type as 16 bit Signed int OK

83

2.1 ADDITION
AIM: To Perform Addition of two numbers using C- Code SOFTWARE: PC and Code Composer Studio PROGRAM : # include <stdio.h> void main() { int a,b; printf("ENTER THE VALUES OF A AND B"); scanf("%d %d",&a,&b); printf("THE VALUE OF A+B IS %d",a+b); } SIMULATED RESULTS: Enter the values of a and b 2 3 The value of a+b is 5

84

2.2 SUBTRACTION
AIM: To Perform Subtraction of two numbers using C- Code SOFTWARE: PC and Code Composer Studio PROGRAM : # include <stdio.h> void main() { int a,b; printf("ENTER THE VALUES OF A AND B"); scanf("%d %d",&a,&b); printf("THE VALUE OF A-B IS %d",a-b); } SIMULATED RESULTS: Enter the values of a and b 3 2 The value of a-b is 1

85

2.3 MULTIPLICATION
AIM: To Perform Multiplication of two numbers using C- Code SOFTWARE: PC and Code Composer Studio PROGRAM : # include <stdio.h> void main() { int a,b; printf("ENTER THE VALUES OF A AND B"); scanf("%d %d",&a,&b); printf("THE VALUE OF A * B IS %d",a*b); } SIMULATED RESULTS: Enter the values of a and b 2 3 The value of a * b is 6

86

3.1 LINEAR CONVOLUTION


AIM : To Perform Linear Convolution of two sequences using C-Code SOFTWARE: PC and Code Composer Studio PROGRAM: #include<stdio.h> void main() { int a[9]={1,2,3,4,5}; int b[9]={1,1,1,1,1}; int m=5,n=5; int c[10],i,j; for(i=0;i<m+n-1;i++) { c[i]=0; for(j=0;j<=i;j++) c[i]=c[i]+(a[j]*b[i-j]); } for(i=0;i<m+n-1;i++) printf ("%d", c[i]); } OUTPUT : 1 3 6 10 15 14 12 9 5

87

3.2 LINEAR CONVOLUTION


AIM : To Perform Linear Convolution of two sequences using C-Code SOFTWARE: PC and Code Composer Studio PROGRAM: #include<stdio.h> #define MAX1 10 #define MAX2 10 void main() { int a[MAX1],b[MAX2],i,j,M,N,temp; printf("ENTER THE RANGE OF THE ARRAY A:(MAX1=10)\n"); scanf("%d",&M); printf("ENTER THE RANGE OF THE ARRAY B:(MAX2=10)\n"); scanf("%d",&N); printf("ENTER THE ELEMENTS OF THE ARRAY A:\n"); for(i=0;i<M;i++) scanf("%d",&a[i]); printf("ENTER THE ELEMENTS OF THE ARRAY B:\n"); for(i=0;i<N;i++) scanf("%d",&b[i]); printf("THE VALUES OF THE ARRAY (A CONV B):\n"); for(i=0;i<(M+N-1);i++) { temp=0; for(j=0;j<=i;j++) { if((j<M)&&((i-j)<N)) temp+=a[j]*b[i-j]; } printf("%d ",temp); } }

88

SIMULATION RESULTS : ENTER THE RANGE OF THE ARRAY A:(MAX1=10) 4 ENTER THE RANGE OF THE ARRAY B:(MAX2=10) 3 ENTER THE ELEMENTS OF THE ARRAY A: 1 2 3 4 ENTER THE ELEMENTS OF THE ARRAY B: 1 2 3 THE VALUES OF THE ARRAY (A CONV B): 1 4 10 16 17 12

89

3.3 LINEAR CONVOLUTION


AIM: To perform Linear Convolution of two sequences using Assembly Code SOFTWARE: PC and Code Composer Studio PROGRAM :
.global _main X H _main: MVKL .S1 X,A4 MVKH .S1 X,A4 MVKL .S2 H,B4 MVKH .S2 H,B4 MVKL .S1 Y,A5 MVKH .S1 Y,A5 MVK .S2 11,B2 ZERO .L1 A7 ZERO .L1 A3 LL2: ZERO .L1 A2 ZERO .L1 A8 LL1: LDH MV SUB LDH NOP 4 MPY ADD ADD CMPLT .S2 NOP 5 .D1 *A4[A8],A6 .S2X A8,B5 .L2 A3,B5,B7 .D2 *B4[B7],B6 .M1X A6,B6,A7 .L1 A8,1,A8 .L1 A2,A7,A2 .L2X B5,A3,B0 LL1 ; for(j=0;j<=i;j++) ;y[i]+=x[j]*h[i-j]; ;J=0, for(i=0;i<m+n-1;i++) ;POINTER TO X ;POINTER TO H ;POINTER TO Y ;M+N-1 ; ;I=0 .half 1,2,3,4,5,6,0,0,0,0,0,0 .half 1,2,3,4,5,6,0,0,0,0,0,0 .bss Y,30,2

[B0]

[A2]

B B

STH .D1 A2,*A5[A3] ADD .L1 A3,1,A3 CMPLT .L1X A3,B2,A2 .S1 LL2 NOP 5 B3 ;RETURN BACK TO C PROGRAM NOP 5

90

OUTPUT: 1. To view Output Numerically Select view Registers Core Registers A5 Select view Memory Address Type value of A5 Format 16 bit Unsigned Int Click OK 80000000 : 1 4 10 20 35 56 70 76 73 60 36

2. To View Output Graphically Select View Graph Time and Frequency

91

4.1 CIRCULAR CONVOLUTION


AIM : To Perform Circular Convolution of two sequences using C-Code SOFTWARE: PC and Code Composer Studio PROGRAM: #include<stdio.h> #define MAX 10 void main( ) { int a[MAX],b[MAX],i,j,M,N,temp,k,c[MAX],x,z; int max(int ,int ); printf("ENTER THE RANGE OF THE ARRAY A:(MAX=10)\n"); scanf("%d",&M); printf("ENTER THE RANGE OF THE ARRAY B:(MAX=10)\n"); scanf("%d",&N); printf("ENTER THE ELEMENTS OF THE ARRAY A:\n"); for(i=0;i<M;i++) scanf("%d",&a[i]); printf("ENTER THE ELEMENTS OF THE ARRAY B:\n"); for(i=0;i<N;i++) scanf("%d",&b[i]); k=max(M,N); if(k==M) { for(i=N;i<M;i++) b[i]=0; for(i=0;i<M;i++) c[i]=b[M-1-i]; } else { for(i=M;i<N;i++) a[i]=0; for(i=0;i<N;i++) c[i]=a[N-i-1]; } printf("THE VALUES OF THE ARRAY (A CIRCULAR CONV B):\n"); for(i=0;i<k;i++) { temp=c[0]; c[0]=c[k-1]; for(z=k-1;z>=2;z--) { c[z]=c[z-1]; } c[1]=temp;
92

x=0; for(j=0;j<k;j++) { if(k==M) x=x+a[j]*c[j]; else x=x+b[j]*c[j]; } printf("%d ",x); } } int max(int l,int p) { if(l>p) return(l); else return(p); } SIMULATED RESULTS : ENTER THE RANGE OF THE ARRAY A:(MAX=10) 4 ENTER THE RANGE OF THE ARRAY B:(MAX=10) 3 ENTER THE ELEMENTS OF THE ARRAY A: 1 2 3 4 ENTER THE ELEMENTS OF THE ARRAY B: 1 2 3 THE VALUES OF THE ARRAY (A CIRCULAR CONV B): 18 16 10 16

93

4.2 CIRCULAR CONVOLUTION


AIM : To Perform Circular Convolution of two sequences using C-Code SOFTWARE: PC and Code Composer Studio PROGRAM: #include<stdio.h> #define MAX 10 void main( ) { int a[MAX],b[MAX],i,j,M,N,temp,k,c[MAX],x,z; int max(int ,int ); printf("ENTER THE RANGE OF THE ARRAY A:(MAX=10)\n"); scanf("%d",&M); printf("ENTER THE RANGE OF THE ARRAY B:(MAX=10)\n"); scanf("%d",&N); printf("ENTER THE ELEMENTS OF THE ARRAY A:\n"); for(i=0;i<M;i++) scanf("%d",&a[i]); printf("ENTER THE ELEMENTS OF THE ARRAY B:\n"); for(i=0;i<N;i++) scanf("%d",&b[i]); k=max(M,N); if(k==M) { for(i=N;i<M;i++) b[i]=0; for(i=0;i<M;i++) c[i]=b[M-1-i]; } else { for(i=M;i<N;i++) a[i]=0; for(i=0;i<N;i++) c[i]=a[N-i-1]; } printf("THE VALUES OF THE ARRAY (A CIRCULAR CONV B):\n"); for(i=0;i<k;i++) { temp=c[0]; c[0]=c[k-1]; for(z=k-1;z>=2;z--) { c[z]=c[z-1]; } c[1]=temp;
94

x=0; for(j=0;j<k;j++) { if(k==M) x=x+a[j]*c[j]; else x=x+b[j]*c[j]; } printf("%d ",x); } } int max(int l,int p) { if(l>p) return(l); else return(p); } SIMULATED RESULTS : ENTER THE RANGE OF THE ARRAY A:(MAX=10) 4 ENTER THE RANGE OF THE ARRAY B:(MAX=10) 3 ENTER THE ELEMENTS OF THE ARRAY A: 1 2 3 4 ENTER THE ELEMENTS OF THE ARRAY B: 1 2 3 THE VALUES OF THE ARRAY (A CIRCULAR CONV B): 18 16 10 16

95

5. FAST FOURIER TRANSFORM(FFT)


AIM : C-Program to implement FFT SOFTWARE: PC and Code Composer Studio PROGRAM 1 :
/*

Number of points for FFT (PTS) 256

iobuffer input signal sample output of FFT function (don't use on graph window) x1 use in graph window */ ============================================================ // FFT256c.c FFT implementation calling a C-coded FFT function #include <math.h> #define PTS 64 //# of points for FFT #define PI 3.14159265358979 typedef struct {float real, imag;} COMPLEX; void FFT(COMPLEX *Y, int n); //FFT prototype float iobuffer[PTS]; //as input and output buffer float x1[PTS]; //intermediate buffer short i; //general purpose index variable short buffercount = 0; //number of new samples in iobuffer short flag = 0; //set to 1 by ISR when iobuffer full COMPLEX w[PTS]; //twiddle constants stored in w COMPLEX samples[PTS]; //primary working buffer main() { for (i = 0 ; i<PTS ; i++) // set up twiddle constants in w { w[i].real = cos(2*PI*i/(PTS*2.0)); //Re component of twiddle constants w[i].imag =-sin(2*PI*i/(PTS*2.0)); //Im component of twiddle constants } for (i = 0 ; i < PTS ; i++) //swap buffers { iobuffer[i] = sin(2*PI*1*i/PTS);/*10- > freq,100 -> sampling freq*/ samples[i].real=0.0; samples[i].imag=0.0; } for (i = 0 ; i < PTS ; i++) //swap buffers { samples[i].real=iobuffer[i]; //buffer with new data
96

/* iobuffer[i] = x1[i]; } for (i = 0 ; i < PTS ; i++) samples[i].imag = 0.0; FFT(samples,PTS);

//processed frame to iobuffer*/ //imag components = 0 //call function FFT.c

for (i = 0 ; i < PTS ; i++) //compute magnitude { x1[i] = sqrt(samples[i].real*samples[i].real + samples[i].imag*samples[i].imag);///32; } } PROGRAM 2 ( FFT.C) #define PTS 256 //# of points for FFT typedef struct {float real, imag} COMPLEX; extern COMPLEX w[PTS]; //twiddle constants stored in w void FFT(COMPLEX *Y, int N) //input sample array, # of points { COMPLEX temp1,temp2; //temporary storage variables int i,j,k; //loop counter variables int upper_leg, lower_leg; //index of upper/lower butterfly leg int leg_diff; //difference between upper/lower leg int num_stages = 0; //number of FFT stages (iterations) int index, step; //index/step through twiddle constant i = 1; //log(base2) of N points= # of stages do { num_stages +=1; i = i*2; }while (i!=N); leg_diff = N/2; //difference between upper&lower legs step = (PTS*2)/N; //step between values in twiddle.h // 512 for (i = 0;i < num_stages; i++) //for N-point FFT { index = 0; for (j = 0; j < leg_diff; j++) { for (upper_leg = j; upper_leg < N; upper_leg += (2*leg_diff)) { lower_leg = upper_leg+leg_diff; temp1.real = (Y[upper_leg]).real + (Y[lower_leg]).real; temp1.imag = (Y[upper_leg]).imag + (Y[lower_leg]).imag; temp2.real = (Y[upper_leg]).real - (Y[lower_leg]).real;
97

//end of main

temp2.imag = (Y[upper_leg]).imag - (Y[lower_leg]).imag; (Y[lower_leg]).real = temp2.real*(w[index]).real -temp2.imag*(w[index]).imag; (Y[lower_leg]).imag = temp2.real*(w[index]).imag +temp2.imag*(w[index]).real; (Y[upper_leg]).real = temp1.real; (Y[upper_leg]).imag = temp1.imag; } index += step; } leg_diff = leg_diff/2; step *= 2; } j = 0; for (i = 1; i < (N-1); i++) //bit reversal for resequencing data { k = N/2; while (k <= j) { j = j - k; k = k/2; } j = j + k; if (i<j) { temp1.real = (Y[j]).real; temp1.imag = (Y[j]).imag; (Y[j]).real = (Y[i]).real; (Y[j]).imag = (Y[i]).imag; (Y[i]).real = temp1.real; (Y[i]).imag = temp1.imag; } } return; }

Procedure :

Add the source files program1 and program2 in the project using project add files to project Add the Linker command file lnk.cmd Add Library file Compile the program using project compile Project build Load the program using file load Run the program and observe output using Graph

98

Output Waveform:

99

POWER DENSITY SPECTRUM (PSD)


AIM : C-Program to implement PSD SOFTWARE: PC and Code Composer Studio PROGRAM 1 : /*Number of points for FFT (PTS) x --> Sine Wave Co-Efficients iobuffer --> Out put of Auto Correlation. sample --> output of FFT function (don't use on graph window) x1 --> use in graph window to view PSD */ #include <math.h> #define PTS 128 //# of points for FFT #define PI 3.14159265358979 typedef struct {float real,imag;} COMPLEX; void FFT(COMPLEX *Y, int n); //FFT prototype float iobuffer[PTS]; //as input and output buffer float x1[PTS],x[PTS]; //intermediate buffer short i; //general purpose index variable short buffercount = 0; //number of new samples in iobuffer short flag = 0; //set to 1 by ISR when iobuffer full float y[128]; COMPLEX w[PTS]; //twiddle constants stored in w COMPLEX samples[PTS]; //primary working buffer main() { float j,sum=0.0 ; int n,k,i,a; for (i = 0 ; i<PTS ; i++) // set up twiddle constants in w { w[i].real = cos(2*PI*i/(PTS*2.0)); //Re component of twiddle constants w[i].imag =-sin(2*PI*i/(PTS*2.0)); /*Im component of twiddle constants*/ } /****************Input Signal X(n) ************************/ for(i=0,j=0;i<PTS;i++) { x[i] = sin(2*PI*5*i/PTS); // Signal x(Fs)=sin(2*pi*f*i/Fs); samples[i].real=0.0; samples[i].imag=0.0; }
100

/********************Auto Correlation of X(n)=R(t) ********/ for(n=0;n<PTS;n++) { sum=0; for(k=0;k<PTS-n;k++) { sum=sum+(x[k]*x[n+k]); } iobuffer[n] = sum; }

// Auto Correlation R(t)

/********************** FFT of R(t) *****************************/ for (i = 0 ; i < PTS ; i++) //swap buffers { samples[i].real=iobuffer[i]; //buffer with new data } for (i = 0 ; i < PTS ; i++) samples[i].imag = 0.0; FFT(samples,PTS); //imag components = 0 //call function FFT.c

/******************** PSD ***************/ for (i = 0 ; i < PTS ; i++) //compute magnitude { x1[i] = sqrt(samples[i].real*samples[i].real + samples[i].imag*samples[i].imag); } } //end of main

101

PROGRAM 2 : Number of points for FFT (PTS) ============================================================ #define PTS 128 //# of points for FFT typedef struct {float real,imag;} COMPLEX; extern COMPLEX w[PTS]; //twiddle constants stored in w void FFT(COMPLEX *Y, int N) //input sample array, # of points { COMPLEX temp1,temp2; //temporary storage variables int i,j,k; //loop counter variables int upper_leg, lower_leg; //index of upper/lower butterfly leg int leg_diff; //difference between upper/lower leg int num_stages = 0; //number of FFT stages (iterations) int index, step; //index/step through twiddle constant i = 1; //log(base2) of N points= # of stages do { num_stages +=1; i = i*2; }while (i!=N); leg_diff = N/2; //difference between upper&lower legs step = (PTS*2)/N; //step between values in twiddle.h // 512 for (i = 0;i < num_stages; i++) //for N-point FFT { index = 0; for (j = 0; j < leg_diff; j++) { for (upper_leg = j; upper_leg < N; upper_leg += (2*leg_diff)) { lower_leg = upper_leg+leg_diff; temp1.real = (Y[upper_leg]).real + (Y[lower_leg]).real; temp1.imag = (Y[upper_leg]).imag + (Y[lower_leg]).imag; temp2.real = (Y[upper_leg]).real - (Y[lower_leg]).real; temp2.imag = (Y[upper_leg]).imag - (Y[lower_leg]).imag; (Y[lower_leg]).real = temp2.real*(w[index]).real -temp2.imag*(w[index]).imag; (Y[lower_leg]).imag = temp2.real*(w[index]).imag +temp2.imag*(w[index]).real; (Y[upper_leg]).real = temp1.real; (Y[upper_leg]).imag = temp1.imag; } index += step; } leg_diff = leg_diff/2; step *= 2; } j = 0; for (i = 1; i < (N-1); i++) //bit reversal for resequencing data
102

{ k = N/2; while (k <= j) { j = j - k; k = k/2; } j = j + k; if (i<j) { temp1.real = (Y[j]).real; temp1.imag = (Y[j]).imag; (Y[j]).real = (Y[i]).real; (Y[j]).imag = (Y[i]).imag; (Y[i]).real = temp1.real; (Y[i]).imag = temp1.imag; } } return; } Procedure : Add the source files program1 and program2 in the project using project add files to project Add the Linker command file lnk.cmd Add Library file Compile the program using project compile Project build Load the program using file load Run the program and observe output using Graph

103

Output Waveforms:

104

7.1 FINITE IMPULSE RESPONSE FILTER


AIM : C-Program to implement FIR filter SOFTWARE: PC and Code Composer Studio PROGRAM 1: (filter.c) #include <stdio.h> #include <c6x.h> #include "c6211dsk.h" #include "codec_poll.h" double h[31] = {-0.020203,-0.016567,0.009656,0.027335,0.011411,-0.023194,-0.033672, 0.000000,0.043293,0.038657,-0.025105,-0.082004,-0.041842,0.115971,0.303048,0.386435, 0.303048,0.115971,-0.041842,-0.082004,-0.025105,0.038657,0.043293,0.000000,-0.033672, -0.023194,0.011411,0.027335,0.009656,-0.016567,-0.020203 }; int main() { /* dsp and periphiral initialization */ CSR=0x100; /* disable all interrupts */ IER=1; /* disable all interrupts except NMI */ ICR=0xffff; /* clear all pending interrupts */ *(unsigned volatile int *)EMIF_GCR = 0x3300; /* EMIF global control */ *(unsigned volatile int *)EMIF_CE0 = 0x30; /* EMIF CE0control */ *(unsigned volatile int *)EMIF_CE1 = 0xffffff03; /* EMIF CE1 control, 8bit async */ *(unsigned volatile int *)EMIF_SDCTRL = 0x07117000; /* EMIF SDRAM control *(unsigned volatile int *)EMIF_SDRP = 0x61a; /* EMIF SDRM refresh period */ *(unsigned volatile int *)EMIF_SDEXT = 0x54519; /* EMIF SDRAM extension */ mcbsp0_init(); codec_playback(); return(0); } void mcbsp0_init() { /* set up McBSP0 */ *(unsigned volatile int *)McBSP0_SPCR = 0; /* reset serial port */ *(unsigned volatile int *)McBSP0_PCR = 0; /* set pin control reg.; */ *(unsigned volatile int *)McBSP0_RCR = 0x10040; /* set rx control reg. one 16 bit data/frame */
105

*/

*(unsigned volatile int *)McBSP0_XCR = 0x10040; /* set tx control reg. one 16 bit data/frame */ *(unsigned volatile int *)McBSP0_DXR = 0; *(unsigned volatile int *)McBSP0_SPCR = 0x12001; /* setup SP control reg.; } void mcbsp0_write(int out_data) { int temp; temp = *(unsigned volatile int *)McBSP0_SPCR & 0x20000; while ( temp == 0) { temp = *(unsigned volatile int *)McBSP0_SPCR & 0x20000; } *(unsigned volatile int *)McBSP0_DXR = out_data; } int mcbsp0_read() { int temp; temp = *(unsigned volatile int *)McBSP0_SPCR & 0x2; while ( temp == 0) { temp = *(unsigned volatile int *)McBSP0_SPCR & 0x2; } temp = *(unsigned volatile int *)McBSP0_DRR; return temp; } void codec_playback() { int temp, x[31], z, i; double y; // set up control register 3 for S/W reset mcbsp0_read(); mcbsp0_write(0); mcbsp0_read(); mcbsp0_write(0); mcbsp0_read(); mcbsp0_write(0); mcbsp0_read(); mcbsp0_write(1); mcbsp0_read(); mcbsp0_write(0x0386); mcbsp0_read(); mcbsp0_write(0); mcbsp0_read();
106

*/

// set up control register 3 for mic input mcbsp0_write(0); mcbsp0_read(); mcbsp0_write(0); mcbsp0_read(); mcbsp0_write(1); mcbsp0_read(); mcbsp0_write(0x0306); mcbsp0_read(); mcbsp0_write(0); mcbsp0_read(); mcbsp0_write(0); mcbsp0_read(); mcbsp0_write(1); mcbsp0_read(); mcbsp0_write(0x2330); temp = mcbsp0_read(); mcbsp0_write(0x0); mcbsp0_read(); mcbsp0_write(0x0); mcbsp0_read(); if((temp & 0xff) != 0x06) { #if PRINT printf ("Error in setting up register 3.\n"); exit(0); #endif } //set up control register 4 mcbsp0_write(0); mcbsp0_read(); mcbsp0_write(0); mcbsp0_read(); mcbsp0_write(1); mcbsp0_read(); mcbsp0_write(0x0400); mcbsp0_read(); mcbsp0_write(0); mcbsp0_read(); mcbsp0_write(0); mcbsp0_read(); mcbsp0_write(1); mcbsp0_read(); mcbsp0_write(0x2430); temp = mcbsp0_read(); mcbsp0_write(0x0); mcbsp0_read();
107

mcbsp0_write(0x0); mcbsp0_read(); if((temp & 0xff) != 0x00) { #if PRINT printf ("Error in setting up register 4.\n"); exit(0); #endif } // set up control register 5 mcbsp0_write(0); mcbsp0_read(); mcbsp0_write(0); mcbsp0_read(); mcbsp0_write(1); mcbsp0_read(); mcbsp0_write(0x0502); mcbsp0_read(); mcbsp0_write(0); mcbsp0_read(); mcbsp0_write(0); mcbsp0_read(); mcbsp0_write(1); mcbsp0_read(); mcbsp0_write(0x2530); temp = mcbsp0_read(); mcbsp0_write(0x0); mcbsp0_read(); mcbsp0_write(0x0); mcbsp0_read(); if((temp & 0xfe) != 0x2) { #if PRINT printf ("Error in setting up register 5.\n"); exit(0); #endif } while(1) /* play back about 5 minutes */ { x[0] = mcbsp0_read(); y = 0; for(i=0; i<31; i++) y = y + x[i] * h[30-i]; z = y; z = z & 0xfffe; mcbsp0_write(z); for(i=29; i>=0; i--)
108

{ x[i+1] = x[i]; } } } PROGRAM 2: (vectors.asm) * * * TI Proprietary Information Internal Data .ref _c_int00 .sect "vectors" RESET_RST: MVKL .S2 _c_int00, B0 MVKH .S2 _c_int00, B0 B .S2 B0 NOP NOP NOP NOP NOP NMI_RST: NOP NOP NOP NOP NOP NOP NOP NOP RESV1: NOP NOP NOP NOP NOP NOP NOP NOP RESV2: NOP NOP NOP NOP
109

NOP NOP NOP NOP INT4: NOP NOP NOP NOP NOP NOP NOP NOP INT5: NOP NOP NOP NOP NOP NOP NOP NOP INT6: NOP NOP NOP NOP NOP NOP NOP NOP INT7: NOP NOP NOP NOP NOP NOP NOP NOP INT8: NOP NOP NOP NOP NOP NOP NOP NOP
110

INT9: NOP NOP NOP NOP NOP NOP NOP NOP INT10: NOP NOP NOP NOP NOP NOP NOP NOP INT11: NOP NOP NOP NOP NOP NOP NOP NOP INT12: NOP NOP NOP NOP NOP NOP NOP NOP INT13: NOP NOP NOP NOP NOP NOP NOP NOP INT14: NOP NOP NOP NOP NOP
111

NOP NOP NOP INT15: NOP NOP NOP NOP NOP NOP NOP NOP

PROGRAM 3 (c6211dsk.h)
* FILENAME * c6211dsk.h * * DESCRIPTION * DSK Header File * /* Register definitions for C6211 chip on DSK */ /* Define EMIF Registers */ #define EMIF_GCR 0x1800000 /* Address of EMIF global control */ #define EMIF_CE0 0x1800008 /* Address of EMIF CE0 control */ #define EMIF_CE1 0x1800004 /* Address of EMIF CE1 control */ #define EMIF_SDCTRL 0x1800018 /* Address of EMIF SDRAM control */ #define EMIF_SDRP 0x180001c /* Address of EMIF SDRM refresh period */ #define EMIF_SDEXT 0x1800020 /* Address of EMIF SDRAM extension */ /* Define McBSP0 Registers */ #define McBSP0_DRR 0x18c0000 /* Address of data receive reg. */ #define McBSP0_DXR 0x18c0004 /* Address of data transmit reg. */ #define McBSP0_SPCR 0x18c0008 /* Address of serial port contl. reg. */ #define McBSP0_RCR 0x18c000C /* Address of receive control reg. */ #define McBSP0_XCR 0x18c0010 /* Address of transmit control reg. */ #define McBSP0_SRGR 0x18c0014 /* Address of sample rate generator */ #define McBSP0_MCR 0x18c0018 /* Address of multichannel reg. */ #define McBSP0_RCER 0x18c001C /* Address of receive channel enable. */ #define McBSP0_XCER 0x18c0020 /* Address of transmit channel enable. */ #define McBSP0_PCR 0x18c0024 /* Address of pin control reg. */ /* Define McBSP1 Registers */
112

#define McBSP1_DRR 0x1900000 /* Address of data receive reg. */ #define McBSP1_DXR 0x1900004 /* Address of data transmit reg. */ #define McBSP1_SPCR 0x1900008 /* Address of serial port contl. reg. */ #define McBSP1_RCR 0x190000C /* Address of receive control reg. */ #define McBSP1_XCR 0x1900010 /* Address of transmit control reg. */ #define McBSP1_SRGR 0x1900014 /* Address of sample rate generator */ #define McBSP1_MCR 0x1900018 /* Address of multichannel reg. */ #define McBSP1_RCER 0x190001C /* Address of receive channel enable. */ #define McBSP1_XCER 0x1900020 /* Address of transmit channel enable. */ #define McBSP1_PCR 0x1900024 /* Address of pin control reg. */ /* Define L2 Cache Registers */ #define L2CFG 0x1840000 /* Address of L2 config reg */ #define MAR0 0x1848200 /* Address of mem attribute reg */ /* Define Interrupt Registers */ #define IMH 0x19c0000 /* Address of Interrupt Multiplexer High*/ #define IML 0x19c0004 /* Address of Interrupt Multiplexer Low */ /* Define Timer0 Registers */ #define TIMER0_CTRL 0x1940000 /* Address of timer0 control reg. #define TIMER0_PRD 0x1940004/* Address of timer0 period reg. */ #define TIMER0_COUNT 0x1940008 /* Address of timer0 counter reg. /* Define Timer1 Registers */ #define TIMER1_CTRL 0x1980000 /* Address of timer1 control reg. #define TIMER1_PRD 0x1980004/* Address of timer1 period reg. */ #define TIMER1_COUNT 0x1980008 /* Address of timer1 counter reg. */ */ */ */

/* Define EDMA Registers */ #define PQSR 0x01A0FFE0 /* Address of priority queue status */ #define CIPR 0x01A0FFE4 /* Address of channel interrupt pending */ #define CIER 0x01A0FFE8 /* Address of channel interrupt enable */ #define CCER 0x01A0FFEC /* Address of channel chain enable */ #define ER 0x01A0FFF0 /* Address of event register */ #define EER 0x01A0FFF4 /* Address of event enable register */ #define ECR 0x01A0FFF8 /* Address of event clear register */ #define ESR 0x01A0FFFC /* Address of event set register */ /* Define EDMA Transfer Parameter Entry Fields */ #define OPT 0*4 #define SRC 1*4 */ #define CNT 2*4 #define DST 3*4 */ #define IDX 4*4 #define LNK 5*4 /* Define EDMA Parameter RAM Addresses */ #define EVENT0_PARAMS 0x01A00000
113

/* Options Parameter /* SRC Address Parameter /* Count Parameter /* DST Address Parameter /* IDX Parameter /* LNK Parameter

*/ */ */ */

#define EVENT1_PARAMS EVENT0_PARAMS + 0x18 #define EVENT2_PARAMS EVENT1_PARAMS + 0x18 #define EVENT3_PARAMS EVENT2_PARAMS + 0x18 #define EVENT4_PARAMS EVENT3_PARAMS + 0x18 #define EVENT5_PARAMS EVENT4_PARAMS + 0x18 #define EVENT6_PARAMS EVENT5_PARAMS + 0x18 #define EVENT7_PARAMS EVENT6_PARAMS + 0x18 #define EVENT8_PARAMS EVENT7_PARAMS + 0x18 #define EVENT9_PARAMS EVENT8_PARAMS + 0x18 #define EVENTA_PARAMS EVENT9_PARAMS + 0x18 #define EVENTB_PARAMS EVENTA_PARAMS + 0x18 #define EVENTC_PARAMS EVENTB_PARAMS + 0x18 #define EVENTD_PARAMS EVENTC_PARAMS + 0x18 #define EVENTE_PARAMS EVENTD_PARAMS + 0x18 #define EVENTF_PARAMS EVENTE_PARAMS + 0x18 #define EVENTN_PARAMS EVENTF_PARAMS + 0x18 #define EVENTO_PARAMS EVENTN_PARAMS + 0x18 /* Define QDMA Memory Mapped Registers */ #define QDMA_OPT 0x02000000 /* Address of QDMA options register */ #define QDMA_SRC 0x02000004 /* Address of QDMA SRC address register */ #define QDMA_CNT 0x02000008 /* Address of QDMA counts register */ #define QDMA_DST 0x0200000C /* Address of QDMA DST address register */ #define QDMA_IDX 0x02000010 /* Address of QDMA index register */ /* Define QDMA Pseudo Registers */ #define QDMA_S_OPT 0x02000020 #define QDMA_S_SRC 0x02000024 #define QDMA_S_CNT 0x02000028 #define QDMA_S_DST 0x0200002C #define QDMA_S_IDX 0x02000030 /* Address of QDMA options register */ /* Address of QDMA SRC address register */ /* Address of QDMA counts register */ /* Address of QDMA DST address register */ /* Address of QDMA index register */

/* Definitions for the DSK Board and SW */ #define PI 3.1415926 #define IO_PORT 0x90080000 /* I/O port Address,top byte valid data */ #define INTERNAL_MEM_SIZE (0x4000)>>2 #define EXTERNAL_MEM_SIZE (0x400000)>>2 #define FLASH_SIZE 0x20000 #define POST_SIZE 0x10000 #define FLASH_WRITE_SIZE 0x80 #define INTERNAL_MEM_START 0xc000 #define EXTERNAL_MEM_START 0x80000000 #define FLASH_START 0x90000000 #define POST_END 0x90010000 #define FLASH_ADR1 0x90005555 #define FLASH_ADR2 0x90002AAA #define FLASH_KEY1 0xAA #define FLASH_KEY2 0x55 #define FLASH_KEY3 0xA0 #define ALL_A 0xaaaaaaaa
114

#define ALL_5 #define CE1_8 #define CE1_32

0x55555555 0xffffff03 /* reg to set CE1 as 8bit async */ 0xffffff23 /* reg to set CE1 as 32bit async */

PROGRAM 4 : (codec_poll.h)
#define PRINT 1 void codec_playback(); void mcbsp0_init(); int mcbsp0_read(); void mcbsp0_write(int out_data);

PROGRAM 5 : (lnk.cmd) -c -heap 0x400 -stack 0x400 -lrts6201.lib

/* very large stack for DSP Programs*/

MEMORY { vecs : o = 00000000h I = 00000200h IRAM : o = 00000200h I = 0000fe00h CEO : o = 80000000h I = 01000000h } SECTIONS { "vectors" > vecs .cinit > IRAM .text > IRAM .stack > IRAM .bss > IRAM .cinit > IRAM .const > IRAM .data > IRAM .far > IRAM .switch > IRAM .sysmem > IRAM .tables > IRAM .cio > IRAM }

115

Procedure : Open Code Composer studio, make sure the DSP kit is turned on. Make sure to connect the signal generator to Audio Jack named IN Make sure Sinusoidal Input frequency = 1 KHz and i/p voltage Vp-p = 1-2 V Connect a CRO to audio jack named OUT Add the source files program1 and program2 in the project using project add files to project Copy Program3 and Program 4 header files and paste it in project folder. Add the Linker command file program5. Add Library file rts6700.lib(c:\ti\c6000\cgtools\lib\rts6700.lib) Compile the program using project compile Project build Load the program using file load Run the program and observe output at the Oscilloscope.

116

7.2 INFINITE IMPULSE RESPONSE FILTER


AIM : C-Program to implement IIR filter SOFTWARE: PC and Code Composer Studio PROGRAM 1: (filter1.c) #include <stdio.h> #include <c6x.h> #include "c6211dsk.h" #include "codec_poll.h" #define order 8 float num_bw1[9]={0.001953,-0.015621,0.054672,-0.109345,0.136681, -0.109345,0.054672,-0.015621,0.001953}; float den_bw1[9]={1.000000,1.991584,3.926426,5.038243,5.385756, 4.463121,2.956255,1.381781,0.495187}; int main() { /* dsp and periphiral initialization */ CSR=0x100; /* disable all interrupts */ IER=1; /* disable all interrupts except NMI */ ICR=0xffff; /* clear all pending interrupts */ *(unsigned volatile int *)EMIF_GCR = 0x3300; /* EMIF global control */ *(unsigned volatile int *)EMIF_CE0 = 0x30; /* EMIF CE0control */ *(unsigned volatile int *)EMIF_CE1 = 0xffffff03; /* EMIF CE1 control, 8bit async */ *(unsigned volatile int *)EMIF_SDCTRL = 0x07117000; /* EMIF SDRAM control *(unsigned volatile int *)EMIF_SDRP = 0x61a; /* EMIF SDRM refresh period */ *(unsigned volatile int *)EMIF_SDEXT = 0x54519; /* EMIF SDRAM extension */ mcbsp0_init(); codec_playback(); return(0); } void mcbsp0_init() { /* set up McBSP0 */ *(unsigned volatile int *)McBSP0_SPCR = 0; /* reset serial port */ *(unsigned volatile int *)McBSP0_PCR = 0; /* set pin control reg.; */ *(unsigned volatile int *)McBSP0_RCR = 0x10040; /* set rx control reg. one 16 bit data/frame */ *(unsigned volatile int *)McBSP0_XCR = 0x10040; /* set tx control reg. one 16 bit data/frame */
117

*/

*(unsigned volatile int *)McBSP0_DXR = 0; *(unsigned volatile int *)McBSP0_SPCR = 0x12001; */ }

/* setup SP control reg.;

void mcbsp0_write(int out_data) { int temp; temp = *(unsigned volatile int *)McBSP0_SPCR & 0x20000; while ( temp == 0) { temp = *(unsigned volatile int *)McBSP0_SPCR & 0x20000; } *(unsigned volatile int *)McBSP0_DXR = out_data; } int mcbsp0_read() { int temp; temp = *(unsigned volatile int *)McBSP0_SPCR & 0x2; while ( temp == 0) { temp = *(unsigned volatile int *)McBSP0_SPCR & 0x2; } temp = *(unsigned volatile int *)McBSP0_DRR; return temp; } void codec_playback() { int temp, z, i; double output,x[9]; double y[9]; // set up control register 3 for S/W reset mcbsp0_read(); mcbsp0_write(0); mcbsp0_read(); mcbsp0_write(0); mcbsp0_read(); mcbsp0_write(0); mcbsp0_read(); mcbsp0_write(1); mcbsp0_read(); mcbsp0_write(0x0386); mcbsp0_read(); mcbsp0_write(0); mcbsp0_read();
118

// set up control register 3 for mic input mcbsp0_write(0); mcbsp0_read(); mcbsp0_write(0); mcbsp0_read(); mcbsp0_write(1); mcbsp0_read(); mcbsp0_write(0x0306); mcbsp0_read(); mcbsp0_write(0); mcbsp0_read(); mcbsp0_write(0); mcbsp0_read(); mcbsp0_write(1); mcbsp0_read(); mcbsp0_write(0x2330); temp = mcbsp0_read(); mcbsp0_write(0x0); mcbsp0_read(); mcbsp0_write(0x0); mcbsp0_read(); if((temp & 0xff) != 0x06) { #if PRINT printf ("Error in setting up register 3.\n"); exit(0); #endif } //set up control register 4 mcbsp0_write(0); mcbsp0_read(); mcbsp0_write(0); mcbsp0_read(); mcbsp0_write(1); mcbsp0_read(); mcbsp0_write(0x0400); mcbsp0_read(); mcbsp0_write(0); mcbsp0_read(); mcbsp0_write(0); mcbsp0_read(); mcbsp0_write(1); mcbsp0_read(); mcbsp0_write(0x2430); temp = mcbsp0_read(); mcbsp0_write(0x0); mcbsp0_read();
119

mcbsp0_write(0x0); mcbsp0_read(); if((temp & 0xff) != 0x00) { #if PRINT printf ("Error in setting up register 4.\n"); exit(0); #endif } // set up control register 5 mcbsp0_write(0); mcbsp0_read(); mcbsp0_write(0); mcbsp0_read(); mcbsp0_write(1); mcbsp0_read(); mcbsp0_write(0x0502); mcbsp0_read(); mcbsp0_write(0); mcbsp0_read(); mcbsp0_write(0); mcbsp0_read(); mcbsp0_write(1); mcbsp0_read(); mcbsp0_write(0x2530); temp = mcbsp0_read(); mcbsp0_write(0x0); mcbsp0_read(); mcbsp0_write(0x0); mcbsp0_read(); if((temp & 0xfe) != 0x2) { #if PRINT printf ("Error in setting up register 5.\n"); exit(0); #endif } while(1) /* play back about 5 minutes */ { x[0] = mcbsp0_read(); output = 0; for(i=0; i<order; i++) output+=num_bw1[order-i]*x[i]; for(i=0; i<order; i++) output-=den_bw1[order-i]*x[i];
120

for(i=order-1;i>=0; i--) x[i+1]=x[i]; for(i=order-1;i>=0; i--) y[i+1]=y[i]; z = output; z = z&0xfffe; mcbsp0_write(z); } } Procedure : Open Code Composer studio, make sure the DSP kit is turned on. Make sure to connect the signal generator to Audio Jack named IN Make sure Sinusoidal Input frequency = 1 KHz and i/p voltage Vp-p = 1-2 V Connect a CRO to audio jack named OUT Add the source files program1(filter1.c) and program2(from FIR) in the project using project add files to project Copy Program3 and Program 4 header files from FIR and paste it in project folder. Add the Linker command file program5. Add Library file rts6700.lib(c:\ti\c6000\cgtools\lib\rts6700.lib) Compile the program using project compile Project build Load the program using file load Run the program and observe output at the Oscilloscope.

121

122

You might also like