Anda di halaman 1dari 56

Department of ECE Digital Signal Processing Lab

VEL TECH MULTI TECH Dr.RANGARAJAN


Dr.SAGUNTHALA ENGINEERING COLLEGE
( ISO 9001: 2008 Certified Institution & NBA Accredited )
(Owned by VEL Sree R.Rangarajan Dr. Sagunthala Rangarajan Educational Academy)
Approved by AICTE, New Delhi & Affiliated to Anna University
No 42, Alamathi Road, Near Avadi Chennai – 600 062

DEPARTMENT OF ELECTRONICS AND


COMMUNICATION ENGINEERING
LAB MANUAL
on
EC2306 - DIGITAL SIGNAL PROCESSING LAB
III YEAR V SEM ECE

Prepared By HOD/ECE PRINCIPAL

G.PANNEERSELVAM (MTS883)
R.KALPANA (MTS 1079)

1
Department of ECE Digital Signal Processing Lab

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

Quantity Quantity Deficiency


S.No. Description of Equipment
required available %

15 Units
PCs with Fixed / Floating point DSP
1. (2 students
Processors (Kit / Add-on Cards)
per system)

List of software required:


10 Users
2. MATLAB with Simulink and Signal
license
Processing Tool Box

3. Function Generators (1MHz) 15

4. CRO (20MHz) 15

EC2306 - DIGITAL SIGNAL PROCESSING LAB

AIM
2
Department of ECE Digital Signal Processing Lab

To introduce the student to various digital Signal Processing techniques using TMS 320c5x family
processors and MATLAB.

OBJECTIVES
● To implement the processing techniques using the instructions of TMS320C5X/TMS320C
67XX/ADSP 218X/219X/BS531/532/561
● To implement the IIR and FIR filter using MATLAB.

LIST OF EXPERIMENTS

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


1. Study of various addressing modes of DSP using simple programming examples
2. Implementation of Linear and Circular Convolution
3. Sampling of input signal and display
4. Waveform generation
5. Implementation of FIR filter
USING MATLAB
1. Generation of Signals
2. Linear and circular convolution of two sequences
3. Sampling and effect of aliasing
4. Design of FIR filters
5. Design of IIR filters
6. Calculation of FFT of a signal
7. Decimation by polyphase decomposition.

S.NO NAME OF THE EXPERIMENT PAGE NO

USING
3
Department of ECE Digital Signal Processing Lab

MATL
AB
1. Generation of Signals. 5

2. Linear and circular convolution of two sequences. 10

3. Sampling and effect of aliasing. 13

4. Design of Linear Phase Low Pass and High Pass FIR filters. 20

Design of Linear Phase Band Pass and Band Stop FIR filters. 20

5. Design of Butterworth / Chebyshev IIR filters. 16

6. Calculation of FFT of a signal. 22

7. Decimation by polyphase decomposition. 24


USING
TMS320
C5X
8. Simple Programming in TMS320C50.

9. Waveform Generation (Square, Saw tooth and Triangular Wave)

10. Implementation of linear & circular convolution of two sequences.

11. Sampling of input signal and display

12. Implementation of FIR filters.


BEYON
D THE
SYLLA
BUS
13. Auto and Cross Correlation of two sequences. 41

14. Power Spectrum Estimation Using Periodogram 43

4
Department of ECE Digital Signal Processing Lab

GENERATION OF INPUT SIGNALS


AIM
To generate a continuous time signal (Unit Step , Unit Ramp, Sine, Cosine, Square, and Saw tooth ) and
discrete time signal (Unit Step , Unit Ramp, Sine, Cosine, Exponential and Unit impulse) using
MATLAB function.
ALGORITHM
1. Get the length of different input sequence.
2. To plot the different input sequence.

A) PROGRAM FOR CONTINUOUS TIME SIGNALS


%program for unit step signal
clc;
t=0:1:10;
y=ones(1,11);
subplot(3,2,1);
plot(t,y,'k');
xlabel('Time');
ylabel('Amplitude');
title('Unit Step Signal');

%Program for unit ramp signal


t1=0:1:10;
y1=t1;
subplot(3,2,2);
plot(t1,y1,'k');
xlabel('Time');

ylabel('Amplitude');
title('Unit Ramp Signal');

%Program for sine wave


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

%Program for cosine wave


t=0:0.1:10;
y=cos(2*pi*t);
subplot(3,2,4);
plot(t,y,'k');

5
Department of ECE Digital Signal Processing Lab

xlabel('Time');

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');

OUTPUT RESPONSE

6
Department of ECE Digital Signal Processing Lab

B) PROGRAM FOR DISCRETE TIME SIGNALS

%Program for unit step sequence


clc;
N=input('Enter the lenght of unit step sequence(N)= ');
n=0:1:N-1;
y=ones(1,N);
subplot(3,2,1);
stem(n,y,'k');
xlabel('Time')
ylabel('Amplitude')
title('Unit step sequence');

%Program for unit ramp sequence


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

%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');

7
Department of ECE Digital Signal Processing Lab

%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 Digital Signal Processing Lab

OUTPUT RESPONSE

RESULT
Thus the continuous time signal and discrete time signal using MATLAB program was generated.
9
Department of ECE Digital Signal Processing Lab

PERFORM LINEAR AND CIRCULAR CONVOLUTION OF TWO SEQUENCES

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

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

; For Linear Convolution

; For Circular Convolution


3. Stop the program.

PROGRAM
A) TO PERFORM THE LINEAR CONVOLUTION OF TWO SEQUENCES
%input sequence
clc;
x=input('enter the input sequence x(n)=');
N1=length(x);
n=0:1:(N1-1);
subplot(3,1,1);
stem(n,x,'k');
xlabel('n-------->');
ylabel('amplitude');
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 response h(n)');

%output convolution
y=conv(x,h)
n2=0:1:(N1+N2-2);
subplot(3,1,3);
stem(n2,y,'k');

10
Department of ECE Digital Signal Processing Lab

xlabel('n--------->');
ylabel('amplitude');
title('linear convolution of two sequences');

INPUT AND OUTPUT SEQUENCES


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

y=

2 5 10 16 12 11 4

>>

OUPUT RESPONSE

B) TO PERFORM THE CIRCULAR CONVOLUTION OF TWO SEQUENCES


%FIRST SEQUENCE
clc;
x1=input('Enter the first input sequence x1(n)= ');
N1=length(x1);
%SECOND SEQUENCE

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


11
Department of ECE Digital Signal Processing Lab

N2=length(x2);

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

%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)]
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

INPUT AND OUTPUT SEQUENCES


enter the first input sequence x1(n)=[1 2 3 4]
enter the second input sequence x2(n)=[4 3]

x2 =

4 3 0 0

The output of circular convolution is


16

11

18

12
Department of ECE Digital Signal Processing Lab

25

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

SAMPLING AND EFFECT OF ALIASING.


AIM
To study the effect of sampling on the frequency domain quantities at different sampling frequencies.
a) Sample at samples/sec to obtain .Determine and plot .
b) Sample at samples/sec to obtain .Determine and plot .
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 to .
5. Determine the magnitude of the signal.
6. Draw the discrete time signal and discrete Fourier transform.

PROGRAM
SAMPLING AND EFFECT OF ALIASING
clc;
%Analog signal
t=-0.005:0.00005:0.005;
xa=exp(-1000*abs(t));

%Discrete time signal


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

%Discrete time fourier transform


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

%omega range from -Wmax to Wmax


W=[-fliplr(w),w(2:N+1)];

%X over -Wmax to Wmax interval


X=[fliplr(X),X(2:N+1)];
13
Department of ECE Digital Signal Processing Lab

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

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

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

subplot(2,1,2);
plot(W/pi,X,'k');
grid;
xlabel('normalised frequency in rad/sec');
ylabel('|X(W)|');
title('discrete time fourier transform');

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

14
Department of ECE Digital Signal Processing Lab

(b) Enter the sampling frequency (Fs)=1000


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

15
Department of ECE Digital Signal Processing Lab

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

DESIGN OF LINEAR PHASE LOW PASS AND HIGH PASS FIR DIGITAL
FILTERS
AIM
To design a linear phase Low Pass and High Pass FIR Digital Filter using different windows in
MATLAB Function.

16
Department of ECE Digital Signal Processing Lab

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.

A) PROGRAM FOR DESIGN OF LINEAR PHASE LOW PASS FILTER USING


DIFFERENT WINDOWS
clc;
N=input('Enter the number of samples (N)=');
wc=input('Enter the cut off frequency (wc)=');
alpha=(N-1)/2;

% To avoid the indeterminant value


eps=0.000001;

%To determine the infinite impulse response


n=0:1:(N-1);
hd=(sin(wc*(n-alpha+eps)))./(pi*(n-alpha+eps));

%Choose the rectangular window sequence


wr=boxcar(N);

%To determine the finite impulse response


hnr=hd.*wr'
w=0:0.001:pi;
h=freqz(hnr,1,w);
plot(w/pi,20*log10(abs(h)),'r.');
hold on

%Choose the hamming window sequence


wham=hamming(N);

%To determine the finite impulse response


hnm=hd.*wham'
w=0:0.001:pi;
h=freqz(hnm,1,w);
plot(w/pi,20*log10(abs(h)),'k.');
hold on

17
Department of ECE Digital Signal Processing Lab

%Choose the hanning window sequence


whan=hanning(N);

%To determine the finite impulse response


hnn=hd.*whan'
w=0:0.001:pi;
h=freqz(hnn,1,w);
plot(w/pi,20*log10(abs(h)),'g.');
hold on

%Choose the blackman window sequence


wb=blackman(N);

%To determine the finite impulse response


hnb=hd.*wb'
w=0:0.001:pi;
h=freqz(hnb,1,w);
plot(w/pi,20*log10(abs(h)),'b.');
grid;
xlabel('Normalized frequency in rad/sec');
ylabel('Gain in db');
title('Magnitude response of LPF');
hold off

INPUT AND OUTPUT SEQUENCE


Enter the number of samples (N)=9
Enter the cut off frequency (wc)=0.9*pi

hnr = -0.0757 0.0858 -0.0935 0.0984 0.9000 0.0984 -0.0935 0.0858 -0.0757

hnm = -0.0061 0.0184 -0.0505 0.0851 0.9000 0.0851 -0.0505 0.0184 -0.0061

hnn = -0.0072 0.0297 -0.0612 0.0890 0.9000 0.0890 -0.0612 0.0297 -0.0072

hnb = 0.0000 0.0057 -0.0318 0.0761 0.9000 0.0761 -0.0318 0.0057 0.0000

>>

OUTPUT RESPONSE (LPF)

18
Department of ECE Digital Signal Processing Lab

B) PROGRAM FOR DESIGN OF LINEAR PHASE HIGH PASS FILTER USING


DIFFERENT WINDOWS
clc;
N=input('Enter the number of samples (N)=');
wc=input('Enter the cut off frequency (wc)=');
alpha=(N-1)/2;

% To avoid the indeterminant value


eps=0.000001;

%To determine the infinite impulse response


n=0:1:(N-1);
hd=(sin(pi*(n-alpha+eps))-sin(wc*(n-alpha+eps)))./(pi*(n-alpha+eps));

%Choose the rectangular window sequence


wr=boxcar(N);

%To determine the finite impulse response


hnr=hd.*wr'
w=0:0.001:pi;
h=freqz(hnr,1,w);
plot(w/pi,20*log10(abs(h)),'r.');
hold on

%Choose the hamming window sequence


19
Department of ECE Digital Signal Processing Lab

wham=hamming(N);
%To determine the finite impulse response
hnm=hd.*wham'
w=0:0.001:pi;
h=freqz(hnm,1,w);
plot(w/pi,20*log10(abs(h)),'k.');
hold on

%Choose the hanning window sequence


whan=hanning(N);
%To determine the finite impulse response
hnn=hd.*whan'
w=0:0.001:pi;
h=freqz(hnn,1,w);
plot(w/pi,20*log10(abs(h)),'g.');
hold on

%Choose the blackman window sequence


wb=blackman(N);
%To determine the finite impulse response
hnb=hd.*wb'
w=0:0.001:pi;
h=freqz(hnb,1,w);
plot(w/pi,20*log10(abs(h)),'b.');
grid;
xlabel('Normalized frequency in rad/sec');
ylabel('Gain in db');
title('Magnitude response of LPF');
hold off

INPUT AND OUTPUT SEQUENCE


Enter the number of samples (N)=9
Enter the cut off frequency (wc)=0.8

hnr = 0.0046 -0.0717 -0.1591 -0.2283 0.7454 -0.2283 -0.1591 -0.0717 0.0046

hnm = 0.0004 -0.0154 -0.0859 -0.1976 0.7454 -0.1976 -0.0859 -0.0154 0.0004

hnn = 0.0004 -0.0248 -0.1041 -0.2065 0.7454 -0.2065 -0.1041 -0.0248 0.0004

hnb = -0.0000 -0.0048 -0.0541 -0.1766 0.7454 -0.1766 -0.0541 -0.0048 -0.0000

>>

20
Department of ECE Digital Signal Processing Lab

OUTPUT RESPONSE (HPF)

RESULT
Thus the linear phase Low Pass and High Pass FIR Digital Filter using different window was
designed in MATLAB program.

21
Department of ECE Digital Signal Processing Lab

DESIGN OF LINEAR PHASE BAND PASS AND BAND STOP FIR DIGITAL
FILTERS
AIM
To design a linear phase Band Pass and Band Stop FIR Digital Filter using different windows in
MATLAB Function.
ALGORITHM
1. Get the number of samples of impulse response.
2. Get the cut off frequencies (wc1 & wc2).
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.
A) PROGRAM FOR DESIGN OF LINEAR PHASE BAND PASS FILTER USING
DIFFERENT WINDOWS
clc;
N=input('Enter the number of samples (N)=');
wc1=input('Enter the lower cut off frequency (wc1)=');
wc2=input('Enter the upper cut off frequency (wc2)=');

alpha=(N-1)/2;

% To avoid the indeterminant value


eps=0.000001;

%To determine the infinite impulse response


n=0:1:(N-1);
hd=(sin(wc2*(n-alpha+eps))-sin(wc1*(n-alpha+eps)))./(pi*(n-alpha+eps));

%Choose the rectangular window sequence


wr=boxcar(N);

%To determine the finite impulse response


hnr=hd.*wr'
w=0:0.001:pi;
h=freqz(hnr,1,w);
plot(w/pi,20*log10(abs(h)),'r.');
hold on

%Choose the hamming window sequence


wham=hamming(N);

%To determine the finite impulse response


hnm=hd.*wham'

22
Department of ECE Digital Signal Processing Lab

w=0:0.001:pi;
h=freqz(hnm,1,w);
plot(w/pi,20*log10(abs(h)),'k.');
hold on

%Choose the hanning window sequence


whan=hanning(N);

%To determine the finite impulse response


hnn=hd.*whan'
w=0:0.001:pi;
h=freqz(hnn,1,w);
plot(w/pi,20*log10(abs(h)),'g.');
hold on
%Choose the blackman window sequence
wb=blackman(N);

%To determine the finite impulse response


hnb=hd.*wb'
w=0:0.001:pi;
h=freqz(hnb,1,w);
plot(w/pi,20*log10(abs(h)),'b.');
grid;
xlabel('Normalized frequency in rad/sec');
ylabel('Gain in db');
title('Magnitude response of LPF');
hold off

INPUT AND OUTPUT SEQUENCE


Enter the number of samples (N)=9
Enter the lower cut off frequency (wc1)=pi/4
Enter the upper cut off frequency (wc2)=3*pi/4

hnr = 0.0000 -0.0000 -0.3183 0.0000 0.5000 -0.0000 -0.3183 0.0000 -0.0000

hnm = 0.0000 -0.0000 -0.1719 0.0000 0.5000 -0.0000 -0.1719 0.0000 -0.0000

hnn = 0.0000 -0.0000 -0.2083 0.0000 0.5000 -0.0000 -0.2083 0.0000 -0.0000

hnb = -0.0000 -0.0000 -0.1082 0.0000 0.5000 -0.0000 -0.1082 0.0000 0.0000

>>

23
Department of ECE Digital Signal Processing Lab

OUTPUT RESPONSE (BPF)

B) PROGRAM FOR DESIGN OF LINEAR PHASE BAND STOP FILTER USING


DIFFERENT WINDOWS
clc;
N=input('Enter the number of samples (N)=');
wc1=input('Enter the lower cut off frequency (wc1)=');
wc2=input('Enter the upper cut off frequency (wc2)=');
alpha=(N-1)/2;

% To avoid the indeterminant value


eps=0.000001;

%To determine the infinite impulse response


n=0:1:(N-1);
hd=( sin(pi*(n-alpha+eps))+sin(wc1*(n-alpha+eps))-sin(wc2*(n-alpha+eps)))./(pi*(n-alpha+eps));

%Choose the rectangular window sequence


wr=boxcar(N);

%To determine the finite impulse response


hnr=hd.*wr'
24
Department of ECE Digital Signal Processing Lab

w=0:0.001:pi;

h=freqz(hnr,1,w);
plot(w/pi,20*log10(abs(h)),'r.');
hold on

%Choose the hamming window sequence


wham=hamming(N);
%To determine the finite impulse response
hnm=hd.*wham'
w=0:0.001:pi;
h=freqz(hnm,1,w);
plot(w/pi,20*log10(abs(h)),'k.');
hold on

%Choose the hanning window sequence


whan=hanning(N);
%To determine the finite impulse response
hnn=hd.*whan'
w=0:0.001:pi;
h=freqz(hnn,1,w);
plot(w/pi,20*log10(abs(h)),'g.');
hold on

%Choose the blackman window sequence


wb=blackman(N);
%To determine the finite impulse response
hnb=hd.*wb'
w=0:0.001:pi;
h=freqz(hnb,1,w);
plot(w/pi,20*log10(abs(h)),'b.');
grid;
xlabel('Normalized frequency in rad/sec');
ylabel('Gain in db');
title('Magnitude response of LPF');
hold off

INPUT AND OUTPUT SEQUENCE


Enter the number of samples (N)=9
Enter the lower cut off frequency (wc1)=pi/4
Enter the upper cut off frequency (wc2)=3*pi/4

hnr = -0.0000 0.0000 0.3183 0.0000 0.5000 -0.0000 0.3183 -0.0000 0.0000

hnm = -0.0000 0.0000 0.1719 0.0000 0.5000 -0.0000 0.1719 -0.0000 0.0000

hnn = -0.0000 0.0000 0.2083 0.0000 0.5000 -0.0000 0.2083 -0.0000 0.0000

25
Department of ECE Digital Signal Processing Lab

hnb = 0.0000 0.0000 0.1082 0.0000 0.5000 -0.0000 0.1082 -0.0000 -0.0000

OUTPUT RESPONSE (BSF)

RESULT
Thus the linear phase Band Pass and Band Stop FIR Digital Filter using different window was
designed in MATLAB program.

26
Department of ECE Digital Signal Processing Lab

DESIGN OF IIR DIGITAL FILTERS


AIM
To design a digital Butterworth and chebyshev Low pass IIR Filter from the given specification
using MATLAB Function.
ALGORITHM
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.

A) PROGRAM FOR DESIGN OF BUTTERWORTH DIGITAL IIR FILTER


clc;
alphap=input('Enter the passband attenuation in dB (alphap)= ');
alphas=input('Enter the stopband attenuation in dB (alphas)= ');
omp=input('Enter the stopband frequency in rad/sec (omp)= ');
oms=input('Enter the stopband frequency in rad/sec (oms)= ');
T=input('Enter the sampling time in sec(T)= ');

%Calculate the order of filter and cut-off frequency


[N,omc]=buttord(omp,oms,alphap,alphas)
%Tofind out coefficient of analog filter
[b,a]=butter(N,omc);
%To find out the analog filter transfer 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,1);
plot(w/pi,angle(h),'k');
grid;
xlabel('Normalised frequency');
ylabel('Angle in radians');
27
Department of ECE Digital Signal Processing Lab

title('Phase response');

INPUT AND OUTPUT DATA


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

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

28
Department of ECE Digital Signal Processing Lab

B) PROGRAM FOR DESIGN OF CHEBYSHEV DIGITAL IIR FILTER


clc;
alphap=input('Enter the passband attenuation in dB (alphap)= ');
alphas=input('Enter the stopband attenuation in dB (alphas)= ');
omp=input('enter the passband frequency in rad/sec(omp)=');
oms=input('enter the stopband frequency in rad/sec(oms)=');
T=input('enter the sampling time in sec(T)=');

%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);
29
Department of ECE Digital Signal Processing Lab

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

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

INPUT AND OUTPUT DATA


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

N=
1

omc =

0.5043

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

30
Department of ECE Digital Signal Processing Lab

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

COMPUTATION OF DFT AND IDFT USING FFT ALGORITHM


AIM
To compute the DFT and IDFT of the given sequence using FFT Algorithm in MATLAB program.
ALGORITHM
1. Get the length of input sequence N.
2. Get the input sequence x(n) of length N in matrix form.

2. DFT and IDFT of sequences is given by

Where
3. Stop the program.

PROGRAM FOR COMPUTATION OF DFT AND IDFT USING FFT


ALGORITHM
clc;
31
Department of ECE Digital Signal Processing Lab

N=input('Enter the length of the sequence(N)= ');


x=input('Enter the input sequence x(n)= ');
n=0:1:(N-1);
subplot(2,2,1);
stem(n,x,'k');
xlabel('n---->');
ylabel('Amplitude');
title('Input sequence');

%Computation of DFT using FFT


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

%Computation of IDFT using FFT


n=0:1:(N-1);
x=ifft(X,N)
subplot(2,2,4);
stem(n,abs(x),'k');

xlabel('n---->');
ylabel('Amplitude');
title('Magnitude plot (IDFT)');

INPUT AND OUTPUT SEQUENCE


Enter the length of the sequence(N)= 8
Enter the input sequence x(n)= [1 2 3 4 4 3 2 1]
X=

Columns 1 through 6

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

Columns 7 through 8

0 -5.8284 + 2.4142i

x=

32
Department of ECE Digital Signal Processing Lab

1 2 3 4 4 3 2 1

OUTPUT RESPONSE

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

DECIMATION BY POLYPHASE DECOMPOSITION


AIM
To perform the down sampling (decimation) and up sampling (interpolation) of the given input signal

.
ALGORITHM
1. Start the program.
2. Get the input sequence value and time period of the sequence is obtained as input for decimation and
interpolation.
3. Get the down sampling and up sampling of values is obtained as input.
4. Plot the output response for Decimation and Interpolation

A).PROGRAM FOR DECIMATION OF INPUT SIGNAL


clc;
%decimation of given input signal
N=input('Enter the length of the samples (N)=');

33
Department of ECE Digital Signal Processing Lab

t1=input('Enter the first time period (t1)=');


t2=input('Enter the second time period(t2)=');
D=input('Enter the down sampling factor (D)=');
n=0:1:(N-1);
X=sin(2*pi*n*t1)+sin(2*pi*n*t2);
Y=decimate(X,D);

subplot(2,1,1);
stem(n,X(1:N),'k');
grid;
xlabel('samples(n)');
ylabel('Amplitude');
title('Sampled signal');

subplot(2,1,2);
d=0:1:(N/D-1);
stem(d,Y(1:N/D),'k');
grid;
xlabel('Samples(n)');
ylabel('Amplitude');
title('Down sampled signal');

INPUT AND OUTPUT DATA


Enter the length of the samples (N)=150
Enter the first time period (t1)=0.01
Enter the second time period (t2)=0.5
Enter the down sampling factor (D)=3
>>

OUTPUT RESPONSE

34
Department of ECE Digital Signal Processing Lab

B).PROGRAM FOR INTERPOLATION OF INPUT SIGNAL


clc;
%Interpolation of given input signal
N=input('Enter the length of samples(N)=');
t1=input('Enter the first time period(t1)=');
t2=input('Enter the second time period(t2)=');
I=input('Enter the up sampling factor(I)=');
n=0:1:(N-1);
X=sin(2*pi*n*t1)+sin(2*pi*n*t2)
Y=interp(X,I);

subplot(2,1,1);
stem(n,X(1:N),'k');
grid;
xlabel('samples(n)');
ylabel('Amplitude');
title('sampled signal');

subplot(2,1,2);
i=0:1:(N/I-1);
stem(i,Y(1:N/I),'k');

35
Department of ECE Digital Signal Processing Lab

grid;
xlabel('samples(n)');
ylabel('Amplitude');
title('up sampled signal');

INPUT AND OUTPUT DATA


Enter the length of the samples (N)=150
Enter the first time period (t1)=0.01
Enter the second time period (t2)=0.5
Enter the down sampling factor (D)=3
>>

OUTPUT RESPONSE

RESULT
Thus the decimation and interpolation of the given input signal had been done and the output was
verified using MATLAB program.

36
Department of ECE Digital Signal Processing Lab

SIMPLE PROGRAMMING USING TMS320C50


AIM
To perform the Addition, Subtraction, Multiplication, 1’s and 2’s Complements, AND and OR operations
of the given numbers 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.
A) PROGRAM FOR ADDITION OF TWO NUMBERS USING TMS320C50

.MMREGS
.TEXT
START: LDP #100H
LACC 00H
ADD 01H
SACL 02H
H: B H

OUTPUT:
;input: 8000-0002
; 8001-0002
;output: 8002-0004

B) PROGRAM FOR SUBRACTION OF TWO NUMBERS USING TMS320C50

.MMREGS
.TEXT
START: LDP #100H
LACC 00H
SUB 01H
SACL 02H
H: B H

OUTPUT:
;input: 8000-0003
; 8001-0002
;output: 8002-0001

37
Department of ECE Digital Signal Processing Lab

C) PROGRAM FOR MULTIPLICATION OF TWO NUMBERS USING TMS320C50

.MMREGS
.TEXT
START: LDP #100H
LT 00H
MPY 01H
PAC
SACL 02H
H: B H

OUTPUT:
;input: 8000-0002
; 8001-0002
;output: 8002-0004

D) PROGRAM FOR 1’s COMPLEMENT OF TWO NUMBERS USING TMS320C50


.MMREGS
.TEXT
START: LDP #100H
LACC 00H
CMPL
SACL 01H
H: B H

OUTPUT:
;input: 8000-0001

;output: 8001-1110 (1’s Complement)

E) PROGRAM FOR 2’s COMPLEMENT OF TWO NUMBERS USING TMS320C50

.MMREGS
.TEXT
START: LDP #100H
LACC 00H
CMPL
ADD #1
SACL 01H
H: B H

OUTPUT:
;input: 8000-0001

;output: 8001-1111 (2’s Complement)

38
Department of ECE Digital Signal Processing Lab

F) PROGRAM FOR AND OPERATION OF GIVEN NUMBER USING TMS320C50

.MMREGS
.TEXT
START: LDP #100H
LACC 00H
AND 01H
SACL 02H
H: B H

OUTPUT:
;input: 8000-0001
; 8001-1011
;output: 8002-0001

G) PROGRAM FOR OR OPERATION OF GIVEN NUMBER USING TMS320C50

.MMREGS
.TEXT
START: LDP #100H
LACC 00H
OR 01H
SACL 02H
H: B H
OUTPUT:
;input: 8000-0001
; 8001-1011
;output: 8002-1011

RESULT
Thus the Addition, Subtraction, Multiplication, 1’s and 2’s Complements, AND and OR
operations of the given numbers was performed using TMS320C50 DSP Processor.

39
Department of ECE Digital Signal Processing Lab

GENERATION OF WAVEFORM USING TMS320C50


AIM
To generate a different wave forms (Square, Saw tooth and Triangular Wave) with amplitude of 5
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 input signal of 5 volts.
3. Load the frequency of the input signal.
4. Observe the waveform by using CRO.
5. Stop the program.
A) 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
.END
B) PROGRAM FOR GENERATION OF SAWTOOTH WAVEFORM USING
TMS320C50
.MMREGS
.TEXT
START: LDP #120H
LACC #0H ; change lower amplitude
SACL 0
LOOP: LACC 0
OUT 0,04H
ADD #05h ; change frequency
SACL 0
SUB #0FFFh ; change upper amplitude
BCND LOOP, LEQ
B START
.END
40
Department of ECE Digital Signal Processing Lab

C) PROGRAM FOR GENERATION OF TRIANGULAR WAVEFORM


USING TMS320C50 PROCESSOR
AMPLITUDE .SET 4
FREQ .SET 350
TEMP .SET 0
;
.MMREGS
.TEXT
START: LDP #100H
SPLK #0,TEMP
CONT1: LAR AR2,#FREQ
CONT: OUT TEMP,4
LACC TEMP
ADD #AMPLITUDE
SACL TEMP
MAR *,AR2
BANZ CONT,*-
LAR AR2,#FREQ
CONTx: OUT TEMP,4
LACC TEMP
SUB #AMPLITUDE
SACL TEMP
MAR *,AR2
BANZ CONTx
B CONT1

OBSERVATION
NAME OF TIME PERIOD
S.No AMPLITUDE (volts)
WAVEFORMS (msec)

1. Square Wave 1.6 * 2 = 3.2mse 2.5 * 2 = 5 V

2. Saw tooth Wave 1.6 * 2 = 3.2mse 2.5 * 2 = 5 V

3. Triangular Wave 1.6 * 2 = 3.2mse 2.5 * 2 = 5 V

RESULT

41
Department of ECE Digital Signal Processing Lab

Thus the Square, Saw tooth and Triangular Wave was generated using TMS320C50 DSP
Processor.

PERFORM LINEAR AND CIRCULAR CONVOLUTION OF TWO SEQUENCES

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

For Linear Convolution

For Linear Convolution


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+N1-1}

42
Department of ECE Digital Signal Processing Lab

MAR *,AR2
ZAP
RPT #03H ;N1-1 times so that N1 times

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

43
Department of ECE Digital Signal Processing Lab

B) PROGRAM TO PERFORM CIRCULAR CONVOLUTION OF TWO


SEQUENCES USING TMS320C50
.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
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:
44
Department of ECE Digital Signal Processing Lab

MAR *,AR0
BANZ LOOP3,*-

H: 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

45
Department of ECE Digital Signal Processing Lab

INPUT AND OUTPUT SEQUENCE


;INPUT:
; 8000-0004
;

;X1(n) = 8050 - 0002


; 8051 - 0001
; 8052 - 0002
; 8053 - 0001
;

;H2(n ) = 8060 - 0001


; 8061 - 0002
; 8062 - 0003
; 8063 - 0004

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

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

46
Department of ECE Digital Signal Processing Lab

SAMPLING OF INPUT SIGNAL AND DISPLAY


AIM
To perform the sampling of the given input signal using TMS320C50 DSP Processor and plot its wave
form.
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.

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 screening 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:
;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.
47
Department of ECE Digital Signal Processing Lab

.MMREGS
.TEXT
START: LDP #140H
LOOP: IN 0,06
NOP
NOP
IN 0,04
LACC 0
AND #0FFFH
ADD #0800H
SACL 0
OUT 0,04
B LOOP
OUTPUT RESPONSE

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

48
Department of ECE Digital Signal Processing Lab

IMPLEMENTATION OF FIR FILTERS


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

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,
5. Find the filter co-efficient.
6. Draw the magnitude and phase response.

PROGRAM FOR IMPLEMENTATION OF LOW PASS FIR FILTER USING


BLACKMANN WINDOW IN TMS320C50 DSP PROCESSOR
* Approximation type: Window design - Blackmann Window
* Filter type: Low pass filter
* Filter Order: 52
* Cutoff frequency in KHz = 3.000000

.MMREGS
.TEXT
B START
CTABLE:
.word 0FFE7H ; Filter coefficients n=0
.word 0FFD3H
.word 0FFC6H
.word 0FFC4H
.word 0FFD0H
.word 0FFECH
.word 018H
.word 051H
.word 08CH
.word 0B9H
.word 0C2H
.word 092H
.word 01AH
.word 0FF5FH
.word 0FE78H
.word 0FD9AH
.word 0FD10H
.word 0FD30H
.word 0FE42H
.word 071H
.word 03B5H
49
Department of ECE Digital Signal Processing Lab

.word 07CAH
.word 0C34H
.word 01054H
.word 01387H
.word 01547H
.word 01547H
.word 01387H
.word 01054H
.word 0C34H
.word 07CAH
.word 03B5H
.word 071H
.word 0FE42H
.word 0FD30H
.word 0FD10H
.word 0FD9AH
.word 0FE78H
.word 0FF5FH
.word 01AH
.word 092H
.word 0C2H
.word 0B9H
.word 08CH
.word 051H
.word 018H
.word 0FFECH
.word 0FFD0H
.word 0FFC4H
.word 0FFC6H
.word 0FFD3H
.word 0FFE7H ; Filter coefficients n=52

* Move the Filter coefficients


* From program memory to data memory
*
START:
MAR *, AR0 ; This block moves the filter coefficient from pgm memory to data
memory.
LAR AR0, #0200H
RPT #33H
BLKP CTABLE,*+
SETC CNF
*
* Input data and perform convolution
*
ISR: LDP #0AH
LACC #0
50
Department of ECE Digital Signal Processing Lab

SACL 0

OUT 0, 05
IN 0,06H
LAR AR7, #0
MAR *, AR7
BACK: BANZ BACK,*-
IN 0, 4
NOP
NOP
NOP
NOP
MAR *, AR1
LAR AR1, #0300H
LACC 0
AND #0FFFH
SUB #800H
SACL *
LAR AR1, #333H
MPY #0
ZAC
RPT #33H
MACD 0FF00H,*- ; CONVOLUTION OPERATION
APAC
LAR AR1, #0300H
SACH *
LACC *
ADD #800h
SACL *
OUT *, 4
LACC #0FFH
SACL 0
OUT 0, 05
NOP
B ISR
.END

51
Department of ECE Digital Signal Processing Lab

OUTPUT RESPONSE FOR LPF & HPF

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

52
Department of ECE Digital Signal Processing Lab

AUTOCORRELATION AND CROSS CORRELATION OF THE SEQUENCES

AIM
To perform auto and Cross correlation of the two sequences using MATLAB function.

ALGORITHM
1. Get the input sequences in matrix form.
2. The correlation of the two sequences is given by

; For Auto Correlation

; For Cross Correlation


PROGRAM
clc;
disp('Autocorrelation and cross correlation of sequences')
disp('1 autocorrelation 2 cross correlation');
choice = input('Enter the choice of correlation = ');

switch(choice)
case{1} % Autocorrelation of the sequence
x = input('Enter the sequence x = ');
y = fliplr(x); % flip the sequence in left/right direction
r = conv(x,y) % Compute the correlation sequence
stem(r); % display the correlation sequence
xlabel('n'); ylabel('Amplitude'); grid;
title('Autocorrelation');

case{2} % Cross correlation of the sequences


x = input('Enter the sequence x = ');
y = input('Enter the sequence y = ');
z = fliplr(y);% flip one of the the sequence in left/right direction
r = conv(x,z) % Compute the correlation sequence
stem(r); % display the correlation sequence
xlabel('n'); ylabel('Amplitude'); grid;
title('Cross correlation');
end

53
Department of ECE Digital Signal Processing Lab

INPUT AND OUTPUT SEQUENCE

Case 1:
Autocorrelation and cross correlation of sequences
1 autocorrelation 2 cross correlation
Enter the choice of correlation = 1
Enter the sequence x = [1 2 3 4]

r=

4 11 20 30 20 11 4

>>
Case 2:
Autocorrelation and cross correlation of sequences
1 autocorrelation 2 cross correlation
Enter the choice of correlation = 2
Enter the sequence x = [1 2 3 4]
Enter the sequence y = [4 3 2 1]

r=

1 4 10 20 25 24 16

>>

RESULT
Thus the auto and Cross correlation of the two sequences using MATLAB program was
performed.

POWER SPECTRUM ESTIMATION USING PERIODOGRAM

54
Department of ECE Digital Signal Processing Lab

AIM
To compute the Power Spectrum Estimation using Periodogram in MATLAB function.

ALGORITHM
1. Get the length input sequences.
2. Get the input sequences in matrix form.
3. Find the signal sum of two sinusoids and random noise.
4. Stop the program.

PROGRAM
%Power Spectrum Estimation using Periodogram
clc;
N=input('Enter the length of the sequence (N)=');
window=hamming(N);
nfft=input('Enter the length of the FFT=');
Fs=input('Enter the sampling frequency (Fs)=');
n=0:1:N-1;
% signal sum of two sinusoids and random noise
x=cos(2*pi*n/Fs)+sin(2*pi*n/Fs)+0.01*randn(size(n));
subplot(2,1,1);
plot(n,x,'k');
xlabel('n');
ylabel('x(n)');
[pxx,f]=periodogram(x,window,nfft,Fs);
subplot(2,1,2)
plot(f/Fs,10*log10(pxx),'k');
grid;
xlabel('\omega/\pi');
ylabel('Power Spectrum');

INPUT AND OUTPUT DATA


Enter the length of the sequence (N)=200
Enter the length of the FFT=10
Enter the sampling frequency (Fs)=100
>>

OUTPUT RESPONSE

55
Department of ECE Digital Signal Processing Lab

RESULT
Thus the power spectrum estimation using periodogram in MATLAB function was performed.

56

Anda mungkin juga menyukai