DSP LAB MANUAL
For
5 ^{T}^{H} SEMESTER ELECTRONICS AND COMMUNICATION ENGINEERING
SITECH ELECTRONICS No.2,”ASHRAYA APARTMENTS” Opp.to S B I, Athmananda Colony Sulthanpalya, R.T.Nagar, BENGALURU 560032, PH: +91 8023339222, Tele /Fax: 23335449 EMail: info@chipmaxindia.com Web: www.chipmaxindia.com
CONTENTS
PARTA. LIST OF EXPERIMENTS USING MATLAB
1. Verification of sampling theorem.
2. Impulse response of a given system.
3. Linear convolution of two given sequences.
4. Circular convolution of two given sequences.
5. Autocorrelation of given sequence and verification of its properties.
6. Cross correlation of a given sequences and verification of its properties.
7. Solving a given difference equation.
8. Computation of Npoint DFT of a given sequence and to plot magnitude and phase spectrum.
9. Linear convolution of two sequences using DFT and IDFT.
10. Circular convolution of two sequences using DFT and IDFT.
11. Design and implementation of FIR filter to meet given specifications.
12. Design and implementation of IIR filter to meet given specifications.
PARTB. LIST OF EXPERIMENTS USING DSP PROCESSOR.
1. Linear convolution of two given sequences.
2. Circular convolution of two given sequences.
3. Computation of Npoint DFT of a given sequence.
4. Realization of an FIR filter (any type) to meet given specifications. The input can be a signal from function generator/speech signal.
5. Audio application such as to plot a time and frequency display of a Microphone plus a cosine using DSP. Read a .wav file and match with their respective spectrograms.
6. Noise removal: Add noise above 3KHz and then remove, interference suppression using 400Hz tone.
7. Impulse response of first order and second order system.
2
3
EXPERIMENT NO1
AIM: VERIFICATION OF SAMPLING THEOREM
Sampling: Is the process of converting a continuous time signal into a discrete time signal. It is the first step in conversion from analog signal to digital signal.
Sampling theorem: Sampling theorem states that “Exact reconstruction of a continuous time baseband signal from its samples is possible, if the signal is bandlimited and the sampling frequency is greater than twice the signal bandwidth”. i.e. f _{s} > 2W, where W is the signal bandwidth.
Nyquist Rate Sampling: The Nyquist rate is the minimum sampling rate required to avoid aliasing, equal to the highest modulating frequency contained within the signal. In other words, Nyquist rate is equal to two sided bandwidth of the signal (Upper and lower sidebands) To avoid aliasing, the sampling rate must exceed the Nyquist rate. i.e. _{f} _{s} _{>} _{f} _{N}
Program:
% Nyquist Rate Sampling. clc; fs = 1400;
% Clear screen % Sampling frequency, fs = 1400Hz
t 
= 0:1/fs:13/fs; 
% Number of samples 
x 
= cos(2*pi*400*t)+cos(2*pi*700*t); % Input signal 
xm = abs (fft(x)); disp(‘xm’); disp (xm);
k = 0:length(xm)1;
subplot (2,2,1); stem (100*k, xm); xlabel ('Hz'); ylabel ('Magnitude'); title ('NR sampling');
%UNDER Sampling. fs = 1000;
% Determine the absolute FFT of the input signal % Displays xm on command window % Displays values of xm on command window
% Number of samples to be plot on xaxis % Divide the figure window to plot the output % Plot the output % Name xaxis as “Hz” % Name yaxis as “Magnitude” % Title is “NR Sampling”
% Sampling frequency, fs = 1000Hz
t 
= 0:1/fs:9/fs; 
% Number of samples 
x 
= cos(2*pi*400*t)+cos(2*pi*700*t); % Input signal 

xm1 = abs(fft(x)); 
% Determine the absolute FFT of the input signal 

disp(‘xm1’); 
% Displays xm1 on command window 

disp (xm1); 
% Displays values of xm1 on command window 
k = 0:length(xm1)1;
subplot(2,2,2);
stem(100*k, xm1); xlabel('Hz'); ylabel('Magnitude');
% Number of samples to be plot on xaxis % Divide the figure window to plot the output % Plot the output % Name xaxis as “Hz” % Name yaxis as “Magnitude”
4
title('UNDER sampling');
% Title is “UNDER Sampling”
%OVER Sampling. fs = 2000;
t = 0:1/fs:20/fs;
x = cos(2*pi*400*t)+cos(2*pi*700*t); % Input signal
% Sampling frequency, fs = 2000Hz % Number of samples
xm2 = abs(fft(x)); 
% Determine the absolute FFT of the input signal 
disp(‘xm2’); 
% Displays xm2 on command window 
disp (xm2); 
% Displays values of xm2 on command window 
k = 0:length(xm2)1;
subplot(2,2,3);
stem(100*k,xm2);
xlabel('Hz'); ylabel('Magnitude'); title('OVER sampling');
Output :
xm
Columns 1 through 7
% Number of samples to be plot on xaxis % Divide the figure window to plot the output % Plot the output % Name xaxis as “Hz” % Name yaxis as “Magnitude” % Title is “OVER Sampling”
0.0000 
0.0000 
0.0000 
0.0000 
7.0000 
0.0000 
0.0000 
Columns 8 through 14 

14.0000 
0.0000 
0.0000 
7.0000 
0.0000 
0.0000 
0.0000 
xm1 

Columns 1 through 7 

0.0000 
0.0000 
0.0000 
5.0000 
5.0000 
0.0000 
5.0000 
Columns 8 through 10 

5.0000 
0.0000 
0.0000 

xm2 

Columns 1 through 7 

2.0000 
2.0741 
2.3496 
3.1607 
11.5127 
0.4052 
1.8998 
Columns 8 through 14 

8.6165 
4.2355 
1.2552 
0.3357 
0.3357 
1.2552 
4.2355 
Columns 15 through 21 

8.6165 
1.8998 
0.4052 
11.5127 
3.1607 
2.3496 
2.0741 
5 
Graph:
6
EXPERIMENT NO2
AIM: IMPULSE RESPONSE OF A GIVEN SYSTEM
A discrete time system performs an operation on an input signal based on a predefined
criteria to produce a modified output signal. The input signal x(n) is the system excitation, and y(n) is the system response. The transform operation is shown as,
y(n) = T[(x(n)]
If the input to the system is unit impulse i.e. x(n) = δ(n) then the output of the system is
known as impulse response denoted by h(n) where,
h(n) = T[δ(n)]
we know that any arbitrary sequence x(n) can be represented as a weighted sum of discrete impulses. Now the system response is given by,
∞
y(n) = T[x(n)] = T[∑x(k) δ(nk)]
k=∞
For linear system (1) reduces to
∞
y(n) = ∑x(k) T[δ(nk)]
k=∞
…(1)
…(2)
The response to the shifted impulse sequence can be denoted by h(n, k) is denoted by,
h(n, k) = T[δ(nk)] 
…(3) 
For a timeinvariant system 

h(n, k) = h(nk) 
…(4) 
Using (4) in (3) we obtain, 

T[δ(nk)] = h(nk) 
…(5) 
Using (5) in (2) we get, 

∞ 

y(n) = ∑x(k) h(nk) 
…(6) 
k=∞
7
For a linear timeinvariant system if the input sequence is x(n) and impulse response h(n) is given, we can fine output y(n) by using eqn (6). Which is known as convolution sum and can be represented by y(n) = x(n) * h(n)
For Example let’s find out an impulse response of a difference equation. The general form of difference equation is,
M 
M 

y(n) = ∑a _{k} y(nk) + ∑b _{k} x(nk) 
…(7) 

k=1 
k=0 

For input x(n) = δ(n) 

M 

y(n) = ∑b _{k} x(nk) = 0 
for n > M 

k=0 

Now (7) can be written as, 

N 

y(n) = ∑a _{k} y(nk) = 0 
a _{0} = 1 
…(8) 
k=0
The solution of eqn (8) is known as homogeneous solution. The particular solution is zero since x(n) = 0 for n > 0, that is
y _{p} (n) = 0
Therefore we can obtain the impulse response by solving the homogeneous equation and imposing the initial conditions to determine the arbitrary constants.
Example:
Let’s take a second order difference equation
y(n) – (1/6) y(n1) –(1/6) y(n2) = x(n) 
…(9) 
For impulse response the particular solution y _{p} (n) = 0 

So, y(n) = y _{h} (n) 
…(10) 
Let y _{h} (n) = λ ^{n} 
…(11) 
Substituting (11) in (9) we get,
λ ^{n}  (1/6) λ ^{n}^{}^{1} – (1/6) λ ^{n}^{}^{2} = 0 ( x(n) = 0 for homogeneous solution)
or
λ ^{2}  (1/6) λ – (1/6) = 0
…(12)
8
The roots of the characteristic equation are,
λ _{1} = 1/2, λ _{2} = 1/3
The solution y _{h} (n) = C _{1} (1/2) ^{n} + C _{2} (1/3) ^{n} 
…(13) 

_{F}_{o}_{r} _{i}_{m}_{p}_{u}_{l}_{s}_{e} x(n) = δ(n); x(n) = 0 for n > 0 and x(0) = 1 

Substituting the above relations in eqn (9) we have, 

For n = 0, 

y(0) – (1/6) y(1) –(1/6) y(2) = x(0) = 1 

i.e. 
y(0) = 1. 
…(14) 
For n = 1, 

y(1) – (1/6) y(0) –(1/6) y(1) = x(1) y(1) – (1/6) = 0 y(1) = 1/6. 
…(15) 

From eqn (13) 

y(0) = C _{1} + C _{2} 
…(16) 

y(1) = (1/2)C _{1} – (1/3)C _{2} 
…(17) 

Comparing equations (14), (15), (16) and (17) we get, 

C _{1} + C _{2} = 1 (1/2)C _{1} – (1/3)C _{2} = (1/6) 

Solving for C _{1} and C _{2} we get, 

C _{1} = 3/5, C _{2} = 2/5 

Therefore, the solution 

y(n) = (3/5)(1/2) ^{n} + (2/5)(1/3) ^{n} 
…(18) 

Now, let’s find out impulse response. We know that, 

y(n) = x(n) * h(n) h(n) = y(n) / x(n) 
…(19) 
9
Compute y(n) for various values of n Substitute n = 0, 1, 2, 3 in eqn (18) we get,
y(0) = 1.0000 y(1) = 0.1667 y(2) = 0.1944 y(3) = 0.0602
So,
We know that, x(n) = 1
y(n) = {1.0000, 0.1667, 0.1944, 0.0602}
So, the impulse response for the given difference equation using eqn (19) is
h(n) = {1.0000, 0.1667, 0.1944, 0.0602}
Program: 

clc; dr = [1,1/6,1/6]; 
% Clear screen 
nr = [1]; 
% Numeartor coefficients % Denominator coefficients 
h = impz(nr,dr,4);
% Computes the impulse response of a given
% difference equation, returns the coefficients
disp('Impulse response h(n):');% Displays impulse response
disp(h); 
% Displays impulse response on command window 
subplot(2,1,1); 
% Divide the figure window to plot the output 
stem(h); 
% Displays the impulse response 
title('Impulse response h(n):');% Title as impulse response
x = [1];
y = conv (h, x);
% Input coefficients
% Convolution of input and impulse coefficients to get the
% output
disp('Output y(n):') disp(y); 
% Displays Output y(n) % Displays the output on command window 
subplot(2,1,2); 
% Divide the figure window to plot the output 
stem(y); 
% Plots the output 
title('Output y(n) for given x(n)'); % Title as “Output y(n) for given x(n)”
Output:
Impulse response:
1.0000
0.1667
0.1944
0.0602
Output y(n):
1.0000
0.1667
0.1944
0.0602
10
Graph:
11
EXPERIMENT NO3
AIM: TO IMPLEMENT LINEAR CONVOLUTION OF TWO GIVEN SEQUENCES
Theory: Convolution is an integral concatenation of two signals. It has many applications in numerous areas of signal processing. The most popular application is the determination of the output signal of a linear timeinvariant system by convolving the input signal with the impulse response of the system. Note that convolving two signals is equivalent to multiplying the Fourier Transform of the two signals.
Mathematic Formula:
The linear convolution of two continuous time signals x(t) and h(t) is defined by
For discrete time signals x(n) and h(n), is defined by
Where x(n) is the input signal and h(n) is the impulse response of the system.
In linear convolution length of output sequence is,
length(y(n)) = length(x(n)) + length(h(n)) – 1
Graphical Interpretation:
• Reflection of h(k) resulting in h(k)
• Shifting of h(k) resulting in h(nk)
• Element wise multiplication of the sequences x(k) and h(nk)
• Summation of the product sequence x(k) h(nk) resulting in the convolution value for _{y}_{(}_{n}_{)}
Example:
x(n) = {1, 2, 3, 1} h(n) = {1, 1, 1}
length(y(n)) = length(x(n)) + length(y(n)) – 1 = 4 + 3 – 1 = 6
12
x(k) 
h(k) 

3 

1 
2 
1 
1 
1 
1 

4 
3 
2 
1 
0 
1 
2 
3 
4 
5 
6 
7 
0 1 
2 

∞ 

n=0; h(k ) 
y(0) = ∑ x(k) h(k) = 1 

1 
k=∞ 

4 
3 
2 
1 
0 
1 
2 
3 
4 
5 
6 
7 

∞ 

n=1; h(1k) 
y(1) = ∑ x(k) h(1k) = 1+2=3 

1 
k= ∞ 

4 
3 
2 
1 
0 
1 
2 
3 
4 
5 
6 
7 

∞ 

n=2; h(2k) 
y(2) =∑ x(k) h(2k) = 1+2+3=6 

1 
k=∞ 

4 
3 
2 
1 
0 
1 
2 
3 
4 
5 
6 
7 

∞ 

n=3; h(3k) 
y(3) =∑ x(k) h(3k) = 2+3+1=6 

1 
k=∞ 

4 
3 
2 
1 
0 
1 
2 
3 
4 
5 
6 
7 

∞ 

n=4; h(4k) 
y(4) = ∑ x(k) h(4k) = 3+1=4 

1 
k=∞ 

4 
3 
2 
1 
0 
1 
2 
3 
4 
5 
6 
7 

∞ 

n=5; h(5k) 
y(5) = ∑ x(k) h(5k) = 1 

1 
k=∞ 

4 
3 
2 
1 
0 
1 
2 
3 
4 
5 
6 
7 
13
6 
6 

4 

3 

y(n) = {1, 3, 6, 6, 4, 1} 

1 
1 

4 
3 
2 
1 
0 
1 
2 
3 
4 
5 
6 
7 
Program:
clc; x1 = input('Enter the 1st seq:');
x2 = input('Enter the 2nd seq:');
y = conv(x1, x2);
disp('The linear convolution of two sequences:'); % Displays the result
disp(y);
n = 0:length(y)1;
stem(n, y); xlabel('Time'); ylabel('Magnitude'); title('Linear convolution');
% Clear screen % Get the first sequence % Get the second sequence % Convolve two signals
% Displays the result on command window % Defines the length for xaxis % Plots the output % Name the xaxis as Time % Name the yaxis as Magnitude % Title as “Linear convolution”
Output:
Enter the 1st seq:[1 2 3 1] Enter the 2nd seq:[1 1 1] The linear convolution of two sequences:
1
3
6
6
4
1
14
Graph:
15
EXPERIMENT NO4
AIM: TO IMPLEMENT CIRCULAR CONVOLUTION OF TWO GIVEN SEQUENCES
Circular convolution:
Let x _{1} (n) and x _{2} (n) are finite duration sequences both of length N with DFT’s X _{1} (k) and X _{2} (k). Convolution of two given sequences x _{1} (n) and x _{2} (n) is given by the equation,
x _{3} (n) = IDFT[X _{3} (k)]
X _{3} (k) = X _{1} (k) X _{2} (k)
N1
x _{3} (n) = ∑ x _{1} (m) x _{2} ((nm)) _{N}
m=0
Example:
Let’s take x _{1} (n) = {1, 1, 2, 1} and x _{2} (n) = {1, 2, 3, 4}
Arrange x _{1} (n) and x _{2} (n) in circular fashion as shown below.
x _{1} (2)
2
x _{1} (m)
1
x _{1} (3)
1
x _{1} (0)
1
16
x _{2} (2)
3
x _{2} (m)
2
x _{2} (1)
x _{2} (3)
4
x _{2} (0)
1
To get x _{2} (m), rotate x _{2} (m) by 4 samples in clockwise direction.
x
_{2} (m)
4
x _{2} (3)
x _{2} (1)
2
x _{3} (0) = x _{1} (m) x _{2} (m)
= x _{1} (0) x _{2} (0) + x _{1} (1) x _{2} (3) + x _{1} (2) x _{2} (2) + x _{1} (3) x _{2} (1)
= 1 + 4 + 6 +2 x _{3} (0) = 13
Keep x _{1} (m) constant and rotate x _{2} (m) once to compute further values.
To get x _{3} (1) rotate x _{2} (m) by one sample in anticlockwise direction
x _{2} (2)
3
x _{3} (1) = x _{1} (m) x _{2} (1m)
= x _{1} (0) x _{2} (1) + x _{1} (1) x _{2} (0) + x _{1} (2) x _{2} (3) + x _{1} (3) x _{2} (2)
= 2 + 1 + 8 + 3 x _{3} (1) = 14
17
To get x _{3} (2) rotate x _{2} (1m) by one sample in anticlockwise direction
x _{2} (3)
4
3
x _{2} (2)
x _{3} (2) = x _{1} (m) x _{2} (2m)
= x _{1} (0) x _{2} (2) + x _{1} (1) x _{2} (1) + x _{1} (2) x _{2} (0) + x _{1} (3) x _{2} (3)
= 3 + 2 + 2+ 4 x _{3} (2) = 11
To get x _{3} (3) rotate x _{2} (2m) by one sample in anticlockwise direction
x _{2} (0)
1
4
x _{2} (3)
x _{3} (3) = x _{1} (m) x _{2} (3m)
= x _{1} (0) x _{2} (3) + x _{1} (1) x _{2} (2) + x _{1} (2) x _{2} (1) + x _{1} (3) x _{2} (0)
= 4 + 3 + 4 + 1 x _{3} (3) = 12
The convoluted signal is,
x _{3} (n) = {13, 14, 11, 12}
18
Program:
clc; x1 = input('Enter the first sequence:');
x2 = input('Enter the second sequence:'); N1 = length(x1); N2 = length(x2);
N = max(N1,N2);
N3 = N1N2;
% Get equal length sequence
if(N3>0)
x1 = [x1,zeros(1, N3)]; else
x2 = [x2,zeros(1, N3)]; end
% Computation of circular convolution
for m=1:N y(m) = 0; for n=1:N
i=mn+1;
if(i<=0)
% Clear screen % Get the first sequence % Get the second sequence % Returns the length of first sequence % Returns the length of second sequence % Get the Maximum length out of two signals
% Pad zeros to the first sequence if N2>N1
% Pad zeros to the second sequence is N1>N2
i=N+i; end y(m) = y(m)+x1(n)*h(i); end
end
disp('The circular convolution of two given sequences is:');
disp(y); 
% Displays the result on command window 
n=0:N1; 
% Get the length for xaxis 
stem(n, y); xlabel('Time'); ylabel('Magnitude'); title('Circular convolution'); 
% Plot the result % Name the xaxis as “Time” % Name the yaxis as “Magnitude” % Title as Circular convolution 
Output:
Enter the first sequence: [1 1 2 1] Enter the second sequence: [1 2 3 4]
The circular convolution of two given sequences is:
13
14
11
12
19
Graph:
20
EXPERIMENT NO5
AIM: AUTOCORRELATION OF A GIVEN SEQUENCE AND VERIFICATION OF ITS PROPERTIES
Correlation: Correlation determines the degree of similarity between two signals. If the signals are identical, then the correlation coefficient is 1; if they are totally different, the correlation coefficient is 0, and if they are identical except that the phase is shifted by exactly 180 ^{0} (i.e. mirrored), then the correlation coefficient is 1.
Autocorrelation: The Autocorrelation of a sequence is correlation of a sequence with itself. The autocorrelation of a sequence x(n) is defined by,
∞
R _{x}_{x} (k) = ∑ x(n) x(nk)
n=∞
Where k is the shift parameter.
Or equivalently
∞
R _{x}_{x} (k) = ∑ x(n+k) x(n)
n=∞
k = 0, ±1, ±2, ±3 …
k = 0, ±1, ±2, ±3 …
Example:
Let’s take a sequence x(n) = {1, 2, 3, 4}
x(n) 
4 

3 

1 
2 

4 
3 
2 
1 
0 
1 
2 
3 
4 
5 
6 
7 

4 

3 

∞ 

k=0; x(n) 
R _{x}_{x} (0) = ∑ x(n) x(n) = 4 

1 
2 

n=∞ 

4 
3 
2 
1 
0 
1 
2 
3 
4 
5 
6 
7 
21
4 

3 
∞ 

R _{x}_{x} (1) = ∑ x(n) x(n+1) = 8+3=11 

k=1; x(n+1) 
2 

1 
n= ∞ 

4 
3 
2 
1 
0 
1 
2 
3 
4 
5 
6 
7 

4 

3 
∞ 

R _{x}_{x} (2) =∑ x(n) x(n+2) = 12+6+2=20 

k=2; x(n+2) 
2 

1 
n=∞ 

4 
3 
2 
1 
0 
1 
2 
3 
4 
5 
6 
7 

4 

3 
∞ 

R _{x}_{x} (3) =∑ x(n) x(n+3) = 16+9+4+1=30 

k=3; x(n+3) 
2 

1 
n=∞ 

4 
3 
2 
1 
0 
1 
2 
3 
4 
5 
6 
7 

4 

3 
∞ 

k=4; x(n+4) 2 
R _{x}_{x} (4) = ∑ x(n) x(n+4) = 12+6+2=20 

1 
n=∞ 

4 
3 
2 
1 
0 
1 
2 
3 
4 
5 
6 
7 
∞ 

k=5; x(n+5) 
4 
R _{x}_{x} (5) = ∑ x(n) x(n+5) = 8+3=11 

3 
n=∞ 

2 

1 

4 
3 
2 
1 
0 
1 
2 
3 
4 
5 
6 
7 
∞ 

k=6; x(n+6) 4 
R _{x}_{x} (6) = ∑ x(n) x(n+6) = 4 

3 
n=∞ 

2 

1 

4 
3 
2 
1 
0 
1 
2 
3 
4 
5 
6 
7 
22
30 

20 
20 

11 
11 
R _{x}_{x} (k) = {4, 11, 20, 30, 20, 11, 4} 

4 
4 

4 
3 
2 
1 
0 
1 
2 
3 
4 
5 
6 
7 
Program:
clc; x = input('Enter the input sequence:'); Rxx = xcorr(x); disp('Auto correlated sequence, Rxx:'); disp(Rxx); t = 0:length(Rxx)1; stem(t,Rxx); xlabel('Time'); ylabel('Magnitude');
title('Autocorrelation of the given sequence:'); % Title
% Clear screen % Get the input sequence % Returns autocorrelated sequence % Display the result % Display the result on command window % Length to plot the graph % plots the result on figure window % xlabel % ylabel
Output:
Enter the input sequence: [1 2 3 4] Auto correlated sequence, Rxx:
4.0000
11.0000
20.0000
30.0000
20.0000
11.0000
4.0000
23
Graph:
Properties of Autocorrelation:
_{1}_{.} Periodicity: R _{x}_{x} (k _{0} ) = R _{x}_{x} (0) then R _{x}_{x} (k) is periodic with period k _{0}
2. Autocorrelation function is symmetric. i.e. R _{x}_{x} (m) = R _{x}_{x} (m)
3. Mean square value: autocorrelation function at _{k}_{=}_{0}_{,} is equal to mean square value of the process. R _{x}_{x} (0) = E{x(n) ^{2} }≥0
24
EXPERIMENT NO6
AIM: CROSSCORRELATION OF A GIVEN SEQUENCE AND VERIFICATION OF ITS PROPERTIES
Correlation: Correlation determines the degree of similarity between two signals. If the signals are identical, then the correlation coefficient is 1; if they are totally different, the correlation coefficient is 0, and if they are identical except that the phase is shifted by exactly 180 ^{0} (i.e. mirrored), then the correlation coefficient is 1.
Crosscorrelation: When two independent signals are compared, the procedure is known as crosscorrelation. It is given by,
∞
R _{x}_{y} (k) = ∑ x(n) y(nk)
n=∞
Where k is the shift parameter.
Or equivalently
∞
R _{y}_{x} (k) = ∑ y(n+k) x(n)
n=∞
k = 0, ±1, ±2, ±3 …
Comparing above two equations, we find that,
R _{x}_{y} (k) = R _{y}_{x} (k)
Where R _{y}_{x} (k) is the folded version of R _{x}_{y} (k) about k = 0.
So, we can write Cross correlation of the two sequences is given by,
∞
R _{x}_{y} (k) = ∑ x(n) y[(kn)]
n=∞
R _{x}_{y} (k) = x(k) * y(k)
… (1)
Equation (1) shows that cross correlation is the essentially the convolution of two sequences in which one of the sequences has been reversed.
25
Example:
Let’s take x(n) = {1, 1, 1, 1} and y(n) = {1, 2, 3, 4} x(n)
1 
1 
1 
1 

4 
3 
2 
1 
0 
1 
2 
3 
4 
5 
6 
7 

4 

3 

∞ 

k=0; y(n) 
R _{x}_{y} (0) = ∑ x(n) y(n) = 4 

2 
1 

n=∞ 

4 
3 
2 
1 
0 
1 
2 
3 
4 
5 
6 
7 

4 

3 
∞ 

R _{x}_{y} (1) = ∑ x(n) y(1n) = 4+3=7 

k=1; y(1n) 
2 

1 
n= ∞ 

4 
3 
2 
1 
0 
1 
2 
3 
4 
5 
6 
7 

4 

3 
∞ 

R _{x}_{y} (2) =∑ x(n) y(2n) = 4+3+2=9 

k=2; y(2n) 
2 

1 
n=∞ 

4 
3 
2 
1 
0 
1 
2 
3 
4 
5 
6 
7 

4 

3 
∞ 

R _{x}_{y} (3) =∑ x(n) y(3n) = 4+3+2+1=10 

k=3; y(3n) 
2 

1 
n=∞ 

4 
3 
2 
1 
0 
1 
2 
3 
4 
5 
6 
7 

k=4; y(4n) 

4 

3 
∞ 

2 
R _{x}_{y} (4) = ∑ x(n) y(4n) = 3+2+1=6 

1 
n=∞ 

4 
3 
2 
1 
0 
1 
2 
3 
4 
5 
6 
7 
26
k=5; y(5n)
∞
27
Program: 

clc; 
% Clear screen 
x = input('Enter the first sequence:'); 
% Get the first sequence 
y = input('Enter the second sequence:'); 
% Get the second sequence 
Rxy = xcorr(x,y); disp('Cross correlated sequence, Rxy:'); disp(Rxy); t = 0:length(Rxy)1; 
% Returns cross correlated sequence % Display the result % Display the result on command window % Length to plot the graph 
stem(t, Rxy); xlabel('Time'); ylabel('Magnitude'); 
% plots the result on figure window % xlabel % ylabel 
title('Cross correlation of the given two sequences:'); % Title
Output:
Enter the first sequence: [1 1 1 1]
Enter the second sequence: [1 2 3 4] Cross correlated sequence, Rxy:
4.0000
Graph:
7.0000
9.0000
10.0000
6.0000
3.0000
1.0000
28
Properties of cross correlation:
1. R _{x}_{y} (k) is always a real valued function which may be a positive or negative.
_{2}_{.}
R _{x}_{y} (k) = R _{y}_{x} (k)
3. R _{x}_{y} (k) ^{2} ≤ R _{x}_{x} (0) R _{y}_{y} (0)
4. R _{x}_{y} (k) ≤[1/2] [R _{x}_{y} (k) + R _{x}_{y} (k)]
5. When R _{x}_{y} (k) = 0, x(n) and y(n) are said to be uncorrelated or they said to be statistically independent.
6. R _{x}_{y} (k) may not be necessarily have a maximum at k=0 nor R _{x}_{y} (k) an even function.
29
EXPERIMENT NO7
AIM: TO SOLVE A GIVEN DIFFERENCE EQUATION
A General N ^{t}^{h} order Difference equations looks like,
y[n] + a _{1} y[n1] + a _{2} y[n2] + …+ a _{N} y[nN) = b _{0} x[n] + b _{1} x[n1] + …. + b _{M} x[nM]
Here y[n] is “Most advanced” output sample and y[nm] is “Least advanced” ouput sample. The difference between these two index values is the order of the difference equation.
Here we have: n(nN) = N
We can rewrite the above equation as,
y[n] + ∑a _{i} y[ni] = ∑b _{i} x[ni]
y[n] becomes,
y[n] = ∑a _{i} y[ni] + ∑b _{i} x[ni]
Example:
y[n+2] – 1.5y[n+1] + y[n] = 2x[n]
In general we start with the “Most advanced” output sample. Here it is y[n+2].
So, here we need to subtract 2 from each sample argument. We get
y[n] – 1.5y[n1] + y[n2] = 2x[n2]
y[n] = 1.5y[n1]  y[n2] + 2x[n2]
Lets assume our input x[n] = u[n] =
_{0}
In our example we have taken _{x}_{[}_{n}_{]} _{=} _{u}_{[}_{n}_{]} =
_{x}_{<}_{0}
1 0≤x<10
We need N past values to solve N ^{t}^{h} order difference equation.
y[2] = 1 y[1] = 2
30
Compute y[n] for various values of n
y[0] = 1.5y[1]  y[2] + 2x[2] = 1.5*2 – 1 + 2*0 y[0] = 2
y[1] = 1.5y[0]  y[1] + 2x[1]
= 1.5*2  2 + 2*0 y[1] = 1
y[2] = 1.5y[1]  y[0] + 2x[0]
= 1.5*1 – 2 + 2*1 y[2] = 1.5
And so on…
Program:
clc; x = [0 0 ones(1, 10)]; y_past = [1 2]; y(1) = y_past(1); y(2) = y_past(2);
% Clear screen % Input x[n] = u[n] % Past values to solve difference equation % y[1] <= y[2] % y[2] <= y[1]
for k = 3:(length(x)+2)
% Compute y[n] for various values of n
y(k) = 1.5*y(k1)  y(k2) + 2*x(k2);
end
% End of for loop
disp(‘Solution for the given difference equation:’);
disp(y); 
% Display the result on command window 
subplot(1,1,1); 
% Divide the window to plot the result 
stem (2:(length(y)3),y); xlabel(‘Input x[n]’); ylabel(‘Output y[n]’); title(‘Difference equation’); 
% Plot the result % Name xaxis as Input x[n] % Name yaxis as Output y[n] % Title as “Difference equation” 
Output:
Solution for the given difference equation:
Columns 1 through 7
1.0000
2.0000
2.0000
1.0000
Columns 8 through 14
6.8125
6.8438
5.4531
3.3359
1.5000
1.5508
31
3.2500
0.9902
5.3750
1.9346
Graph:
32
EXPERIMENT NO8
AIM: TO COMPUTE NPOINT DFT OF A GIVEN SEQUENCE AND TO PLOT MAGNITUDE AND PHASE SPECTRUM.
Discrete Fourier Transform: The Discrete Fourier Transform is a powerful computation tool which allows us to evaluate the Fourier Transform _{X}_{(}_{e} ^{j}^{ω} _{)} on a digital computer or specially designed digital hardware. Since X(e ^{j}^{ω} ) is continuous and periodic, the DFT is obtained by sampling one period of the Fourier Transform at a finite number of frequency points. Apart from determining the frequency content of a signal, DFT is used to perform linear filtering operations in the frequency domain.
The sequence of N complex numbers x _{0} ,
complex numbers X _{0} ,
,
x _{N}_{−}_{1} is transformed into the sequence of N
, X _{N}_{−}_{1} by the DFT according to the formula:
N1
X(k) = ∑x(n)e ^{}^{j}^{2}^{π}^{n}^{k}^{/}^{N}
n=0
k = 0,1, …. N1
Example:
Lets assume the input sequence x[n] = [1 1 0 0]
We have,
N1
X(k) = ∑x(n)e ^{}^{j}^{2}^{π}^{n}^{k}^{/}^{N}
n=0
For k = 0,
3
k = 0,1, …. N1
X(0) = ∑x(n) = x(0) + x(1) + x(2) + x(3)
n=0
X(0) = 1+1+0+0 = 2
For k = 1,
3
X(1) = ∑x(n)e ^{}^{j}^{π}^{n}^{/}^{2} = x(0) + x(1) e ^{}^{j}^{π}^{/}^{2} + x(2) e ^{}^{j}^{π} + x(3) e ^{}^{j}^{3}^{π}^{/}^{2}
n=0
X(1)
= 1 + cos(π/2)  jsin(π/2) = 1 – j
33
For k = 2,
3
X(2) = ∑x(n)e ^{}^{j}^{π}^{n} = x(0) + x(1) e ^{}^{j}^{π} + x(2) e ^{}^{j}^{2}^{π} + x(3) e ^{}^{j}^{3}^{π}
n=0
= 1 + cos π – jsin π X(2) = 11 = 0
For k = 3,
3
X(3) = ∑x(n)e ^{}^{j}^{3}^{n}^{π}^{/}^{2} = x(0) + x(1) e ^{}^{j}^{3}^{π}^{/}^{2} + x(2) e ^{}^{j}^{3}^{π} + x(3) e ^{}^{j}^{9}^{π}^{/}^{2}
n=0
X(3)
= 1 + cos(3π/2)  jsin(3π/2) = 1 + j
The DFT of the given sequence is,
X(k) = { 2, 1j, 0, 1+j }
To find Magnitude of X(k):
Magnitude= (a ^{2} +b ^{2} ) ^{1}^{/}^{2} Where a and b are real and imaginary parts respectively To fine Phase of X(k):
Phase=tan ^{}^{1} (b/a)
Program: 

clc; 
% Clear screen % Get the value of N 

x1 = input('Enter the sequence:'); n = input('Enter the length:'); 
% Get the input sequence 

m disp('Npoint DFT of a given sequence:'); disp(m); = abs(fft(x1,n)); 
% Computes the DFT using FFT algorithm % Display the results % Displays the result on command window 

N 
= 0:1:n1; 
% Decides the length to plot the results 
subplot(2,2,1);
stem(N,m); xlabel('Length'); ylabel('Magnitude of X(k)'); title('Magnitude spectrum:'); an = angle(fft(x1,n)); disp(an);
% Divide the figure window to plot the
% results
% Plots the magnitude spectrum % Name xaxis as “Length” % Name yaxis as “Magnitude of X(k)” % Title as “Magnitude spectrum” % Get the angle of the output sequence X(k)
subplot(2,2,2); 
% Divide the figure window to plot the 

% 
results 

stem(N, an); 
% Plots the phase spectrum 
34
xlabel('Length'); ylabel('Phase of X(k)'); title('Phase spectrum:');
Output:
Enter the sequence:[1 1 0 0] Enter the length:4 Magnitude of X(k) 2.0000 1.4142
0
1.4142
Phase of X(k)
0
0.7854
0
0.7854
Graph:
Magnitude spectrum:
Length
% Name xaxis as “Length” % Name yaxis as “Phase of X(k)” % Title as “Phase spectrum”
1
0.5
0
0.5
1
Phase spectrum:
Length
35
EXPERIMENT NO9
AIM: LINEAR CONVOLUTION OF TWO GIVEN SEQUENCES USING DFT AND IDFT
Theory: Convolution is an integral concatenation of two signals. It has many applications in numerous areas of signal processing. The most popular application is the determination of the output signal of a linear timeinvariant system by convolving the input signal with the impulse response of the system. Note that convolving two signals is equivalent to multiplying the Fourier Transform of the two signals.
Mathematic Formula:
The linear convolution of two continuous time signals x(t) and h(t) is defined by
For discrete time signals x(n) and h(n), is defined by
Where x(n) is the input signal and h(n) is the impulse response of the system.
Example:
x _{1} (n) = {1, 1, 2} x _{2} (n) = {1, 2}
For linear convolution,
Length N = Length(x _{1} ) + Length(x _{2} )  1 N = 3 + 2 – 1 = 4
Convolution of two sequences _{x} _{1} _{(}_{n}_{)} and _{x} _{2} _{(}_{n}_{)} is,
x _{3} (n) = IDFT[X _{3} (k)] x _{3} (n) = IDFT[X _{1} (k) X _{2} (k)]
Where,
X _{1} (k) = DFT [x _{1} (n)]
X _{2} (k) = DFT [x _{2} (n)]
36
N1
X _{1} (k) = ∑
n=0
x _{1} (n)e ^{}^{j}^{2}^{π}^{k}^{n}^{/}^{N}
k= 0, 1, 2, … , N1
Given x _{1} (n) = {1, 1, 2} and N=4
3
X _{1} (0) = ∑ x _{1} (n) = 1 + 1 + 2 = 4
n=0
5
X _{1} (1) = ∑ x _{1} (n)e ^{}^{j}^{π}^{n}^{/}^{2} = 1 – j – 2 = 1  j
n=0
5
X _{1} (2) = ∑ x _{1} (n)e ^{}^{j}^{π}^{n} = 1 – 1 + 2 = 2
n=0
5
X _{1} (3) = ∑ x _{1} (n)e ^{}^{j}^{3}^{π}^{n}^{/}^{2} = 1 + j – 2 = 1 + j
n=0
X _{1} (k) = {4, 1j, 2, 1+j}
Now,
N1
X _{2} (k) = ∑ x _{2} (n)e ^{}^{j}^{2}^{π}^{k}^{n}^{/}^{N}
n=0
k= 0, 1, 2, … , N1
Given x _{2} (n) = {1, 2} and N=4
3
X _{2} (0) = ∑
n=0
x _{2} (n) = 1 + 2 = 3
37
3
X _{2} (1) = ∑ x _{2} (n) e ^{}^{j}^{π}^{n}^{/}^{2} = 1 + 2(j) = 1  j2
n=0
3
X _{2} (2) = ∑ x _{2} (n) e ^{}^{j}^{π}^{n} = 1 + 2(1) = 1
n=0
3
X _{2} (3) = ∑ x _{2} (n) e ^{}^{j}^{3}^{π}^{n}^{/}^{2} = 1 + 2(j) = 1 + j2
n=0
X _{2} (k) = {3, 1j2, 1, 1+j2}
We know that,
X _{3} (k) = X _{1} (k) X _{2} (k) X _{3} (k) = {12, 3+j, 2, 3j}
Convolution of two given sequences is,
x _{3} (n) = IDFT[X _{3} (k)]
N1
x _{3} (n) = (1/N) ∑ X _{3} (k)e ^{j}^{2}^{π}^{k}^{n}^{/}^{N}
k=0
3
n = 0, 1, 2, …. , N1
x _{3} (0) = (1/4) ∑ X _{3} (k) = (1/4) [12 – 3 +j 2 3 –j] = 1
k=0
3
x _{3} (1) = (1/4) ∑ X _{3} (k)e ^{j}^{π}^{k}^{/}^{2}
k=0
x _{3} (1) = (1/4) [12 + (3 + j) j + (2) (1) + (3  j) (j)] = 3
3
x _{3} (2) = (1/4) ∑ X _{3} (k)e ^{j}^{π}^{k}
k=0
x _{3} (2) = (1/4) [12 + (3 + j) (1) + (2) (1) + (3  j) (1)] = 4
38
3
x _{3} (3) = (1/4) ∑ X _{3} (k)e ^{j}^{3}^{π}^{k}^{/}^{2}
k=0
x _{3} (3) = (1/4) [12 + (3 + j) (j) + (2) (1) + (3  j) (j)] = 4
Convoluted sequence of two given sequences is,
x _{3} (n) = {1, 3, 4, 4}
Program:
clc; x1 = input('Enter the 1st seq:'); x2 = input('Enter the 2nd seq:');
n = length(x1) + length(x2)1; x1 = fft(x1,n); x2 = fft(x2,n);
y = x1.*x2;
yc = ifft(y,n);
disp('Linear convolution using DFT and IDFT:'); % Display Linear convolution
% Clear screen % Get the first sequence % Get the second sequence % Get the length of the sequence % Compute the DFT of x1 using FFT algorithm % Compute the DFT of x2 using FFT algorithm % Multiply two DFT’s % Compute IDFT using IFFT algorithm
disp(yc); N = 0:1:n1; 
% Displays the result on command window % Defines the length of xaxis to plot the result 
subplot(1,1,1); 
% Divide the window to plot the result 
stem(N,yc); 
% Plots the result 
xlabel('Time'); 
% Name the xaxis as Time 
ylabel('Magnitude'); 
% Name the yaxis as Magnitude 
title('Linear convolution using DFT and IDFT:'); % Title
Output:
Enter the 1st seq: [1 1 2] Enter the 2nd seq: [1 2] Linear convolution using DFT and IDFT:
1
3
4
4
39
Graph:
40
EXPERIMENT NO10
AIM: TO IMPLEMENT CIRCULAR CONVOLUTION OF TWO GIVEN SEQUENCES USING DFT AND IDFT
Circular convolution:
Let x _{1} (n) and x _{2} (n) are finite duration sequences both of length N with DFT’s X _{1} (k) and X _{2} (k). Convolution of two given sequences x _{1} (n) and x _{2} (n) is given by,
x _{3} (n) = IDFT[X _{3} (k)] x _{3} (n) = IDFT[X _{1} (k) X _{2} (k)]
Where,
X _{1} (k) = DFT [x _{1} (n)] X _{2} (k) = DFT [x _{2} (n)]
Example:
x _{1} (n) = {1, 1, 2, 1} x _{2} (n) = {1, 2, 3, 4}
N1
X _{1} (k) = ∑ x _{1} (n)e ^{}^{j}^{2}^{π}^{k}^{n}^{/}^{N}
n=0
k= 0, 1, 2, … , N1
Mult mai mult decât documente.
Descoperiți tot ce are Scribd de oferit, inclusiv cărți și cărți audio de la editori majori.
Anulați oricând.