DSP Lab Manual 5 Semester Electronics and Communication Engineering
DSP Lab Manual 5 Semester Electronics and Communication Engineering
DSP Lab Manual 5 Semester Electronics and Communication Engineering
For
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.
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. fs > fN
Program:
% Nyquist Rate Sampling.
clc; % Clear screen
fs = 1400; % 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)); % Determine the absolute FFT of the input signal
disp(‘xm’); % Displays xm on command window
disp (xm); % Displays values of xm on command window
k = 0:length(xm)-1; % Number of samples to be plot on x-axis
subplot (2,2,1); % Divide the figure window to plot the output
stem (100*k, xm); % Plot the output
xlabel ('Hz'); % Name x-axis as “Hz”
ylabel ('Magnitude'); % Name y-axis as “Magnitude”
title ('NR sampling'); % Title is “NR Sampling”
%UNDER Sampling.
fs = 1000; % 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
xm = 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; % Number of samples to be plot on x-axis
subplot(2,2,2); % Divide the figure window to plot the output
stem(100*k, xm1); % Plot the output
xlabel('Hz'); % Name x-axis as “Hz”
ylabel('Magnitude'); % Name y-axis as “Magnitude”
title('UNDER sampling'); % Title is “UNDER Sampling”
%OVER Sampling.
fs = 2000; % Sampling frequency, fs = 2000Hz
t = 0:1/fs:20/fs; % Number of samples
x = cos(2*pi*400*t)+cos(2*pi*700*t); % Input signal
xm = 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; % Number of samples to be plot on x-axis
subplot(2,2,3); % Divide the figure window to plot the output
stem(100*k,xm2); % Plot the output
xlabel('Hz'); % Name x-axis as “Hz”
ylabel('Magnitude'); % Name y-axis as “Magnitude”
title('OVER sampling'); % Title is “OVER Sampling”
OUTPUT :
xm
Columns 1 through 7
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
N R s a m p lin g U N D E R s a m p lin g
15 6
10 4
M agnitude
M agnitude
5 2
0 0
0 500 1000 1500 0 500 1000
Hz Hz
O V E R s a m p lin g
15
10
M agnitude
0
0 500 1000 1500 2000
Hz
EXPERIMENT NO-2
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) δ(n-k)] …(1)
k=-∞
For linear system (1) reduces to
∞
y(n) = ∑x(k) T[δ(n-k)] …(2)
k=-∞
The response to the shifted impulse sequence can be denoted by h(n, k) is denoted by,
M M
y(n) = ∑ak y(n-k) + ∑bk x(n-k) …(7)
k=1 k=0
For input x(n) = δ(n)
M
y(n) = ∑bk x(n-k) = 0 for n > M
k=0
Now (7) can be written as,
N
y(n) = ∑ak y(n-k) = 0 a0 = 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
yp(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
For n = 0,
For n = 1,
y(0) = 1.0000
y(1) = 0.1667
y(2) = 0.1944
y(3) = 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; % Clear screen
nr = [1]; % Numeartor co-efficients
dr = [1,-1/6,-1/6]; % Denominator co-efficients
h = impz(nr,dr,4); % Computes the impulse response of a given
% difference equation, returns the co-efficients
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]; % Input co-efficients
y = conv (h, x); % Convolution of input and impulse co-efficients to get the
% output
disp('Output y(n):') % Displays Output y(n)
disp(y); % 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
Im p u l s e r e s p o n s e
1
0 .5
0
1 1 .5 2 2 .5 3 3 .5 4
O u t p u t y ( n ) fo r g i v e n x ( n )
1
0 .5
0
1 1 .5 2 2 .5 3 3 .5 4
EXPERIMENT NO-3
Mathematic Formula:
The linear convolution of two continuous time signals x(t) and h(t) is defined by
Where x(n) is the input signal and h(n) is the impulse response of the system.
Graphical Interpretation:
Example:
x(n) = {1, 2, 3, 1}
h(n) = {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(1-k) y(1) = ∑ x(k) h(1-k) = 1+2=3
1 k=- ∞
-4 -3 -2 -1 0 1 2 3 4 5 6 7
∞
n=2; h(2-k) y(2) =∑ x(k) h(2-k) = 1+2+3=6
1 k=-∞
-4 -3 -2 -1 0 1 2 3 4 5 6 7
∞
n=3; h(3-k) y(3) =∑ x(k) h(3-k) = 2+3+1=6
1 k=-∞
-4 -3 -2 -1 0 1 2 3 4 5 6 7
∞
n=4; h(4-k) y(4) = ∑ x(k) h(4-k) = 3+1=4
1 k=-∞
-4 -3 -2 -1 0 1 2 3 4 5 6 7
∞
n=5; h(5-k) y(5) = ∑ x(k) h(5-k) = 1
1 k=-∞
-4 -3 -2 -1 0 1 2 3 4 5 6 7
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:
OUTPUT:
4
Magnitude
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
Time
EXPERIMENT NO-4
Circular convolution:
Let x1(n) and x2(n) are finite duration sequences both of length N with DFT’s X1(k)
and X2(k). Convolution of two given sequences x1(n) and x2(n) is given by the
equation,
x3(n) = IDFT[X3(k)]
N-1
x3(n) = ∑ x1(m) x2((n-m))N
m=0
Example:
x1(m) x2(m)
1 2
x1(1) x2(1)
x1(2) x1(0)
x2(2) x2(0) 2 2 1
3 1
x1(3) x2(3)
1 4
To get x2(-m), rotate x2(m) by 4 samples in clockwise direction.
x2(-m)
4
x2(3)
x2(2) x2(0)
3 1
x2(1)
2
Keep x1(m) constant and rotate x2(-m) once to compute further values.
x2(1-m)
1
x2(0)
x2(3) x2(1)
4 2
x2(2)
3
x2(2-m)
2
x2(1)
1 3
x2(0) x2(2)
x2(3)
4
x2(3-m)
3
x2(2)
2 4
x2(1) x2(3)
x2(0) 1
Program:
clc; % Clear screen
x1 = input('Enter 1st seq:'); % Get the first sequence
x2 = input('Enter 2nd seq:'); % Get the second sequence
n = max(length(x1),length(x2)); % Get the Maximum length out of two signals
x1 = fft(x1,n); % Compute FFT of the first sequence
x2 = fft(x2,n); % Compute FFT of the second sequence
y = x1.*x2; % Multiply the two sequences
yc = ifft(y,n); % Compute IFFT of the result
disp('circular convolution:'); % Displays circular convolution
disp(yc); % Displays the result on command window
N=0:1:n-1; % Get the length for x-axis
subplot(1,1,1); % Divide the window to plot the result
stem(N,yc); % Plot the result
xlabel('Time'); % Name the x-axis as “Time”
ylabel('Magnitude'); % Name the y-axis as “Magnitude”
title('Circular convolution'); % Title as Circular convolution
OUTPUT:
Enter 1st seq:[1 1 2 1]
Enter 2nd seq:[1 2 3 4]
Circular convolution:
13 14 11 12
Circular convolution
15
10
Magnitude
0
0 0.5 1 1.5 2 2.5 3
Time
EXPERIMENT NO-5
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 1800(i.e. mirrored), then the correlation coefficient is -1.
Autocorrelation: When the same signal is compared to phase shifted copies of itself, the
procedure is known as autocorrelation.
The autocorrelation of a random signal describes the general dependence of the values of
the samples at one time on the values of the samples at another time. Consider a random
process x(t) (i.e. continuous time), its autocorrelation function is,
Where T is the period of observation.
Rxx (τ) is always real valued and an even function with a maximum value at τ = 0.
Biased autocorrelation
….. Eqn.1
Unbiased autocorrelation
For m = 1 + 2 + …. + M+1
Where M is the number of lags.
Note that we used the function xcorr to estimate the autocorrelation sequence, it has
double the number of samples as the signal x(n). An important point to remember when
using the function xcorr is that the origin is in the middle of the figure (here it is at lag =
1024). xcorr is a built in function in MATLAB library.
Program:
OUTPUT:
S in e w a ve o f fre q u e n c y 1 H z (F s = 2 0 0 H z )
1
0 .5
Amplitude
-0 .5
-1
0 1 2 3 4 5 6
Tim e , [s ]
A uto c o rre la tio n fu n c tio n o f th e s in e w a ve
1000
Autocorrelation
500
-5 0 0
0 500 1000 1500 2000 2500
lag s
We can also include our own functions to the MATLAB library by saving the file name
with .m extension.
For example we can write the autocorrelation function for the sampled signal defined in
Eqn.1, and we should save this file as autom.m
We can call this function autom in the main program instead of the function xcorr, we
will get the output as,
OUTPUT:
S i n e w a v e o f fr e q u e n c y 1 H z ( F s = 2 0 0 H z )
1
0 .5
A m plitude
-0 .5
-1
0 1 2 3 4 5 6
T im e , [ s ]
A u t o c o r r e l a t i o n fu n c t i o n o f t h e s i n e w a v e
1000
500
A utocorrelation
-5 0 0
0 200 400 600 800 1000 1200
la g s
EXPERIMENT NO-6
AIM: CROSS-CORRELATION 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 1800(i.e. mirrored), then the correlation coefficient is -1.
Cross-correlation: When two independent signals are compared, the procedure is known
as cross-correlation.
The cross correlation function measures the dependence of the value of one signal on
another signal. For two WSS (Wide Sense Stationary) processes x(t) and y(t) it is
described by,
Or
Example:
Plot the cross correlation for the following signal,
x(n) = sin(2πf1t) with f1 = 1 Hz
y(n) = x(n) + w(n)
Program:
OUTPUT:
P u re s in e w a ve
1
A m plitude
0
-1
0 200 400 600 800 1000 1200
T im e
P u re s in e w a ve + N o is e
50
A m plitude
-5 0
0 200 400 600 800 1000 1200
T im e
C ro s s -c o rre la t io n R x y
1000
C ros s -c orrelation
-1 0 0 0
0 500 1000 1500 2000 2500
la g s
EXPERIMENT NO-7
AIM: TO SOLVE A GIVEN DIFFERENCE EQUATION
Here y[n] is “Most advanced” output sample and y[n-m] is “Least advanced” ouput
sample.
The difference between these two index values is the order of the difference equation.
Here we have: n-(n-N) = N
y[n] becomes,
Example:
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
And so on…
Program:
clc; % Clear screen
x = [0 0 ones(1, 10)]; % Input x[n] = u[n]
y_past = [1 2]; % Past values to solve difference equation
y(1) = y_past(1); % y[1] <= y[-2]
y(2) = y_past(2); % y[2] <= y[-1]
OUTPUT:
Columns 8 through 14
6.8125 6.8438 5.4531 3.3359 1.5508 0.9902 1.9346
D iffe r e n c e e q u a t io n
8
6
O utp ut y [n]
0
-2 0 2 4 6 8 1 0 1 2
In p u t x [ n ]
EXPERIMENT NO-8
The sequence of N complex numbers x0,..., xN−1 is transformed into the sequence of N
complex numbers X0, ..., XN−1 by the DFT according to the formula:
N-1
X(k) = ∑x(n)e-j2πnk/N k = 0,1, …. N-1
n=0
Example:
Lets assume the input sequence x[n] = [1 1 0 0]
We have,
N-1
X(k) = ∑x(n)e-j2πnk/N k = 0,1, …. N-1
n=0
For k = 0,
3
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-j3π/2
n=0
= 1 + cos(π/2) - jsin(π/2)
X(1) = 1 – j
For k = 2,
3
X(2) = ∑x(n)e-jπn = x(0) + x(1) e-jπ + x(2) e-j2π + x(3) e-j3π
n=0
= 1 + cos π – jsin π
X(2) = 1-1 = 0
For k = 3,
3
X(3) = ∑x(n)e-j3nπ/2 = x(0) + x(1) e-j3π/2 + x(2) e-j3π + x(3) e-j9π/2
n=0
= 1 + cos(3π/2) - jsin(3π/2)
X(3) = 1 + j
Program:
clc; % Clear screen
x1 = input('Enter the sequence:'); % Get the input sequence
n = input('Enter the length:'); % Get the value of N
m = fft(x1,n); % Computes the DFT using FFT algorithm
disp('N-point DFT of a given sequence:'); % Display the results
disp(m); % Displays the result on command window
N = 0:1:n-1; % Decides the length to plot the results
Column 4
1.0000 + 1.0000i
1.5 0.5
Phase of X(k)
1 0
0.5 -0.5
0 -1
0 1 2 3 0 1 2 3
Length Length
EXPERIMENT NO-9
Mathematic Formula:
The linear convolution of two continuous time signals x(t) and h(t) is defined by
Where x(n) is the input signal and h(n) is the impulse response of the system.
Example:
x1(n) = {1, 1, 2}
x2(n) = {1, 2}
Where,
X1(k) = DFT [x1(n)]
3
X1(0) = ∑ x1(n) = 1 + 1 + 2 = 4
n=0
5
X1(1) = ∑ x1(n)e-jπn/2 = 1 – j – 2 = -1 - j
n=0
5
X1(2) = ∑ x1(n)e-jπn = 1 – 1 + 2 = 2
n=0
5
X1(3) = ∑ x1(n)e-j3πn/2 = 1 + j – 2 = -1 + j
n=0
Now,
N-1
X2(k) = ∑ x2(n)e-j2πkn/N k= 0, 1, 2, … , N-1
n=0
3
X2(0) = ∑ x2(n) = 1 + 2 = 3
n=0
3
X2(1) = ∑ x2(n) e-jπn/2 = 1 + 2(-j) = 1 - j2
n=0
3
X2(2) = ∑ x2(n) e-jπn = 1 + 2(-1) = -1
n=0
3
X2(3) = ∑ x2(n) e-j3πn/2 = 1 + 2(j) = 1 + j2
n=0
We know that,
X3(k) = X1(k) X2(k)
X3(k) = {12, -3+j, -2, -3-j}
N-1
x3(n) = (1/N) ∑ X3(k)ej2πkn/N n = 0, 1, 2, …. , N-1
k=0
3
x3(0) = (1/4) ∑ X3(k) = (1/4) [12 – 3 +j -2 -3 –j] = 1
k=0
3
x3(1) = (1/4) ∑ X3(k)ejπk/2
k=0
x3(1) = (1/4) [12 + (-3 + j) j + (-2) (-1) + (-3 - j) (-j)] = 3
3
x3(2) = (1/4) ∑ X3(k)ejπk
k=0
Program:
clc; % Clear screen
x1 = input('Enter the 1st seq:'); % Get the first sequence
x2 = input('Enter the 2nd seq:'); % Get the second sequence
n = length(x1) + length(x2)-1; % Get the length of the sequence
x1 = fft(x1,n); % Compute the DFT of x1 using FFT algorithm
x2 = fft(x2,n); % Compute the DFT of x2 using FFT algorithm
y = x1.*x2; % Multiply two DFT’s
yc = ifft(y,n); % Compute IDFT using IFFT algorithm
disp('Linear convolution using DFT and IDFT:'); % Display Linear convolution
disp(yc); % Displays the result on command window
N = 0:1:n-1; % Defines the length of x-axis 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 x-axis as Time
ylabel('Magnitude'); % Name the y-axis 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
Linear convolution using DFT and IDFT:
4
3.5
2.5
Magnitude
1.5
0.5
0
0 0.5 1 1.5 2 2.5 3
Time
EXPERIMENT NO-10
Circular convolution:
Let x1(n) and x2(n) are finite duration sequences both of length N with DFT’s X1(k)
and X2(k). Convolution of two given sequences x1(n) and x2(n) is given by,
x3(n) = IDFT[X3(k)]
x3(n) = IDFT[X1(k) X2(k)]
Where,
X1(k) = DFT [x1(n)]
X2(k) = DFT [x2(n)]
Example:
x1(n) = {1, 1, 2, 1}
x2(n) = {1, 2, 3, 4}
N-1
X1(k) = ∑ x1(n)e-j2πkn/N k= 0, 1, 2, … , N-1
n=0
3
X1(0) = ∑ x1(n) = 1 + 1 + 2 + 1 = 5
n=0
3
X1(1) = ∑ x1(n)e-jπn/2 = 1 – j – 2 + j = -1
n=0
3
X1(2) = ∑ x1(n)e-jπn = 1 – 1 + 2 - 1 = 1
n=0
3
X1(3) = ∑ x1(n)e-j3πn/2 = 1 + j - 2 - j = -1
n=0
X1(k) = {5, -1, 1, -1}
Now,
N-1
X2(k) = ∑ x2(n)e-j2πkn/N k= 0, 1, 2, … , N-1
n=0
3
X2(0) = ∑ x2(n) = 1 + 2 + 3 + 4 = 10
n=0
3
X2(1) = ∑ x2(n) e-jπn/2 = 1 + 2(-j) + 3(-1) + 4(j) = -2 + j2
n=0
3
X2(2) = ∑ x2(n) e-jπn = 1 + 2(-1) + 3(1) + 4(-1) = -2
n=0
3
X2(3) = ∑ x2(n) e-j3πn/2 = 1 + 2(j) + 3(-1) + 4(-j) = -2 – j2
n=0
We know that,
X3(k) = X1(k) X2(k)
X3(k) = {50, 2 – j2, -2, 2 + j2}
N-1
x3(n) = (1/N) ∑ X3(k)ej2πkn/N n = 0, 1, 2, …. , N-1
k=0
3
x3(0) = (1/4) ∑ X3(k) = (1/4) [50 + 2 - j2 – 2 + 2 + j2] = 13
k=0
3
x3(1) = (1/4) ∑ X3(k)ejπk/2
k=0
x3(1) = (1/4) [50 + (2 - j2) j + (-2) (-1) + (2 + j2) (-j)] = 14
3
x3(2) = (1/4) ∑ X3(k)ejπk
k=0
3
x3(3) = (1/4) ∑ X3(k)ej3πk/2
k=0
x3(3) = (1/4) [50 + (2 - j2) (-j) + (-2) (-1) + (2 + j2) (j)] = 12
Program:
clc; % Clear screen
x1 = input('Enter 1st sequence:'); % Get the first sequence
x2 = input('Enter 2nd sequence:'); % Get the second sequence
n = max(length(x1), length(x2)); % Get the maximum length of the two sequences
x1 = fft(x1,n); % Compute the DFT of the x1 using FFT algorithm
x2 = fft(x2,n); % Compute the DFT of the x2 using FFT algorithm
y = x1.*x2; % Multiply two DFT’s
yc = ifft(y,n); % Compute the IDFT of mutliplied sequence to get
% the convoluted sequence
disp('Circular convolution using DFT and IDFT:'); % Displays Circular convolution
disp(yc); % Displays the result on command window
N = 0:1:n-1; % Defines the length of x-axis to plot the result
subplot(1,1,1); % Divide the window to plot the result
stem(N,yc); % Plots the results
xlabel('Time'); % Name the x-axis as “Time”
ylabel('Magnitude'); % Name the y-axis as “Magnitude”
title('Circular convolution using DFT and IDFT:'); % Title
OUTPUT:
C ir c u la r c o n v o lu t io n u s in g D F T a n d ID F T :
1 5
1 0
M a g n itu d e
0
0 0 .5 1 1 .5 2 2 .5 3
T im e
EXPERIMENT NO-11
Finite Impulse Response (FIR) Filter: The FIR filters are of non-recursive type,
whereby the present output sample is depending on the present input sample and previous
input samples.
The transfer function of a FIR causal filter is given by,
N-1
H(z) = ∑ h(n)z-n
n=0
In the design of FIR filters most commonly used approach is using windows.
The desired frequency response Hd(ejw) of a filter is periodic in frequency and can be
expanded in Fourier series. The resultant series is given by,
π
hd(n) = (1/2π) ∫ H(ejw)ejwn dw
-π
And known as Fourier coefficients having infinite length. One possible way of obtaining
FIR filter is to truncate the infinite Fourier series at n = ± [(N-1)/2]
Where N is the length of the desired sequence.
The Fourier coefficients of the filter are modified by multiplying the infinite impulse
response with a finite weighing sequence w(n) called a window.
After multiplying w(n) with hd(n), we get a finite duration sequence h(n) that satisfies
the desired magnitude response,
Example:
Here we design a lowpass filter using hamming window.
Hamming window function is given by,
=0 otherwise
WH(ejw ) = 0.54[(sin(wN/2))/(sin(w/2))]
+ 0.23[sin (wN/2 – πN/N – 1)/sin (w/2 – π/N -1)]
+ 0.23[sin (wN/2 + πN/N – 1)/sin (w/2 + π/N – 1)]
Program:
Columns 8 through 14
Columns 15 through 20
-1 0
-2 0
-3 0
-4 0
Gain in db
-5 0
-6 0
-7 0
-8 0
-9 0
-1 0 0
0 0 .5 1 1.5 2 2.5 3 3 .5
F re q u e n c y in ra d ia n s in t e rm s o f p i
EXPERIMENT NO-12
Example:
Let’s design an analog Butterworth lowpass filter.
Steps to design an analog Butterworth lowpass filter.
1. From the given specifications find the order of the filter N.
2. Round off it to the next higher integer.
3. Find the transfer function H(s) for Ωc = 1rad/sec for the value of N.
4. calculate the value of cutoff frequency Ωc
5. find the transfer function Ha(s) for the above value of Ωc by substituting
s→ (s/ Ωc) in H(s).
Program:
OUTPUT:
Cutoff frequency:
0.4914
b=
0.1600 0.4800 0.4800 0.1600
a=
1.0000 -0.0494 0.3340 -0.0045
Procedure to Setup Emulator:
5. Choose the option Falling edge is JTAG Standard in TMS/TDO Output Timing.
6. Right Click on TMS320C6710 and Select Add to System…Enter.
7. a) Provide Processor Name as TMS320C6713_0
b) Select GEL File, Click on browse icon and select DSP621x_671x.gel.
c) Select N/A in Master/Slave.
d) Click on Ok.
8. Click on Save and quit (highlighted by Circle).
Mathematical Formula:
The linear convolution of two continuous time signals x(t) and h(t) is defined by
Where x(n) is the input signal and h(n) is the impulse response of the system.
Program:
#include<stdio.h>
main()
{ int m=4; /*Lenght of i/p samples sequence*/
int n=4; /*Lenght of impulse response Co-efficients */
int i=0,j;
int x[10]={1,2,3,4,0,0,0,0}; /*Input Signal Samples*/
int h[10]={1,2,3,4,0,0,0,0}; /*Impulse Response Co-efficients*/
/*At the end of input sequences pad 'M' and 'N' no. of zero's*/
int *y;
y=(int *)0x0000100;
for(i=0;i<m+n-1;i++)
{
y[i]=0;
for(j=0;j<=i;j++)
y[i]+=x[j]*h[i-j];
}
for(i=0;i<m+n-1;i++)
printf("%d\n",y[i]);
}
Output:
1, 4, 10, 20, 25, 24, 16.
4. Enter the source code and save the file with “.C” extension.
5. Right click on source, Select add files to project .. and Choose “.C “ file Saved before.
6. Right Click on libraries and select add files to Project.. and choose
C:\CCStudio_v3.1\C6000\cgtools\lib\rts6700.lib and click open.
7. a)Go to Project to Compile .
b) Go to Project to Build.
c) Go to Project to Rebuild All.
Here it
shows
error if
any
8. Go to file and load program and load “.out” file into the board..
9. Go to Debug and click on run to run the program.
10. Observe the output in output window.
11. To see the Graph go to View and select time/frequency in the Graph, And give the
correct Start address provided in the program, Display data can be taken as per user.
12. Green line is to choose the point, Value at the point can be seen (Highlighted by
circle at the left corner).
Experiment 2: Circular Convolution
Procedure to create new Project:
1. To create project, go to Project and Select New.
Circular Convolution:
Let x1(n) and x2(n) are finite duration sequences both of length N with DFT’s X1(k) and
X2(k). Convolution of two given sequences x1(n) and x2(n) is given by the equation,
x3(n) = IDFT[X3(k)]
N-1
Program:
#include<stdio.h>
int m,n,x[30],h[30],y[30],i,j,temp[30],k,x2[30],a[30];
void main()
{
int *y;
y=(int *)0x0000100;
printf(" enter the length of the first sequence\n");
scanf("%d",&m);
printf(" enter the length of the second sequence\n");
scanf("%d",&n);
printf(" enter the first sequence\n");
for(i=0;i<m;i++)
scanf("%d",&x[i]);
printf(" enter the second sequence\n");
for(j=0;j<n;j++)
scanf("%d",&h[j]);
if(m-n!=0) /*If length of both sequences are not equal*/
{
if(m>n) /* Pad the smaller sequence with zero*/
{
for(i=n;i<m;i++)
h[i]=0;
n=m;
}
for(i=m;i<n;i++)
x[i]=0;
m=n;
}
y[0]=0;
a[0]=h[0];
for(j=1;j<n;j++) /*folding h(n) to h(-n)*/
a[j]=h[n-j];
/*Circular convolution*/
for(i=0;i<n;i++)
y[0]+=x[i]*a[i];
for(k=1;k<n;k++)
{
y[k]=0;
/*circular shift*/
for(j=1;j<n;j++)
x2[j]=a[j-1];
x2[0]=a[n-1];
for(i=0;i<n;i++)
{
a[i]=x2[i];
y[k]+=x[i]*x2[i];
}
}
/*displaying the result*/
printf(" the circular convolution is\n");
for(i=0;i<n;i++)
printf("%d ",y[i]);
}
Output:
5. Right click on source, Select add files to project .. and Choose “.C “ file Saved before.
6. Right Click on libraries and select add files to Project.. and choose
C:\CCStudio_v3.1\C6000\cgtools\lib\rts6700.lib and click open.
7. a) Go to Project to Compile .
b) Go to Project to Build.
c) Go to Project to Rebuild All.
In case of
any errors
or
warnings
it will be
displayed
here
8. Go to file and load program and load “.out” file into the board..
9. Go to Debug and click on run to run the program.
10. Enter the input data to calculate the circular convolution.
The corresponding output will be shown on the output window as shown below
11. To see the Graph go to View and select time/frequency in the Graph, and give the
correct Start address provided in the program, Display data can be taken as per user.
12. 12. Green line is to choose the point, Value at the point can be seen (Highlighted by
circle at the left corner).
Experiment 3: N-Point DFT
Procedure to create new Project:
1. To create project, Go to Project and Select New.
The sequence of N complex numbers x0,..., xN−1 is transformed into the sequence of N
complex numbers X0, ..., XN−1 by the DFT according to the formula:
N-1
X(k) = ∑x(n)e -j2πnk/N
k = 0,1, …. N-1
n=0
Program:
#include <stdio.h>
#include <math.h>
#define N 4 //number of data values
float pi = 3.1416;
short x[N] = {1,1,0,0}; //1-cycle cosine
float out[2] = {0,0}; //initialize Re and Im results
void main()
{
int j;
for (j = 0; j < N; j++)
dft(x, j, out); //call DFT function
}
Output:
2.000000 0.000000
0.999996 -1.000000
0.000000 0.000007
1.000011 1.000000
4. Enter the source code and save the file with “.C” extension.
5. Right click on source, Select add files to project .. and Choose “.C “ file Saved before.
6. Right Click on libraries and select add files to Project.. and choose
C:\CCStudio_v3.1\C6000\cgtools\lib\rts6700.lib and click open.
7. a) Go to Project to Compile .
b) Go to Project to Build.
c) Go to Project to Rebuild All.
It will shows
warnings and
errors if any
Here it
shows
error if
any
8. Go to file and load program and load “.out” file into the board..
9. Go to Debug and click on run to run the program.
10. Observe the output in output window.
Output will
shown here
11. To see the Graph go to View and select time/frequency in the Graph, And give the
correct Start address provided in the program, Display data can be taken as per user.
12. Green line is to choose the point, Value at the point can be seen (Highlighted by
circle at the left corner).
Experiment 4: FIR FILTER
Procedure to create new Project:
1. To create project, Go to Project and Select New.
After multiplying w(n) with hd(n), we get a finite duration sequence h(n) that satisfies
the desired magnitude response,
The frequency response H(ejw) of the filter can be obtained by convolution of Hd(ejw)
and W(ejw) is given by,
π
H(ejw) = (1/2π) ∫ Hd(ejθ) W(ej(w-θ) dθ
-π
H(e ) = Hd(e ) * W(ejw)
jw jw
Program:
#include <stdio.h>
#include "c6713dsk.h"
#include "master.h"
#include "aic23cfg.h"
#include "dsk6713_aic23.h"
#include <std.h>
#include <swi.h>
#include <log.h>
#include <c6x.h>
#include <csl.h>
#include <csl_mcbsp.h>
// Delta
/*float filter_Coeff[] ={0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,
0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,
0.00,0.00,0.00,0.00,0.00,0.00,1.00,0.00};*/
DSK6713_AIC23_CodecHandle hCodec;
Int32 InitWait =1;
Int32 data;
Int32 Logger[1024];
Int32 LoggerIndex =0;
float in_buffer[100];
main(){
int i;
LED=0x0;
// Filter Initialization
for( i = 0 ; i < 100; i++ ) in_buffer[i]=0.0;
// Initialize codec
hCodec = DSK6713_AIC23_openCodec(0, &config);
IRQ_globalEnable();
IRQ_enable(IRQ_EVT_RINT1);
IRQ_enable(IRQ_EVT_XINT1);
}
void led(){
static int cc = 1;
LED = cc;
// To Shift Pattern
if (cc == 0x03) cc = 0x05;
else if (cc == 0x05) cc = 0x06;
else if (cc == 0x06) cc = 0x03;
else cc = 0x03;
//To count Binary
//cc++; if (cc>0x07) cc = 0x00;
// TO Toggle LED
// *cc ^= 0x07; if ((cc !=0x00) && (cc !=0x07)) cc = 0x07;
}
setpll200M(){
void read(){
int i = 0;
float result;
data=MCBSP_read(DSK6713_AIC23_DATAHANDLE);
result = 0;
for( i = 0 ; i <= 30; i++ ) result += filter_Coeff[i] * in_buffer[i];
data = (Int32)(result*512);
//data = (Int32)(in_buffer[30]*16);
Logger[LoggerIndex++] = data;
if (LoggerIndex == 1024)
LoggerIndex = 0;
}
void write(){
if (InitWait<1000){
InitWait++;
MCBSP_write(DSK6713_AIC23_DATAHANDLE, 0);
MCBSP_write(DSK6713_AIC23_DATAHANDLE, 0);
}
else{
MCBSP_write(DSK6713_AIC23_DATAHANDLE, data);
MCBSP_write(DSK6713_AIC23_DATAHANDLE, data);
}
}
Output:
4. Enter the source code and save the file with main.c extension.
5. Right click on source, Select add files to project and Choose main.c file Saved before.
6. Add the other supporting .c files which configure the audio codec.
7. 7. a) Go to Project to Compile.
b) Go to Project to Build.
c) Go to Project to Rebuild All.
It will shows
warnings and
errors if any
8. Go to file and load program and load “.out” file into the board.
12. In the graph, chose FFT magnitude as display type we will get Graph B
Graph 2:FFT magnitude of FIR filter.
Program:
#include <stdio.h>
#include "c6713dsk.h"
#include "master.h"
#include "aic23cfg.h"
#include "dsk6713_aic23.h"
#include <std.h>
#include <swi.h>
#include <log.h>
#include <c6x.h>
#include <csl.h>
#include <csl_mcbsp.h>
// Delta
/*float filter_Coeff[] ={0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,
0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,
0.00,0.00,0.00,0.00,0.00,0.00,1.00,0.00};*/
DSK6713_AIC23_CodecHandle hCodec;
Int32 InitWait =1;
Int32 data;
Int32 Logger[1024];
Int32 LoggerIndex =0;
float in_buffer[100];
main(){
int i;
LED=0x0;
// Filter Initialization
for( i = 0 ; i < 100; i++ ) in_buffer[i]=0.0;
// Initialize codec
hCodec = DSK6713_AIC23_openCodec(0, &config);
IRQ_globalEnable();
IRQ_enable(IRQ_EVT_RINT1);
IRQ_enable(IRQ_EVT_XINT1);
}
void led(){
static int cc = 1;
LED = cc;
// To Shift Pattern
if (cc == 0x03) cc = 0x05;
else if (cc == 0x05) cc = 0x06;
else if (cc == 0x06) cc = 0x03;
else cc = 0x03;
//To count Binary
//cc++; if (cc>0x07) cc = 0x00;
// TO Toggle LED
// *cc ^= 0x07; if ((cc !=0x00) && (cc !=0x07)) cc = 0x07;
}
setpll200M(){
void read(){
int i = 0;
float result;
data=MCBSP_read(DSK6713_AIC23_DATAHANDLE);
result = 0;
for( i = 0 ; i <= 30; i++ ) result += filter_Coeff[i] * in_buffer[i];
data = (Int32)(result*512);
//data = (Int32)(in_buffer[30]*16);
Logger[LoggerIndex++] = data;
if (LoggerIndex == 1024)
LoggerIndex = 0;
}
void write(){
if (InitWait<1000){
InitWait++;
MCBSP_write(DSK6713_AIC23_DATAHANDLE, 0);
MCBSP_write(DSK6713_AIC23_DATAHANDLE, 0);
}
else{
MCBSP_write(DSK6713_AIC23_DATAHANDLE, data);
MCBSP_write(DSK6713_AIC23_DATAHANDLE, data);
}
}
Output:
4. Enter the source code and save the file with main.c extension.
5. Right click on source, Select add files to project and Choose main.c file Saved before.
6. Add the other supporting .c files which configure the audio codec.
7. 7. a) Go to Project to Compile.
b) Go to Project to Build.
c) Go to Project to Rebuild All.
It will shows
warnings and
errors if any
8. Go to file and load program and load “.out” file into the board.
9. Go to Debug and click on run to run the program.
10. To see the Graph go to View and select time/frequency in the Graph and give the
correct Start address provided in the program, Display data can be taken as per user.
11. Green line is to choose the point, Value at the point can be seen (Highlighted by
circle at the left corner).
Experiment 7: Impulse Response
Procedure to create new Project:
1. To create project, Go to Project and Select New.
AIM: To find Impulse response of a first order and second order system.
A discrete time system performs an operation on an input signal based on 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,
M M
y(n) = ∑ak y(n-k) + ∑bk x(n-k)
k=1 k=0
Output:
0.131100 0.360237 0.364799 0.174741 0.031373
void main()
{
int j, k;
float a[Order+1] = {0.1311, 0.2622};
float b[Order+1] = {1, -0.7478};
for(j=0; j<Len; j++)
{
sum = 0.0;
for(k=1; k<=Order; k++)
{
if((j-k)>=0)
sum = sum+(b[k]*h[j-k]);
}
if(j<=Order)
h[j] = a[j]-sum;
else
h[j] = -sum;
printf("%f ", j, h[j]);
}
}
Output:
0.131100 0.360237 0.269385 0.201446 0.150641
4. Enter the source code and save the file with “.C” extension.
5. Right click on source, Select add files to project .. and Choose “.C “ file Saved before.
6. Right Click on libraries and select add files to Project.. and choose
C:\CCStudio_v3.1\C6000\cgtools\lib\rts6700.lib and click open.
7. a) Go to Project to Compile.
b) Go to Project to Build.
c) Go to Project to Rebuild All.
It shows errors
and warnings
here.
8. Go to file and load program and load “.out” file into the board..
9. Go to Debug and click on run to run the program.
10. Observe the output in output window.
Output will
display
here
11. To see the Graph go to View and select time/frequency in the Graph, and give the
correct Start address or the output variable name provided in the program, Display data
can be taken as per user. Select DSP data type as 32-bit floating point.
12. Green line is to choose the point, Value at the point can be seen (Highlighted by
circle at the left corner).