DSP Manual
DSP Manual
DSP Manual
LAB MANUAL
Department of ECE
Prepared By
HOD/ECE
FACULTY OF INFORMATION AND COMMUNICATION ENGINEERING V SEMESTER B. E. ELECTRONICS AND COMMUNICATION ENGINEERING (R 2008) EC2306 DIGITAL SIGNAL PROCESSING LABORATORY REQUIREMENT FOR A BATCH OF 30 STUDENTS S.No. Description of Equipment PCs with Fixed / Floating point DSP Processors (Kit / Add-on Cards) List of software required: MATLAB with Simulink and Signal Processing Tool Box Function Generators (1MHz) CRO (20MHz) Quantity required 15 Units (2 students per system) 10 Users license Quantity available Deficiency %
1.
2.
3. 4.
15 15
Department of ECE
USING MATLAB
Department of ECE
S.NO 1. 2. 3. 4. 5 6. 7.
PAGE NO 5 10 13 16 20 22 24
USING MATLAB
Generation of Signals. Linear and circular convolution of two sequences. Sampling and effect of aliasing. Design of Butterworth / Chebyshev IIR filters. Design of FIR filters. Calculation of FFT of a signal. Decimation by polyphase decomposition.
USING TMS320C5X
8.
9. STUDY OF VARIOUS ADDRESSING OF DSP USING SIMPLE PROGRAMMING EXAMPLES. WAVEFORM GENERATION
27-29
1. Generation of square wave by using TMS320C50. 2. Generation of saw tooth wave by using TMS320C50. 3. Generation of Triangular wave by using TMS320C50. 10. 11. 12. Perform linear and circular convolution of two sequences. Sampling of input signal and display Implementation of FIR filters.
27 28 29 30 35 40
Department of ECE
ALGORITHM
1. Get the length of different input sequence. 2. To plot the different input sequence.
Department of ECE ylabel('Amplitude'); title('Cosine wave'); %Program for square wave t=0:0.001:10; y=square(t); subplot(3,2,5); plot(t,y,'k'); xlabel('Time'); ylabel('Amplitude'); title('Square wave'); %Program for sawtooth wave t=0:0.1:10; y=sawtooth(t); subplot(3,2,6); plot(t,y,'k'); xlabel('Time'); ylabel('Amplitude'); title('Sawtooth wave'); %program for impulse wave t=-3:1:3; y=[zeros(1,3),ones(1,1),zeros(1,3)]; subplot(3,2,7); plot (n,y,'k'); xlabel('Time'); ylabel('Amplitude'); title('Unit impulse'); %Program for exponential sequence N=input('Enter the length of the exponential sequence(N)= '); n=0:1:N-1; a=input('Enter the value of the exponential sequence(a)= '); y=exp(a*n); subplot(3,2,1); plot (n,y,'k'); xlabel('Time'); ylabel('Amplitude'); title('Exponential sequence');
OUTPUT RESPONSE
Department of ECE
Department of ECE %Program for sinusoidal sequence N2=input('Enter the length of sinusoidal sequence(N2)= '); n2=0:0.1:N2-1; y2=sin(2*pi*n2); subplot(3,2,3); stem(n2,y2,'k'); xlabel('Time'); ylabel('Amplitude'); title('Sinusoidal sequence'); %Program for cosine sequence N3=input('Enter the length of the cosine sequence(N3)= '); n3=0:0.1:N3-1; y3=cos(2*pi*n3); subplot(3,2,4); stem(n3,y3,'k'); xlabel('Time'); ylabel('Amplitude'); title('Cosine sequence');
%Program for exponential sequence N4=input('Enter the length of the exponential sequence(N4)= '); n4=0:1:N4-1; a=input('Enter the value of the exponential sequence(a)= '); y4=exp(a*n4); subplot(3,2,5); stem(n4,y4,'k'); xlabel('Time'); ylabel('Amplitude'); title('Exponential sequence'); %Program for unit impulse n=-3:1:3; y=[zeros(1,3),ones(1,1),zeros(1,3)]; subplot(3,2,6); stem(n,y,'k'); xlabel('Time'); ylabel('Amplitude'); title('Unit impulse');
INPUT DATA
Enter the lenght of unit step sequence(N)= 10 Enter the length of unit ramp sequence(N1)= 10 Enter the length of sinusoidal sequence(N2)= 2 Enter the length of the cosine sequence(N3)= 2 Enter the length of the exponential sequence(N4)= 10 Enter the value of the exponential sequence(a)= 0.5 8
Department of ECE
OUTPUT RESPONSE
Department of ECE
RESULT
Thus the continuous time signal and discrete time signal using MATLAB program was generated.
ALGORITHM
1. Get the two sequence x(n) and h(n) in matrix form. 2. The convolution of the two sequences is given by y ( n) = x ( n ) h ( n ) =
k =
x(k )h(n k )
N 1 n=0
Department of ECE title('input sequence x(n)'); %impulse sequence h=input('Enter the impulse sequence h(n)= '); N2=length(h); n1=0:1:(N2-1); subplot(3,1,2); stem(n1,h,'k'); xlabel('n----->'); ylabel('Amplitude'); title('Impulse sequence h(n)'); %Output Convolution y=conv(x,h) n2=0:1:(N1+N2-2); subplot(3,1,3) stem(n2,y,'k'); xlabel('n----->'); ylabel('Amplitude'); title('Linear convolution of two sequences');
INPUT SEQUENCE
Enter the input sequence x(n)= [1 2 3 4] Enter the impulse sequence h(n)= [4 3 2 1] y= 4 11 20 30 20 11 4
OUPUT RESPONSE
11
Department of ECE
%LOOP FOR GETTING EQUAL LENGTH SEQUENCE if(N3==0) x1=[x1,zeros(1,N3)] x2=[x2,zeros(1,N3)] end if(N1>N2) x2=[x2,zeros(1,N3)] end if(N1<N2) x1=[x1,zeros(1,-N3)] 12
Department of ECE end %CIRCULAR CONVOLUTION disp('The output of circular convolution is') for m=1:N %This 'for' loop is for circular shifting sum=0; for k=1:N %This 'for' loop is for summation if((m-k)>=0) %This 'if' loop is for circular folding n=m-k+1; else n=m-k+N+1; end sum=sum+x1(k)*x2(n); end disp(sum) %display the result of circular convolution end
RESULT
Thus the Linear and Circular convolution of the two sequences using MATLAB program was performed.
ALGORITHM
1. Determine the analog value with respect to variation of time. 13
Department of ECE EC2306 Digital Signal Processing Lab 2. Get the sampling frequency. 3. Determine the discrete value with respect to variation of frequency. 4. Determine the Omega range from max to max . 5. Determine the magnitude of the signal. 6. Draw the discrete time signal and discrete Fourier transform.
Department of ECE grid; xlabel('normalised frequency in rad/sec'); ylabel('|X(W)|'); title('discrete time fourier transform');
15
Department of ECE
RESULT
Thus the effect of sampling on the frequency domain quantities at different sampling frequencies was studied MATLAB program.
ALGORITHM
16
Department of ECE EC2306 Digital Signal Processing Lab 1. Get the pass band and stop band attenuation. 2. Get the pass band and stop band frequencies. 3 Get the sampling frequency 4. Calculate the order and cut off frequency. 5. Find out the filter co-efficient both numerator and denominator. 6. Draw the magnitude and phase response.
Department of ECE N= 1 omc = 0.5043 Transfer function: 0.5033 s + 0.5033 ----------------s + 0.006691 Transfer function: 0.7525 z - 0.2508 ----------------z - 0.9933 Sampling time: 1
OUTPUT RESPONSE
Department of ECE %Calculate the order of filter and cut-off frequency [N,omc]=cheb1ord(omp,oms,alphap,alphas); %Tofind out coefficient of analog filter [b,a]=cheby1(N,0.5,omc); %To find out the analog filter transfer function Hs=tf(b,a) %To find out the coefficient of digital filter [bz,az]=bilinear(b,a,1/T); %To find out the digital filter transfeer function Hz=tf(bz,az,T) %Draw the magnitude and phase response w=0:0.001:pi; h=freqz(b,a,w); subplot(2,1,1); plot(w/pi,20*log10(abs(h)),'k'); grid; xlabel('Normalised frequency'); ylabel('Gain in dB'); title('Magnitude response'); subplot(2,1,2); plot(w/pi,angle(h),'k'); grid; xlabel('Normalised frequency'); ylabel('Angle in radians'); title('Phase response');
Department of ECE Transfer function: 0.08254 s + 0.08254 ------------------s - 0.8349 Transfer function: 0.2125 z - 0.07085 -----------------z - 2.433 Sampling time: 1
OUTPUT RESPONSE
RESULT Thus the digital Butterworth and chebyshev Low Pass IIR Filter from the given specification was designed using MATLAB program.
Department of ECE
ALGORITHM
1. Get the number of samples of impulse response. 2. Get the cut off frequency. 3. Determine the value of infinite impulse response. 4. Choose the window sequence. 5. Determine the filter co-efficient of finite impulse response. 6. Draw the magnitude and phase response.
PROGRAM
%DESIGN OF DIGITAL FIR (LPF & HPF) FILTER USING RECTENGULAR WINDOW clc; rp=input('Enter the ripple of pass band (rp)='); rs=input('Enter the ripple of stop band (rs)='); fp=input('Enter the frequency of pass band (fp)='); fs=input('Enter the frequency of stop band (fs)='); f=input('Enter the Sampling Frequency (f)='); wp=(2*pi*fp)/f; ws=(2*pi*fs)/f; num=-20*log10(sqrt(rp*rs))-13; den=14.6*(fs-fp)/f; n=ceil(num/den); n1=n+1; y=boxcar(n1); %DESIGN OF LOW PASS FILTER b=fir1(n,wp,y); [h,o]=freqz(b,1,256); m=20*log10(abs(h)); subplot(1,2,1); plot(o/pi,m,'k'); title('LPF FREQUENCY RESPONSE'); %DESIGN OF HIGH PASS FILTER b=fir1(n,wp,'high',y); [h,o]=freqz(b,1,256); m=20*log10(abs(h)); subplot(1,2,2); plot(o/pi,m,'k'); title('HPF FREQUENCY RESPONSE'); INPUT DATA Enter the ripple of pass band (rp) =.04 Enter the ripple of stop band (rs) =.05 Enter the frequency of pass band (fp) =1500 Enter the frequency of stop band (fs) =2000 Enter the Sampling Frequency (f) =25000 21
Department of ECE
RESULT
Thus the linear phase Low Pass digital FIR Filter using different window was designed in MATLAB program.
ALGORITHM
1. Get the length of input sequence N. 2. Get the input sequence x(n) of length N in matrix form. 22
;0 k N 1
nk N
1 N
X (k )
k =0
N 1
;0 n N 1
Where = e j 2
-0.1716 - 0.4142i
-0.1716 + 0.4142i
OUTPUT RESPONSE
RESULT Thus the DFT and IDFT of the given sequence using FFT Algorithm in MATLAB program were
performed.
24
Department of ECE
ALGORITHM
1. Determine the analog value with respect to variation of time. 2. Get the sampling frequency. 3. Determine the discrete value with respect to variation of frequency. 4. Determine the Omega range from max to max . 5. Determine the magnitude of the signal. 6. Draw the discrete time signal and discrete Fourier transform.
Department of ECE subplot(2,1,2); plot(W/pi,X,'k'); grid; xlabel('normalised frequency in rad/sec'); ylabel('|X(W)|'); title('discrete time fourier transform');
Department of ECE
RESULT
Thus the Decimation by polyphase decomposition at different sampling frequencies was studied MATLAB program.
GENERATION OF SQUARE WAVE USING TMS320C50 AIM To generate a square wave with amplitude of 2 volts by using TMS320C50 DSP processor.
27
Department of ECE
APPARATUS REQUIRED TMS320C50 DSP processor kit, PC, CRO with probe. ALGORITHM 1. Start the program. 2. Load the amplitude of the square signal of 5 volts. 3. Load the frequency of the square signal. 4. Observe the square waveform by using CRO. 5. Stop the program. .END PROGRAM FOR GENERATION OF SQUARE WAVEFORM USING TMS320C50 .MMREGS .TEXT START: LDP #100H LACC #0FFFH ;change this value for amplitude. LOOP: SACL 0 RPT #0FFH ;change this value for frequency. OUT 0,04H ;address for dac. CMPL B LOOP
AMPLITUDE (volts)
Department of ECE
1 RESULT
1.6 * 2 = 3.2mse
2.5 * 2 = 5 V
Thus the square wave was generated using TMS320C50 DSP Processor.
GENERATION OF SAWTOOTH WAVE USING TMS320C50 AIM To generate a saw tooth wave with amplitude of 4 volts by using TMS320C50 DSP processor. APPARATUS REQUIRED TMS320C50 DSP processor kit, PC, CRO with probe. ALGORITHM 1. Start the program. 2. Load the amplitude of the saw tooth signal of 5 volts. 3. Load the frequency of the saw tooth signal. 4. Observe the saw tooth waveform by using CRO and stop the program. PROGRAM FOR GENERATION OF SAWTOOTH WAVEFORM USING TMS320C50 .MMREGS .TEXT START: LDP #120H LACC #0H ;change lower amplitude SACL 0
29
Department of ECE
OUT 0,04H LOOP: LACC 0 OUT 0,04H ADD #05H ;change frequency SACL 0 SUB #0FFFH ;change upper amplitude BCND LOOP,LEQ B START .END OBSERVATION S.No TIME PERIOD (msec) 1 1.6 * 2 = 3.2mse AMPLITUDE (volts) 2.5 * 2 = 5 V
RESULT Thus the saw tooth wave was generated using TMS320C50 DSP Processor.
Department of ECE
CONTx:
OBSERVATION S.No 1 RESULT Thus the triangular wave was generated using TMS320C50 DSP Processor. TIME PERIOD (msec) 1.6 * 2 = 3.2mse AMPLITUDE (volts) 2.5 * 2 = 5 V
PERFORM LINEAR CONVOLUTION OF TWO SEQUENCES AIM To perform the linear convolution of the two sequences using TMS320C50 DSP Processor. ALGORITHM 1. Get the two sequence x(n) and h(n) in matrix form. 2. The convolution of the two sequences is given by
y ( n) = x ( n ) h ( n ) =
k =
3. Stop the program. A) PROGRAM TO PERFORM LINEAR CONVOLUTION OF TWO SEQUENCES USING TMS320C50 .MMREGS .TEXT START: LDP #02H LAR AR1,#8100H ; x(n) datas LAR AR0,#8200H ;h(n) datas LAR AR3,#8300H ;y(n) starting LAR AR4,#0007 ;N1+N2-1 ;to fold the h(n) values LAR AR0,#08203H LACC #0C100H MAR *,AR0 RPT #3 TBLW *;padding of zerros for x(n) values LAR AR6,#8104H MAR *,ar6 LACC #0H RPT #3H SACL *+ ;convalution operation starts LOP: MAR *,AR1 LACC *+ SACL 050H ;starting of the scope of multiplication LAR AR2,#0153H ; end of the array, to be multiplied with h(n) {150+N11} MAR *,AR2 ZAP RPT #03H ;N1-1 times so that N1 times
32
Department of ECE
MACD 0C100H,*APAC ;to accmulate the final product sample MAR *,AR3 SACL *+ MAR *,AR4 BANZ LOP,*H: B H
INPUT AND OUTPUT SEQUENCE ;INPUT ( x(n) ) ;8100 - 1 ;8101 - 3 ;8102 - 1 ;8103 - 3 ;INPUT ( h(n) ) ; 8200 - 0 ; 8201 - 1 ; 8202 - 2 ; 8203 - 1 ;OUTPUT ( y(n) ) ; 8300 - 0 ; 8301 - 1 ; 8302 - 5 ; 8303 - 8 ; 8304 - 8 ; 8305 - 7 ; 8306 - 3
33
Department of ECE
.MMREGS .TEXT START: LDP #100H LACC 0H ;length of the input is given in 8000 SUB #1H SACL 1H LAR AR0,1H LAR AR1,#8060H; LAR AR2,#8100H COPYX2: MAR *,AR1 LACC *+ MAR *,AR2 SACL *+ MAR *,AR0 BANZ COPYX2,*LAR AR0,1H LAR AR2,#8010H LOOP3: LAR AR1,#8060H ;give the inputs x1[n] & h2[n] in AR1 & AR3 LAR AR3,#8050H LAR AR4,1H ZAP LOOP: MAR *,AR3 ;multiply x1[n] & X2[n] and add the;multiplication LT *+ MAR *,AR1 ;output 34
Department of ECE EC2306 Digital Signal Processing Lab MPY *+ SPL 5H ;store the partial result at location 8005 ADD 5H ; add the partial result with accumulator MAR *,AR4 BANZ LOOP,*MAR *,AR2 ;outputs of correlation are stored in AR2 SACL *+ CALL ROTATE LOOP2: MAR *,AR0 BANZ LOOP3,*002D`jhmgjmh B H
ROTATE: LDP #100H ;rotate the values of X1[n] LACC 1H SUB #1H SACL 2H LACC 0050H SACB ; 8050 DATA MOVED TO THE ACCUMULATOR TO THE ACCUMULATOR BUFFER LAR AR3,#8051H LAR AR5,#8070H LAR AR6,2H LOOP1: MAR *,AR3 LACC *+ MAR *,AR5 SACL *+ MAR *,AR6 BANZ LOOP1,*-; DATA FROM 8051-8053 TO 8070-8072 LACB ;MOVE THE DATA ACCUMULATOR BUFFER TO ACCUMULATOR AS LAST DATA MAR *,AR5 SACL *+ LACC #8070H SAMM BMAR LAR AR3,#8050H MAR *,AR3 RPT #3H ;ROTATE 4 TIMES BLDD BMAR,*+ ;BMAR AUTOMATICALLY INCREMENTED ,TO COPY SHIFTED DATA TO 8050 RET
35
Department of ECE
RESULT Thus the linear convolution of the two sequences was performed using TMS320C50 DSP Processor.
36
Department of ECE
ALGORITHM
1. Start the program. 2. Switch off the trainer kit. 3. Connect the function generator in the corresponding terminals. 4. Download the program to the trainer kit using Xtalk.exe 5. Quit from the Xtalk. 6. Enter into the basic TB.exe 7. Load and run the program "sample50.bas" which executes the ASM program and plots the samples on the screen.
SAMPLING THEOREM
;PROGRAM DESCRIPTION: In this program the samples are taken from the ADC with the desired sampling rate and the sample values are stored in the memory locations from the data memory 9000H. After taking 720 samples from the ADC the samples are sent through the serial port which is received by the basic program named "sample50.bas",and plots the samples in the pc screen.In this program the sampling rate is varied by varying the number in the address named DELAY. The delay value is also sent to the basic programas a first data. The distance between the samples in the basic program varies according to the delay value which it receives as a first data. ;Note: 37
Department of ECE EC2306 Digital Signal Processing Lab ;1. Swith off the trainer kit. ;2. Connect the function generator in the corresponding terminals. ;3. Download the program to the trainer kit using Xtalk.exe ;4. Quit from the Xtalk. ;5. Enter into the basic TB.exe ;6. Load and run the program "sample50.bas" which executes the asm program ; and plots the samples on the screen. ; TXD .SET 0H STS .SET 1H DATA .SET 2H DELAY B3 B2 B1 B0 .SET 3H
.SET 0F000H .SET 0F00H .SET 00F0H .SET 000FH .mmregs .text START: LDP #100H LAR AR0,#9000H LAR AR1,#719 REP: IN 0,06 RPT #0FH NOP IN 0,04 SPLK #5FFH,DELAY RPT DELAY NOP LACC 0 AND #0FFFH MAR *,AR0 SACL *+,0,AR1 BANZ REP,*LACC SACL CALL REPSER: LAR LAR REPSAMP: MAR LACC SACL CALL DELAY DATA SERIAL AR2,#9000H AR0,#719 *,AR2 *+ DATA SERIAL 38
;routine to send each digit of DATA individually to the serial port ;first send the start of character "%" ;seperate and send each digits of DATA from MSB ;send end of character "$" SERIAL SPLK #25H,TXD ;start of character "%" CALL TXDATA RPT #0FFFH
NOP LACC AND BSAR SACL CALL CALL RPT NOP LACC AND BSAR SACL CALL CALL RPT NOP LACC AND BSAR SACL CALL CALL RPT NOP LACC AND SACL CALL CALL RPT
DATA #B3 ;1st digit (from msb) 12 TXD HEXASC TXDATA #0FFFH DATA #B2 ;second digit 8 TXD HEXASC TXDATA #0FFFH DATA #B1 ;3rd digit 4 TXD HEXASC TXDATA #0FFFH DATA #B0 ;4th digit TXD HEXASC TXDATA #0FFFH 39
Department of ECE NOP SPLK #24H,TXD CALL TXDATA RPT #0FFFH NOP RET ;end of character "$"
;loop to conver hex data to ascii ;input is in address TXD ;output is also in TXD ;subtracts 9 from input hex data ;if >0 add 37h to input hex data ;Otherwise add 30h to input hex data HEXASC: LACC TXD SUB #9H BCND GRT9,GT LACC TXD ADD #30H SACL TXD RET GRT9: LACC TXD ADD #37H SACL TXD RET ;loop to send a character to the serial port ;checks the status of the serial port(TXREADY-bit2). ;if not 0, send that character. Otherwise checks it repeatedly. TXDATA: REPCHK: IN STS,9 LACC STS AND #04H BCND REPCHK,EQ OUT RET TXD,8
Department of ECE EC2306 Digital Signal Processing Lab Therefore it satisfies the above condition hence there is no aliasing effect.
RESULT
Thus the sampling of the given input signal was performed using TMS320C50 DSP Processor.
41
Department of ECE
ALGORITHM
1. Get the pass band and stop band ripples. 2. Get the pass band and stop band frequency. 3 Get the sampling frequency 4. Calculate the order the filter by using the formula,
2 1 2 1 A2 log 2 1 1 A2 1 1 N 2 log 2 1
5. Find the filter co-efficient. 6. Draw the magnitude and phase response.
PROGRAM
%DESIGN OF DIGITAL FIR (LPF & HPF) FILTER USING RECTENGULAR WINDOW clc; rp=input('Enter the ripple of pass band (rp)='); rs=input('Enter the ripple of stop band (rs)='); fp=input('Enter the frequency of pass band (fp)='); fs=input('Enter the frequency of stop band (fs)='); f=input('Enter the Sampling Frequency (f)='); wp=(2*pi*fp)/f; ws=(2*pi*fs)/f; num=-20*log10(sqrt(rp*rs))-13; den=14.6*(fs-fp)/f; n=ceil(num/den); n1=n+1; y=boxcar(n1); %DESIGN OF LOW PASS FILTER b=fir1(n,wp,y); [h,o]=freqz(b,1,256); m=20*log10(abs(h)); subplot(1,2,1); plot(o/pi,m,'k'); title('LPF FREQUENCY RESPONSE'); 42
Department of ECE %DESIGN OF HIGH PASS FILTER b=fir1(n,wp,'high',y); [h,o]=freqz(b,1,256); m=20*log10(abs(h)); subplot(1,2,2); plot(o/pi,m,'k'); title('HPF FREQUENCY RESPONSE'); INPUT DATA Enter the ripple of pass band (rp) =.04 Enter the ripple of stop band (rs) =.05 Enter the frequency of pass band (fp) =1500 Enter the frequency of stop band (fs) =2000 Enter the Sampling Frequency (f) =25000
RESULT Thus the digital FIR Filter (LPF and HPF) was implemented using TMS320C50 DSP Processor.
43
Department of ECE
44