SlideShare uma empresa Scribd logo
1 de 68
Baixar para ler offline
K. S. SCHOOL OF ENGINEERING & MANAGEMENT
# 15, Mallasandra, Off Kanakapura Road,
Bangalore-560062, Karnataka, India.
DEPARTMENT OF ELECTRONICS & COMMUNICATION
ENGINEERING
Digital Signal Processing Lab Manual
Sub Code: 10ECL57
Sem : V
Prepared By
Mrs. Vidhya R., Asst. Professor
Mr. Ravikiran B. A., Asst. Professor
Table of Contents
PART – A
1 Verification of Sampling theorem. 1
2 Impulse response of a given system 4
3 Linear convolution of two given sequences. 7
4 Circular convolution of two given sequences 11
5
Autocorrelation of a given sequence and verification of its
properties.
15
6
Cross-correlation of given sequences and verification of
its properties.
18
7 Solving a given difference equation. 21
8
Computation of N point DFT of a given sequence and to
plot magnitude and phase spectrum.
23
9
Linear convolution of two sequences using DFT and
IDFT.
26
10
Circular convolution of two given sequences using DFT
and IDFT
29
11
Design and implementation of FIR filter to meet given
specifications.
32
12
Design and implementation of IIR filter to meet given
specifications.
36
DSPLab-ECEDepartment,KSSEM
PART – B
About the DSP Trainer Kit 44
Using Code Composer Studio 47
1 Linear convolution of two given sequences. 56
2 Circular convolution of two given sequences 58
3 Computation of N point DFT of a given sequence. 60
4
Impulse Response of the First Order and Second Order
Systems
62
Viva Questions 64
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) 5th
Sem KSSEM, Bangalore
Dept of ECE Page | 1
PROGRAM 1
VERIFICATION OF SAMPLING THEOREM
Aim: To write the MATLAB code for verifying Sampling Theorem.
Generate a sinusoidal wave of 1kHz. Calculate the Nyquist frequency, and verify
Sampling Theorem, showing output waveforms for undersampled, oversampled and right
sampled cases.
Theory:
Sampling is the process of converting an continuous time signal into a discrete time signal.
In sampling, the values of the continuous time signal is recorded at discrete intervals of time
(usually equidistant). The number of samples taken during one second is called the sampling
rate.
Sampling is described by the relation: 𝑥(𝑛) = 𝑥 𝑎(𝑛𝑇) − ∞ < 𝑛 < ∞
Where 𝑥(𝑛) is the discrete-time signal obtained by sampling the analog signal every T
seconds. 𝐹𝑠 = 1/𝑇 is known as the Sampling Frequency.
The Sampling Theorem states that :
“A bandlimited signal can be reconstructed exactly if it is sampled at a rate atleast twice
the maximum frequency component in it."
Assume a band-limited signal 𝑥(𝑡) = 𝐴 sin(𝜔𝑡) = 𝐴 sin(2𝜋𝐹𝑡) with maximum
frequency component ′𝜔′. The theorem says that, for a good reconstruction of the original
continuous time signal, the sampling frequency must be at least 2𝜔. This frequency is known
as the “Nyquist Rate”.
Sampling this signal at 𝐹𝑠 gives us the discrete time signal:
𝑥 𝑎(𝑛𝑇) = 𝐴 sin �
2𝜋𝑛𝐹
𝐹𝑠
�
Now, assuming the sampling frequency is more than the Nyquist Frequency, the
continuous time signal can be reconstructed accurately using the interpolation function:
𝑔(𝑡) =
sin 2𝜋𝐹𝑡
2𝜋𝐹𝑡
Then, approximated recovered signal can be written as:
𝑥′
𝑎(𝑡) = � 𝑥 𝑎 �
𝑛
𝐹𝑠
�
∞
𝑛=−∞
𝑔 �𝑡 −
𝑛
𝐹𝑠
�
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) 5th
Sem KSSEM, Bangalore
Dept of ECE Page | 2
Whenever the Sampling frequency 𝐹𝑠 is greater than or equal to the Nyquist Frequency, the
signal can be reconstructed faithfully, capturing all the essential properties of the original
continuous-time signal. However, when 𝐹𝑠 < 2𝐹, we encounter a problem called “Aliasing”,
where distortion is caused by high frequencies overlapping low frequencies. A lot of data is
lost in this process and the signal cannot be recovered.
MATLAB CODE:
% Experiment 1 : Sampling Theorem Verification
clear all; close all; clc;
% Signal Parameters
f = 1000; % Signal Frequency = 1kHz
T = 1/f; % Signal Period
t = 0:0.01*T:2*T; % Time index
% Generate the original signal and plot it:
x = cos(2*pi*t*f); % Signal : 2*pi*f*t
subplot(2,2,1);
plot(t,x);
title('Continuous signal');
xlabel('t');
ylabel('x(t)');
%Oversampling Condition:
fs1 = 10*f; % Oversampling (fs > 2f)
n1 = 0:1/fs1:2*T; % Time scale
x1 = cos(2*pi*f*n1); % Generating sampled signal
subplot(2,2,2);
stem(n1,x1);
hold on;
plot(n1,x1,'r');
hold off;
title('Oversampling Condition : Fs = 10F');
xlabel('n');
ylabel('x(n)');
% Right Sampling Condition:
fs2 = 2*f; % Nyquist Rate Sampling (fs = 2f)
n2 = 0:1/fs2:2*T;
x2 = cos(2*pi*f*n2);
subplot(2,2,3);
stem(n2,x2);
hold on;
plot(n2,x2,'r');
hold off;
title('Sampling at Nyquist Frequency : Fs = 2F');
xlabel('n');
ylabel('x(n)');
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) 5th
Sem KSSEM, Bangalore
Dept of ECE Page | 3
% Under Sampling Condition:
fs3 = 1.5*f; % Undersampling (fs < 2f)
n3 = 0:1/fs3:2*T;
x3 = cos(2*pi*f*n3);
subplot(2,2,4);
stem(n3,x3);
hold on;
plot(n3,x3,'r');
hold off;
title('Undersampling Condition : Fs = 1.5 f');
xlabel('n');
ylabel('x(n)');
OUTPUT:
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) 5th
Sem KSSEM, Bangalore
Dept of ECE Page | 4
PROGRAM 2
IMPULSE RESPONSE OF A GIVEN SYSTEM
Aim: To write the MATLAB code to find the impulse response of a given second-order
system whose difference equation representation is given.
Assume a second-order system represented by the following difference equation:
𝑦(𝑛) = 𝑏0 𝑥(𝑛) + 𝑏1 𝑥(𝑛 − 1) + 𝑏20 𝑥(𝑛 − 2) + 𝑎1 𝑦(𝑛 − 1) + 𝑎2 𝑦(𝑛 − 2)
Theory:
Impulse response of a system is defined as the output of a given system, when the input
applied to the system, is in the form of an unit impulse, or a Dirac delta function. The impulse
response completely characterizes the behaviour of any LTI system. The impulse response is
often determined from knowledge of the system configuration and dynamics, or can be
measured by applying and approximate impulse to the system input.
Discrete-time LTI systems can also be described using Difference Equations. A linear
constant-coefficient difference equation can be of the form:
� 𝑎 𝑘 𝑦[𝑛 − 𝑘] =
𝑁
𝑘=0
� 𝑏 𝑘 𝑦[𝑛 − 𝑘]
𝑀
𝑘=0
Where the integer N is termed the order of the difference equation, and corresponds to the
maximum memory involving the system output. The order generally represents the number of
energy storage devices in a physical system.
We can calculate the impulse response of the system using Z-transforms as shown in the
following example:
Consider a difference equation:
𝑦(𝑛) = 𝑥(𝑛) + 0.2 𝑥(𝑛 − 1) − 1.5 𝑥(𝑛 − 2) − 3 𝑦(𝑛 − 1) + 0.12 𝑦(𝑛 − 2)
This can be rewritten in the standard form as:
𝑦(𝑛) + 3 𝑦(𝑛 − 1) − 0.12 𝑦(𝑛 − 2) = 𝑥(𝑛) + 0.2 𝑥(𝑛 − 1) − 1.5 𝑥(𝑛 − 2)
Finding the Z-transform of the equation:
𝑌(𝑍) + 3 𝑍−1
𝑌(𝑍) − 0.12 𝑍−2
𝑌(𝑍) = 𝑋(𝑍) + 0.2 𝑍−1
𝑋(𝑍) − 1.5 𝑍−2
𝑋(𝑍)
Or:
𝑌(𝑍)[1 + 3 𝑍−1
− 0.12 𝑍−2
] = 𝑋(𝑍)[1 + 0.2 𝑍−1
− 1.5 𝑍−2
]
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) 5th
Sem KSSEM, Bangalore
Dept of ECE Page | 5
Transfer Function of the system can be obtained as :
𝐻(𝑍) =
𝑌(𝑍)
𝑋(𝑍)
=
[1 + 3 𝑍−1
− 0.12 𝑍−2
]
[1 + 0.2 𝑍−1 − 1.5 𝑍−2]
By long division, we get :
𝐻(𝑍) = 1 − 2.8 𝑍−1
+ 7.02 𝑍−2
− 21.4 𝑍−3
+ 65.03 𝑍−4
By taking Inverse-Z transform, we can obtain the Impulse Response as:
ℎ[𝑛] = [1 − 2.8 7.02 21.4 65.03]
MATLAB CODE:
% Experiment 2 : Impulse Response of a Given Second-Order System
clear all; close all; clc;
% Accept Input and Output signal Co-efficients:
b = input('Enter the coefficients of x(n) in 1-D Matrix Form: ');
a = input('Enter the coefficients of y(n) in 1-D Matrix Form: ');
N = input('Enter the number of samples of impulse response desired: ');
% Calculate Impulse Response using IMPZ function:
% [H,T] = IMPZ(B,A,N) computes N samples of the impulse response, using
% coefficients B and A from difference equation representation.
[h,t] = impz(b,a,N);
%Plot and Display impulse response co-efficients:
stem(t,h);
title('Impulse Response Plot');
ylabel('h(n)'); xlabel('n');
disp('Impulse Response Coefficients:');
disp(h);
OUTPUT:
Enter the coefficients of x(n) in 1-D Matrix Form: [1 0.2 -1.5]
Enter the coefficients of y(n) in 1-D Matrix Form: [1 3 -0.12]
Enter the number of samples of impulse response desired: 5
Impulse Response Coefficients:
1.0000
-2.8000
7.0200
-21.3960
65.0304
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) 5th
Sem KSSEM, Bangalore
Dept of ECE Page | 6
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) 5th
Sem KSSEM, Bangalore
Dept of ECE Page | 7
PROGRAM 3
LINEAR CONVOLUTION OF TWO GIVEN SEQUENCES
Aim: To write the MATLAB code to perform Linear Convolution upon two given discrete
time signals.
Theory:
Convolution is the process used to find the response of a Linear Time Invariant system to a
given input, assuming we already know the impulse response of that system. In case of
continuous-time signals, we can find the system response using the Convolution Integral,
while in case of discrete-time systems, the response can be calculated using the Convolution
Sum.
Let 𝑥1(𝑛) and 𝑥2(𝑛) be two discrete-time signals. The convolution sum of the two signals
can be calculated using the formula:
𝑦(𝑛) = 𝑥1(𝑛) ∗ 𝑥2(𝑛) = � 𝑥1(𝑘) 𝑥2(𝑛 − 𝑘)
∞
𝑘=−∞
If 𝑥1(𝑛) is a M- point sequence and 𝑥2(𝑛) is an N – point sequence, then the convolved
sequence, 𝑦(𝑛) is a (M+N-1) – point sequence.
We can perform the convolution by different methods:
1. Using MATLAB’s “CONV” function :
MATLAB has a built-in function called “conv” function, which basically performs a
linear convolution of any two given sequences.
2. Using the Linear Convolution Sum formula :
Here, we use the convolution sum formula and substitute values of 𝑛 and 𝑘 in the
expression, and calculate the values of the convolved signal. Alternatively, we can
perform the signal inversion-time shift-superposition method, by which we can
calculate the resultant signal values.
Assume two discrete-time sequences 𝑥1 and 𝑥2 in a Linear Time Invariant System, given
by:
𝑥1(𝑛) = {1, 2, −1, 3} and 𝑥2(𝑛) = {2,3, −2}
We see that length of sequence 𝑥1 is (M = 4) and that of sequence 𝑥2 is (N = 3). Therefore,
the length of the convolved sequence will be (M+N-1 = 6).
Using any of the above given methods, we see that the resultant convolved sequence can be
given by:
𝑦(𝑛) = 𝑥1(𝑛) ∗ 𝑥2(𝑛) = { 2 7 2 − 1 11 − 6}
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) 5th
Sem KSSEM, Bangalore
Dept of ECE Page | 8
MATLAB CODE:
1. Using “conv” function:
%% Linear Convolution using CONV command
clear all; close all; clc;
% Accept input signal sequences
x1 = input('Enter Input Sequence for Signal x1(n): ');
x2 = input('Enter Input Sequence for Signal x2(n): ');
%Perform Linear Convolution using CONV command
y=conv(x1,x2);
%Plot Input and Convolved Signals
subplot(3,1,1);
stem(x1);
title('Input Signal x1(n)');
xlabel('n'); ylabel('x1(n)');
subplot(3,1,2);
stem(x2);
title('Input Signal x2(n)');
xlabel('n'); ylabel('x2(n)');
subplot(3,1,3);
stem(y);
title('Convolved Signal y(n) = x1(n)*x2(n)');
xlabel('n'); ylabel('y(n)');
% Display the convolved Sequence in Command Window
disp('Convolved sequence:');
disp(y);
2. Using Convolution Sum formula:
%% Linear Convolution without using CONV command
clear all; close all; clc;
x1 = input('Enter Input Sequence for Signal x1(n): ');
n1 = length(x1);
x2 = input('Enter Input Sequence for Signal x2(n): ');
n2=length(x2);
N = n1+n2-1; %Length of Convolved Sequence
T = 1:N; % Create Time Index
%Zero padding to make sequences of length N
x1=[x1 zeros(1,N-n1)];
x2=[x2 zeros(1,N-n2)];
%Initializing Output sequence of zeros.
y = zeros(1,N);
%Performing Linear Convolution:
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) 5th
Sem KSSEM, Bangalore
Dept of ECE Page | 9
for n = 1:N
% y(n) = 0R;
for k = 1:n
y(n)=y(n)+x1(k)*x2(n-k+1);
end
end
% Plot Input and Output Sequences:
subplot(3,1,1);
stem(T,x1);
title('Input Signal x1(n)');
xlabel('n'); ylabel('x1(n)');
subplot(3,1,2);
stem(T,x2);
title('Input Signal x2(n)');
xlabel('n'); ylabel('x2(n)');
subplot(3,1,3);
stem(T,y);
title('Convolved Signal y(n) = x1(n)*x2(n)');
xlabel('n'); ylabel('y(n)');
% Display the convolved Sequence in Command Window
disp('Convolved sequence:');
disp(y);
OUTPUT:
Enter Input Sequence for Signal x1(n): [1 2 -1 3]
Enter Input Sequence for Signal x2(n): [2 3 -2]
Convolved sequence:
2 7 2 -1 11 -6
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) 5th
Sem KSSEM, Bangalore
Dept of ECE Page | 10
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) 5th
Sem KSSEM, Bangalore
Dept of ECE Page | 11
PROGRAM 4
CIRCULAR CONVOLUTION OF TWO GIVEN SEQUENCES
Aim: To write the MATLAB code to perform Circular Convolution upon two given discrete
time signals.
Theory:
The Circular convolution, also known as cyclic convolution, of two aperiodic functions occurs
when one of them is convolved in the normal way with a periodic summation of the other
function. Circular convolution is only defined for finite length functions (usually equal in
length), continuous or discrete in time. In circular convolution, it is as if the finite length
functions repeat in time, periodically. Because the input functions are now periodic, the
convolved output is also periodic.
Circular convolution sum can be calculated using the formula:
𝑦(𝑛) = 𝑥1(𝑛) ∗ 𝑥2(𝑛) = � 𝑥1(𝑛) 𝑥2�(𝑚 − 𝑛)� 𝑁
𝑁−1
𝑛=0
For 𝑚 = 0,1, … . , 𝑁 − 1
Circular convolution can be performed in different ways :
1. Using the expression for linear convolution sum, but assuming the signal repeats
periodically. This can be done by changing the negative indices of (n-k) to repetitions
of the latter portions of the original aperiodic signal.
2. Convolution in time domain corresponds to multiplication in frequency domain. To
make use of this property, we can calculate the DTFT of each of the aperiodic signals,
multiply these in the frequency domain, and find the IDFT of the product, to get the
periodic convolved signal in time domain.
Let us take the case of two discrete-time aperiodic signals given by:
𝑥1(𝑛) = {2,1,2,1} and 𝑥2(𝑛) = {1,2,3,4}
Using the formula with N = 4.
For m = 0:
𝑦(0) = � 𝑥1(𝑛) 𝑥2�(−𝑛)�4
3
𝑛=0
= 14
For m = 1:
𝑦(1) = � 𝑥1(𝑛) 𝑥2�(1 − 𝑛)�4
3
𝑛=0
= 16
For m = 2:
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) 5th
Sem KSSEM, Bangalore
Dept of ECE Page | 12
𝑦(2) = � 𝑥1(𝑛) 𝑥2�(2 − 𝑛)�4
3
𝑛=0
= 14
For m = 3:
𝑦(3) = � 𝑥1(𝑛) 𝑥2�(3 − 𝑛)�4
3
𝑛=0
= 16
So, we get the circular convolution sum as: 𝑦(𝑛) = {14,16,14,16}
MATLAB CODE:
1. Using Convolution Sum Formula:
%% Circular Convolution using Formula
clear all; close all; clc;
x1 = input('Enter Input Sequence for Signal x1(n): ');
n1 = length(x1);
x2 = input('Enter Input Sequence for Signal x2(n): ');
n2=length(x2);
N = max(n1,n2); % Length of Convolved Sequence
T = 1:N; % Create Time Index
%Zero padding to make sequences of length N
x1=[x1 zeros(1,N-n1)];
x2=[x2 zeros(1,N-n2)];
%Initializing Output sequence of zeros.
y = zeros(1,N);
%Performing Linear Convolution:
for m=1:N
for n=1:N
i=m-n+1; %(m-n+1) since we're taking index
from 1
if(i<=0)
i=N+i;
end
y(m)=y(m)+x1(n)*x2(i); %Convolution Sum Formula
end
end
% Plot Input and Output Sequences:
subplot(3,1,1);
stem(T,x1);
title('Input Signal x1(n)');
xlabel('n'); ylabel('x1(n)');
subplot(3,1,2);
stem(T,x2);
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) 5th
Sem KSSEM, Bangalore
Dept of ECE Page | 13
title('Input Signal x2(n)');
xlabel('n'); ylabel('x2(n)');
subplot(3,1,3);
stem(T,y);
title('Convolved Signal y(n) = x1(n)*x2(n)');
xlabel('n'); ylabel('y(n)');
% Display the convolved Sequence in Command Window
disp('Convolved sequence:');
disp(y);
2. Using “cconv” function.
%% Circular Convolution using CCONV command
clear all; close all; clc;
% Accept input signal sequences
x1 = input('Enter Input Sequence for Signal x1(n): ');
x2 = input('Enter Input Sequence for Signal x2(n): ');
n=max(length(x1),length(x2));
%Perform Linear Convolution using CONV command
y=cconv(x1,x2,n);
%Plot Input and Convolved Signals
subplot(3,1,1);
stem(x1);
title('Input Signal x1(n)');
xlabel('n'); ylabel('x1(n)');
subplot(3,1,2);
stem(x2);
title('Input Signal x2(n)');
xlabel('n'); ylabel('x2(n)');
subplot(3,1,3);
stem(y);
title('Convolved Signal y(n) = x1(n)*x2(n)');
xlabel('n'); ylabel('y(n)');
% Display the convolved Sequence in Command Window
disp('Convolved sequence:');
disp(y);
OUTPUT:
Enter Input Sequence for Signal x1(n): [2 1 2 1]
Enter Input Sequence for Signal x2(n): [1 2 3 4]
Convolved sequence:
14 16 14 16
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) 5th
Sem KSSEM, Bangalore
Dept of ECE Page | 14
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) 5th
Sem KSSEM, Bangalore
Dept of ECE Page | 15
PROGRAM 5
AUTOCORRELATION OF A GIVEN SEQUENCE
Aim: To write the MATLAB code to perform Autocorrelation on a given signal and to verify
its properties.
Theory:
In signal processing, Correlation is a measure of similarity of two waveforms, as a function
of a time-lag applied to one of them. This is also known as a sliding dot product or sliding
inner-product. It is commonly used for searching a long-signal for a shorter, known feature.
Auto-correlation is a special form of Correlation, in which a signal is cross-convolved with
itself. It is a mathematical tool for finding repeating patterns, such as the presence of a
periodic signal which has been buried under noise, or identifying the missing fundamental
frequency in a signal implied by its harmonic frequencies. It is often used in signal processing
for analyzing functions or series of values, such as time domain signals.
Auto-correlation of a signal 𝑥(𝑛) is given by the formula:
𝑟𝑥𝑥(𝑙) = � 𝑥(𝑛)𝑥(𝑛 − 𝑙) 𝑙 = 0, ±1, ±2, …
∞
𝑛=−∞
In case of finite-duration signals, we can write:
𝑟𝑥 𝑥(𝑙) = � 𝑥(𝑛)𝑥(𝑛 − 𝑙)
𝑁−|𝑘|−1
𝑛=𝑖
Where 𝑖 = 𝑙, 𝑘 = 0 𝑓𝑜𝑟 𝑙 ≥ 0 and 𝑖 = 0, 𝑘 = 𝑙 𝑓𝑜𝑟 𝑙 < 0.
Assuming our signal is of the form 𝑎𝑥(𝑛) + 𝑏𝑥(𝑛 − 𝑙)
Energy in the signal is given by:
� [𝑎𝑥(𝑛) + 𝑏𝑥(𝑛 − 𝑙)]2
∞
𝑛=−∞
= 𝑎2
� 𝑥2
∞
𝑛=−∞
(𝑛) + 𝑏2
� 𝑥2
∞
𝑛=−∞
(𝑛 − 𝑙) + 2𝑎𝑏 � 𝑥
∞
𝑛=−∞
(𝑛)𝑥(𝑛 − 𝑙)
= 𝑎2
𝑟𝑥 𝑥(0)+𝑏2
𝑟𝑥 𝑥(0) + 2𝑎𝑏 𝑟𝑥 𝑥(𝑙) ≥ 0
This can be written as: |𝑟𝑥𝑥(𝑙)| ≤ |𝑟𝑥𝑥(0)| = 𝐸 𝑥.
That is, autocorrelation sequence of a signal attains its maximum value at zero lag. This is
consistent with the notion that a signal matches perfectly with itself at zero shift.
Assume a signal 𝑥(𝑛) = {1,2,3,4}. Its autocorrelation sequence can be calculated as:
𝑟𝑥 𝑥(𝑙) = {4,11,20,30, 20,11,4}
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) 5th
Sem KSSEM, Bangalore
Dept of ECE Page | 16
Energy of the signal is given by:
𝐸 = � 𝑥(𝑛)2
3
𝑛=0
= 12
+ 22
+ 32
+ 42
= 30 = 𝑟𝑥 𝑥(0)
Hence, it is an energy signal.
We see that the Total energy of the signal is equal to the amplitude of the autocorrelation
signal at the origin.
MATLAB CODE:
% Experiment 5 : Autocorrelation of a Signal.
clear all; close all; clc;
% Accept user-defined input sequence and define time index
x = input('Enter a finite-length signal sequence : ');
n = 0:length(x)-1;
% Perform Autocorrelation using xcorr function.
rxx = xcorr(x,x);
% Generate Time Index for Autocorrelation sequence, about origin
n2 = -length(x)+1:length(x)-1;
disp('Autocorrelation Sequence : ');
disp(int8(rxx));
% Plot the Original Signal and Autocorrelation Sequence
subplot(2,1,1);
stem(n,x);
title('Input Signal');
xlabel('n'); ylabel('x(n)');
subplot(2,1,2);
stem(n2,rxx);
title('Autocorrelation Sequence');
xlabel('n'); ylabel('rxx(l)');
grid on;
% Verifying Autocorrelation properties:
E = sum(x.^2); % Energy of signal.
mid = ceil(length(rxx)/2); % Find index of centre of sequence
E0 = rxx(mid); % Detect Amplitude of Sequence
midpoint
fprintf('Energy of Input Signal : %dn',E);
fprintf('Amplitude of Midpoint of Autocorrelation Sequence :
%dn',E0);
% Verify Autocorrelation Property by comparing Energy values
if int8(E0) == int8(E) %Type conversion for approximation
disp('Autocorrelation Energy Property is verified');
else
disp('Autocorrelation Energy Property is not verified');
end
% Verify that the Signal is even.
rxx_r = rxx(mid:length(rxx)); %Right Side of AC Sequence
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) 5th
Sem KSSEM, Bangalore
Dept of ECE Page | 17
rxx_l = rxx(mid:-1:1); %Left Side of AC Sequence
if rxx_r == rxx_l
disp('Autocorrelation Sequence is Even. Hence, verified.');
else
disp('Autocorrelation Sequence is not Even. Hence, not
verified.');
end
OUTPUT:
Enter a finite-length signal sequence : [1 2 3 4]
Autocorrelation Sequence :
4 11 20 30 20 11 4
Energy of Input Signal : 30
Amplitude of Midpoint of Autocorrelation Sequence : 30
Autocorrelation Energy Property is verified
Autocorrelation Sequence is Even. Hence, verified.
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) 5th
Sem KSSEM, Bangalore
Dept of ECE Page | 18
PROGRAM 6
CROSS - CORRELATION OF A GIVEN SEQUENCE
Aim: To write the MATLAB code to perform cross-correlation on a given signal and to verify
its properties.
Theory:
Cross-correlation is a process, in which a signal is convolved with another signal. It is
commonly used for searching a long-signal for a shorter, known feature. It also has
applications in pattern recognition, single particle analysis, electron tomographic averaging,
cryptanalysis, and neurophysiology. Cross-correlation of two signals 𝑥1(𝑛) and 𝑥2(𝑛) is
given by the formula:
𝑟𝑥 𝑦(𝑙) = � 𝑥(𝑛)𝑦(𝑛 − 𝑙) 𝑙 = 0, ±1, ±2, …
∞
𝑛=−∞
In case of finite-duration signals, we can write:
𝑟𝑥 𝑦(𝑙) = � 𝑥(𝑛)𝑦(𝑛 − 𝑙)
𝑁−|𝑘|−1
𝑛=𝑖
Where 𝑖 = 𝑙, 𝑘 = 0 𝑓𝑜𝑟 𝑙 ≥ 0 and 𝑖 = 0, 𝑘 = 𝑙 𝑓𝑜𝑟 𝑙 < 0.
Assuming our signal is of the form 𝑎𝑥(𝑛) + 𝑏𝑦(𝑛 − 𝑙)
Energy in the signal is given by:
� [𝑎𝑥(𝑛) + 𝑏𝑦(𝑛 − 𝑙)]2
∞
𝑛=−∞
= 𝑎2
� 𝑥2
∞
𝑛=−∞
(𝑛) + 𝑏2
� 𝑦2
∞
𝑛=−∞
(𝑛 − 𝑙) + 2𝑎𝑏 � 𝑥
∞
𝑛=−∞
(𝑛)𝑦(𝑛 − 𝑙)
= 𝑎2
𝑟𝑥𝑥(0)+𝑏2
𝑟𝑦𝑦(0) + 2𝑎𝑏 𝑟𝑥𝑦(𝑙) ≥ 0
This can be written as: �𝑟𝑥 𝑦(𝑙)� ≤ � 𝑟𝑥 𝑥(0)𝑟𝑦𝑦(0) = � 𝐸 𝑥 𝐸 𝑦.
Note that the shape of the autocorrelation sequence does not change with amplitude scaling
of input signals. Only the amplitude of the autocorrelation sequence changes accordingly.
Cross-correlation satisfies the property:
𝑟𝑥𝑦(𝑙) = 𝑟𝑦𝑥(−𝑙)
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) 5th
Sem KSSEM, Bangalore
Dept of ECE Page | 19
MATLAB CODE:
% Experiment 6 : Cross-correlation of two Signals.
clear all; close all; clc;
% Accept user-defined input sequences and define time index for it
x1 = input('Enter a finite-length signal sequence X1(n): ');
n1 = 0:length(x1)-1;
x2 = input('Enter a finite-length signal sequence X2(n): ');
n2 = 0:length(x2)-1;
x= max(x1,x2);
% Perform Cross - Correlation using xcorr function.
rxy = xcorr(x1,x2); % rxy(l)
ryx = xcorr(x2,x1); % ryx(l)
% Generate Time Index for Cross - Correlation sequence, about origin
n3 = -length(x)+1:length(x)-1;
disp('Cross - Correlation Sequence rxy(l): ');
disp(int8(rxy));
disp('Cross - Correlation Sequence ryx(l): ');
disp(int8(ryx));
% Plot the Original Signal and Cross - Correlation Sequence
subplot(3,1,1);
stem(n1,x1);
title('Input Signal 1');
xlabel('n'); ylabel('x1(n)');
subplot(3,1,2);
stem(n2,x2);
title('Input Signal 2');
xlabel('n'); ylabel('x2(n)');
subplot(3,1,3);
stem(n3,rxy);
title('Cross - Correlation Sequence');
xlabel('n'); ylabel('rxy(l)');
grid on;
% Verifying Cross-correlation properties:
E1 = sum(x1.^2); % Energy of signal 1.
E2 = sum(x2.^2); % Energy of signal 2.
mid = ceil(length(rxy)/2); % Find index of centre of sequence
E0 = abs(max(rxy)); % Detect Max Amplitude of Sequence
fprintf('Energy of Input Signal X1 : %dn',E1);
fprintf('Energy of Input Signal X2 : %dn',E2);
fprintf('Max Amplitude of Cross - Correlation Sequence : %dn',E0);
% Verify Cross - Correlation Property by comparing Energy values
% Max amplitude of Sequence should be less than sqrt(E1*E2).
if int8(E0) <= int8(sqrt(E1*E2)) %Type conversion to 8-bit
int
disp('Cross - Correlation Energy Property is verified');
else
disp('Cross - Correlation Energy Property is not verified');
end
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) 5th
Sem KSSEM, Bangalore
Dept of ECE Page | 20
% Verify Signal property : rxy(l)=ryx(-l).
if rxy == fliplr(ryx)
disp('Since rxy(l) = ryx(-l), Cross - Correlation property is
verified.');
else
disp('Cross - Correlation property is not verified.');
end
OUTPUT:
Enter a finite-length signal sequence X1(n): [4 3 2 1]
Enter a finite-length signal sequence X2(n): [1 2 3 4]
Cross - Correlation Sequence rxy(l):
16 24 25 20 10 4 1
Cross - Correlation Sequence ryx(l):
1 4 10 20 25 24 16
Energy of Input Signal X1 : 30
Energy of Input Signal X2 : 30
Max Amplitude of Cross - Correlation Sequence : 25
Cross - Correlation Energy Property is verified
Since rxy(l) = ryx(-l), Cross - Correlation property is verified.
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) 5th
Sem KSSEM, Bangalore
Dept of ECE Page | 21
PROGRAM 7
SOLVING A GIVEN DIFFERENCE EQUATION
Aim: To write the MATLAB code to solve a given difference equation, given the co-efficients
and initial values.
Let us consider the difference equation as y (n) – 3/2 y (n-1) + ½ y (n-2) = x (n). Given
x(n) = (1/4)n
*u(n). Assume initial conditions as y(-1) = 4, y(-2) = 10.
Theory:
Consider x(n) = (1/4)n
*u(n).
Let n take values from 0 to 5,
n=0:5
n=0, x(0)=1
n=1, x(1)=0.25
n=2, x(2)=0.0625
n=3, x(3)=0.0156
n=4, x(4)=0.0039
n=5, x(5)=0.0010
For n=0;
y(0) - 3/2 y(0-1) + 1/2 y(0-2) = x(0)
Substituting the initial conditions and the value of x(0) in the above equation we get,
y(0) = 1 + 6 - 5 = 2
Similarly,
For n=1; y(1) = 0.25 + 3 - 2 = 1.2500
For n=2; y(2) = 0.0625 + 1.875 -1 = 0.9375
For n=3; y(3) = 0.0156 + 1.40625 - 0.625 = 0.7969
For n=4; y(4) = 0.0039 + 1.19535 - 0.46625 = 0.7365
For n=5; y(5) = 0.0010 + 1.09575 - 0.3982 = 0.6982
MATLAB CODE:
%Experiment 7 : Difference Equation Solving
clear all; close all; clc;
%Accept Difference Equation Coefficients from Input
b = input('Enter the coefficients of input x(n) : ');
a = input('Enter the coefficients of output y(n) : ');
y = input('Enter the initial conditions y(-1), y(-2),... : ');
%Calculate Initial Conditions using filtic
z = filtic(b,a,y);
%Enter Input sequence samples.
x = [1 1/4 1/16 1/64 1/256 1/1024];
n = 0:length(x)-1; %Time Base for plotting
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) 5th
Sem KSSEM, Bangalore
Dept of ECE Page | 22
%Calculate output using initial conditions
Yout = filter(b,a,x,z);
%Display output sequence
disp('Difference Equation Solution : y(n) : ');
disp(Yout);
%Plot Input and Output
subplot(2,1,1);
stem(n,x);
title('Input Sequence x(n)');
xlabel('n'); ylabel('x(n)');
subplot(2,1,2);
stem(n,Yout);
grid on;
title('Output Sequence y(n)');
xlabel('n'); ylabel('y(n)');
OUTPUT:
Enter the coefficients of input x(n) : 1
Enter the coefficients of output y(n) : [1 -3/2 1/2]
Enter the initial conditions y(-1), y(-2),... : [4 10]
Difference Equation Solution : y(n) :
2.0000 1.2500 0.9375 0.7969 0.7305
0.6982
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) 5th
Sem KSSEM, Bangalore
Dept of ECE Page | 23
PROGRAM 8
COMPUTATION OF N- POINT DFT
Aim: Computation of N point DFT of a given sequence and to plot magnitude and phase
spectrum.
Theory:
DFT stands for Discrete Fourier Transform. It is used to find the amplitude and phase
spectrum of a discrete time sequence.
The N-point DFT of a finite-length sequence x(n) of length N, is given by X(k) as
x(n) X(k)
Basic equation to find the DFT of a sequence is given below.
𝑋(𝑘) = � 𝑥(𝑛)𝑒
−𝑗�
2𝜋
𝑁
�𝑘𝑛
𝑁−1
𝑛=0
For example: Find the DFT of the sequence x(n) = {0,1,2,3}
In this case N=4.
For k=0,
𝑋(0) = � 𝑥(𝑛)𝑒0
= 𝑥(0) + 𝑥(1) + 𝑥(2) + 𝑥(3) = 0 + 1 + 2 + 3 = 6
4−1
𝑛=0
For k=1,
𝑋(1) = � 𝑥(𝑛)𝑒
−𝑗�
2𝜋
𝑁
�𝑛
= 𝑥(1)𝑒
−𝑗�
2𝜋
4
�.0
+ 𝑥(1)𝑒
−𝑗�
2𝜋
4
�1
+ 𝑥(2)𝑒
−𝑗�
2𝜋
4
�2
+ 𝑥(3)𝑒
−𝑗�
2𝜋
4
�3
4−1
𝑛=0
= - j- 2 + 3j = -2 + j2
Similarly,
For k=2,
𝑋(2) = � 𝑥(𝑛)𝑒
−𝑗�
2𝜋
4
�2𝑛
= 𝑥(1)𝑒−𝑗𝜋.0
+ 𝑥(1)𝑒−𝑗𝜋1
+ 𝑥(2)𝑒−𝑗𝜋2
+ 𝑥(3)𝑒−𝑗𝜋3
4−1
𝑛=0
= 0-1+2-3 = -2
For k=3,
X(3) = -2 –j2
Hence, X(k) = {6, -2+j2, -2, -2-j2}
N-DFT
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) 5th
Sem KSSEM, Bangalore
Dept of ECE Page | 24
MATLAB CODE:
%Experiment 8 : N-Point DFT
clear all; close all; clc;
%Accept Input sequence from user
xn = input ('Enter the sequence x(n) : ');
xn=xn';
N = length(xn);
Xk = zeros(N, 1); %Initialize zero matrix for DFT sequence
%Calculate DFT using formula
n = 0:N-1;
for k = 0:N-1
Xk(k+1) = exp(-j*2*pi*k*n/N)*xn;
end
%Display DFT Sequence
disp('DSP Sequence : X(k) :');
disp(Xk);
%Plot Signals
n = 0:N-1; %Time base
% Input Sequence
subplot (2,2,[1:2]);
stem(n, xn);
title('Input Sequence x(n)');
xlabel('n');ylabel('x(n)');
% Output Magnitude Plot
subplot (2,2,3);
stem(n, abs(Xk));
grid on;
title('Magnitude Plot of DFT : |X(k)|');
xlabel('n');ylabel('|X(k)|');
% Output Phase Plot
subplot(2,2,4);
stem(n, angle(Xk)');
grid on;
title('Phase Plot of DFT : angle(X(k))');
xlabel('n');ylabel('Angle');
OUTPUT:
Enter the sequence x(n) : [0 1 2 3]
DSP Sequence : X(k) :
6.0000
-2.0000 + 2.0000i
-2.0000 - 0.0000i
-2.0000 - 2.0000i
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) 5th
Sem KSSEM, Bangalore
Dept of ECE Page | 25
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) 5th
Sem KSSEM, Bangalore
Dept of ECE Page | 26
PROGRAM 9
LINEAR CONVOLUTION USING DFT AND IDFT
Aim: To calculate the Linear Convolution of two sequences using DFT and IDFT
Theory:
An interesting property of the Discrete Fourier Transforms, is the effect it has on
convolution. Convolution of two signals in the time domain translates to a multiplication of
their Fourier transforms in the frequency domain. In this procedure, we find the discrete
Fourier transforms of the individual signals, multiply them, and apply an Inverse Fourier
Transform upon the product, to get the convolved signal in the time domain.
If x(n) and h(n) are the two sequences of length ‘l’ and ‘m’ respectively. then X(k) and
H(k) their DFT’s of length N=L+M-1.
Y(k)=x(k)h(k)
Therefore the linear convolution of two sequence is the N point IDFT of Y(k).
Ex: Find the linear convolution of x(n)={1,2} and h(n)={1,2,3} using DFT and IDFT method.
Soln: Given, x(n)={1,2}
h(n)={1,2,3}
here L = 2, M = 3
N=L+M-1 Therefore, N=4
x(n)={1,2,0,0} and h(n)={1,2,3,0}
Finding X(k) using DIT FFT algorithm:
X(k) = {3 , 1-2j , -1 , 1+2j }
Finding H(k) using DIT FFT algorithm
H(k) = {6 , -2-2j , 2 , -2+2j }
Product Y(k) is calculated as :
Y(k) = X(k)H(k)
𝑌(𝑘) = { 18 , −6 + 2j , −2 , 6 − 2j }
Finding y(n) using DIT FFT algorithm:
y(n) = { 1 , 4 , 7 , 6 }
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) 5th
Sem KSSEM, Bangalore
Dept of ECE Page | 27
MATLAB CODE
% Experiment 9 : Linear Convolution using Fourier Transforms
clear all; close all; clc;
%Accept input sequences
x1 = input('Enter Input Sequence for Signal x1(n): ');
n1 = length(x1);
x2 = input('Enter Input Sequence for Signal x2(n): ');
n2=length(x2);
N = n1+n2-1; % Length of convolved sequence
T = 1:N;
%Calculate N-point DFT and IDFT.
y1=fft(x1,N); % N-point DFT of x1
y2=fft(x2,N); % N-point DFT of x2
y3=y1.*y2; % Multiplication in time domain
y=ifft(y3,N); % N-point IDFT of y to recover result
% Plot Input and Output Sequences:
subplot(3,1,1);
stem(T,x1);
title('Input Signal x1(n)');
xlabel('n'); ylabel('x1(n)');
subplot(3,1,2);
stem(T,x2);
title('Input Signal x2(n)');
xlabel('n'); ylabel('x2(n)');
subplot(3,1,3);
stem(T,y);
title('Convolved Signal y(n) = x1(n)*x2(n)');
xlabel('n'); ylabel('y(n)');
% Display the convolved Sequence in Command Window
disp('Convolved sequence:');
disp(y);
OUTPUT
Enter Input Sequence for Signal x1(n): [1 2]
Enter Input Sequence for Signal x2(n): [1 2 3]
Convolved sequence:
1 4 7 6
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) 5th
Sem KSSEM, Bangalore
Dept of ECE Page | 28
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) 5th
Sem KSSEM, Bangalore
Dept of ECE Page | 29
PROGRAM 10
CIRCULAR CONVOLUTION USING DFT AND IDFT
Aim: To calculate the Circular Convolution of two sequences using DFT and IDFT
Theory:
Convolution in time domain corresponds to multiplication in frequency domain. To make use
of this property, we can calculate the DTFT of each of the aperiodic signals, multiply these in
the frequency domain, and find the IDFT of the product, to get the periodic convolved signal
in time domain.
Example: Find the circular convolution of x(n)={1,2,3,4} and h(n)={4,3,2} using DFT and
IDFT method.
Solution: Given two signals, x(n)={1,2,3,4} and h(n)={4,3,2}
Finding X(k) using DIT FFT algorithm
X(k) = {10 , -2-2j , -2 , -2-2j }
Finding H(k) using DIT FFT algorithm
H(k) = { 9 , 2-3j , 3 , 2+3j }
Y(k) = X(k)H(k)
Y(k) ={ 90 , 2+10j , -6 , 2-10j }
Finding y(n) using DIT FFT algorithm
y(n) = { 22 , 19 , 20 , 29 }
MATLAB CODE
% Experiment 10 - Circular Convolution using Fourier Transforms
clear all; close all; clc;
%Accept input sequences
x1 = input('Enter Input Sequence for Signal x1(n): ');
n1 = length(x1);
x2 = input('Enter Input Sequence for Signal x2(n): ');
n2=length(x2);
N=max(n1,n2); % Length of convolved sequence
T = 1:N;
x1=[x1 zeros(1,N-n1)];
x2=[x2 zeros(1,N-n2)];
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) 5th
Sem KSSEM, Bangalore
Dept of ECE Page | 30
%Calculate N-point DFT and IDFT.
y1=fft(x1,N); % N-point DFT of x1
y2=fft(x2,N); % N-point DFT of x2
y3=y1.*y2; % Multiplication in time domain
y=ifft(y3,N); % N-point IDFT of y to recover result
% Plot Input and Output Sequences:
subplot(3,1,1);
stem(T,x1);
title('Input Signal x1(n)');
xlabel('n'); ylabel('x1(n)');
subplot(3,1,2);
stem(T,x2);
title('Input Signal x2(n)');
xlabel('n'); ylabel('x2(n)');
subplot(3,1,3);
stem(T,y);
title('Convolved Signal y(n) = x1(n)*x2(n)');
xlabel('n'); ylabel('y(n)'); grid on;
% Display the convolved Sequence in Command Window
disp('Convolved sequence:');
disp(y);
OUTPUT
Enter Input Sequence for Signal x1(n): [1 2 3 4]
Enter Input Sequence for Signal x2(n): [4 3 2]
Convolved sequence:
22 19 20 29
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) 5th
Sem KSSEM, Bangalore
Dept of ECE Page | 31
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) 5th
Sem KSSEM, Bangalore
Dept of ECE Page | 32
PROGRAM 11
DESIGN AND IMPLEMENTATION OF FIR FILTER
Aim: To design and implement a FIR Filter for the given specifications.
Theory:
A linear-phase is required throughout the passband of the filter to preserve the shape of the
given signal in the passband. A causal IIR filter cannot give linear-phase characteristics and
only special types of FIR filters that exhibit center symmetry in its impulse response give the
linear-space. An FIR filter with impulse response h(n) can be obtained as follows:
h(n) = hd(n) 0≤n≤N-1
= 0 otherwise ……………….(a)
The impulse response hd(n) is truncated at n = 0, since we are interested in causal FIR Filter. It
is possible to write above equation alternatively as
h(n) = hd(n)w(n) ……………….(b)
where w(n) is said to be a rectangular window defined by
w(n) = 1 0≤n≤N-1
= 0 otherwise
Taking DTFT on both the sides of equation(b), we get
H(ω) = Hd(ω)*W(ω)
Hamming window:
The impulse response of an N-term Hamming window is defined as follows:
𝑤 𝐻𝑎𝑚(𝑛) = �
0.54 – 0.46𝑐𝑜𝑠(2п𝑛 / (𝑁 − 1)) 0 ≤ 𝑛 ≤ 𝑁 − 1
0 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
Problem: Using MATLAB design an IIR filter to meet the following specifications choosing
Hamming window:
• Window length, N = 27
• Stop band attenuation = 50dB
• Cut-off frequency = 100 Hz
• Sampling frequency = 1000 Hz
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) 5th
Sem KSSEM, Bangalore
Dept of ECE Page | 33
MATLAB CODE
% Experiment 11 : Designing a FIR Filter (Hamming Window)
close all; clear all; clc;
% Accept Filter Parameters from User
N = input('Enter the window length N : ');
fc = input('Enter the cut-off frequency fc (Hz) : ');
Fs = input('Enter the sampling frequency Fs (Hz) : ');
Wc = 2*fc/ Fs; %Nyquist Frequency
Wh = hamming(N); %Create a N-point symmetric Hamming
window
% Generate a FIR filter based on Hamming Window created
b = fir1(N-1, Wc ,Wh);
% Calculate Frequency Response of Filter designed.
% h - Frequency Response values w = Frequencies
[h,w] = freqz(b,1,256);
mag = 20*log10(abs(h)); %Magnitude of Response
% Display Values
disp('Hamming Window Co-efficients : ');
disp(Wh);
disp('Unit Sample Response of FIR Filter h(n) : ');
disp(b);
% Plot Frequency response of Butterworth Filter.
freqz(b);
title('Hamming Filter Frequency Response');
OUTPUT
Enter the window length N : 27
Enter the cut-off frequency fc (Hz) : 100
Enter the sampling frequency Fs (Hz) : 1000
Hamming Window Co-efficients :
0.0800
0.0934
0.1327
0.1957
0.2787
0.3769
0.4846
0.5954
0.7031
0.8013
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) 5th
Sem KSSEM, Bangalore
Dept of ECE Page | 34
0.8843
0.9473
0.9866
1.0000
0.9866
0.9473
0.8843
0.8013
0.7031
0.5954
0.4846
0.3769
0.2787
0.1957
0.1327
0.0934
0.0800
Unit Sample Response of FIR Filter h(n) :
Columns 1 through 7
0.0019 0.0023 0.0022 -0.0000 -0.0058 -0.0142 -0.0209
Columns 8 through 14
-0.0185 0.0000 0.0374 0.0890 0.1429 0.1840 0.1994
Columns 15 through 21
0.1840 0.1429 0.0890 0.0374 0.0000 -0.0185 -0.0209
Columns 22 through 27
-0.0142 -0.0058 -0.0000 0.0022 0.0023 0.0019
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) 5th
Sem KSSEM, Bangalore
Dept of ECE Page | 35
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) 5th
Sem KSSEM, Bangalore
Dept of ECE Page | 36
PROGRAM 12
DESIGN AND IMPLEMENTATION OF IIR FILTER
Aim: To design and implement a IIR Filter for the given specifications.
Theory:
A desired frequency response is approximated by a transfer function expressed as a ratio of
polynomials. This type of transfer function yields an impulse response of infinite duration.
Therefore, the analog filters are commonly referred to as infinite impulse response (IIR)
filters.
The main classes of analog filters are -
1.Butterworth Filter.
2.Chebyshev Filter.
These filters differ in the nature of their magnitude responses as well as in their design and
implementation.
BUTTERWORTH FILTERS:
Butterworth filters have very smooth passband, which we pay for with a relatively wide
transition region. A Butterworth filter is characterized by its magnitude frequency response,
| 𝐻(𝑗𝛺) | = 1 / [1 + (𝛺/𝛺𝑐)2𝑁]1/2
where N is the order of the filter and Ωc is defined as the cutoff frequency where the filter
magnitude is 1/√2 times the dc gain (Ω=0)
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) 5th
Sem KSSEM, Bangalore
Dept of ECE Page | 37
Butterworth filter tables
N=1; (s + 1)
N=2; (s2
+0.5 s +1)
N=3; (s2
+s+1)(s+1)
N=4; (s2
+0.76536s+1)(s2
+1.864776s+2)
N=5; (s+1)( s2
+0.6180s+1)( s2
+1.6180s+1)
CHEBYSHEV FILTERS:
Chebyshev filters are equiripple in either the passband or stopband. Hence the magnitude
response oscillates between the permitted minimum and maximum values in the band a
number of times depending upon the order of filters. There are two types of chebyshev filters.
The chebyshev I filter is equiripple in passband and monotonic in the stopband, whereas
Chebyshev II is just the opposite.
The Chebyshev low-pass filter has a magnitude response given by
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) 5th
Sem KSSEM, Bangalore
Dept of ECE Page | 38
PROBLEM 1: BUTTERWORTH FILTER:
Using MATLAB design an IIR filter with passband edge frequency 1500Hz and stop band
edge at 2000Hz for a sampling frequency of 8000Hz, variation of gain within pass band 1db
and stopband attenuation of 15 db. Use Butterworth prototype design and Bilinear
Transformation.
MATLAB CODE :
% Experiment 12 : Design of IIR Filter (Butterworth Filter)
clear all; close all; clc;
% Accept Input Parameters from user
Rp = input('Enter Passband Attenuation in dB : ');
Rs = input('Enter Stopband Attenuation in dB : ');
fp = input('Enter Passband Frequency in Hz : ');
fs = input('Enter Stopband Frequency in Hz : ');
Fs = input('Enter Sampling Frequency in Hz : ');
% Calculate Sampled Frequency values
Wp=2* fp / Fs ;
Ws=2* fs / Fs ;
% Calculate Butterworth filter order and cutoff frequency:
% N = Minimum order of Filter Wn = Cutoff Frequencies
[N,Wn] = buttord(Wp,Ws,Rp,Rs);
% Butterworth Filter Design (z = zeros p = poles)
[z,p] = butter(N,Wn);
% Display Filter parameters :
disp('Order of Butterworth Filter : ');
disp(N);
disp('Butterworth Window Cutoff Frequency : ');
disp(Wn);
% Plot Frequency Response of Filter
freqz(z,p);
title('Butterworth frequency response');
OUTPUT:
Enter Passband Attenuation in dB : 1
Enter Stopband Attenuation in dB : 15
Enter Passband Frequency in Hz : 1500
Enter Stopband Frequency in Hz : 2000
Enter Sampling Frequency in Hz : 8000
Order of Butterworth Filter :
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) 5th
Sem KSSEM, Bangalore
Dept of ECE Page | 39
6
Butterworth Window Co-efficient :
0.4104
PROBLEM 2: CHEBYSHEV FILTER:
Using MATLAB design an IIR filter with passband edge frequency 1500Hz and stop band
edge at 2000Hz for a sampling frequency of 8000Hz, variation of gain within pass band 1 db
and stopband attenuation of 15 db. Use Chebyshev prototype design and Bilinear
Transformation.
DESIGN:
W1 = (2*pi* F1 )/ Fs = 2*pi*100)/4000 = 0.05Π rad
W2 = (2*pi* F2 )/ Fs = 2*pi*500)/4000 =0.25Π rad
Prewarp:
T=1sec
Ω1 = 2/T tan (w1/2) = 0.157 rad/sec
Ω2 = 2/T tan (w2/2) = 0.828 rad/sec
Order:
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) 5th
Sem KSSEM, Bangalore
Dept of ECE Page | 40
έ =�10−
𝐴𝑝
10 − 1
έ = 0.765
A= 10-As/20
, A = 1020/20
, A=10
g= (A2 - 1) / έ , g = 13.01
Ωr= Ω2 / Ω1 Ωr=0.828/0.157 = 5.27 radsec
n = log10 �𝐠 + �(𝐠𝟐 − 𝟏) � / log10{Ωr + √(𝜴 𝒓
𝟐
– 𝟏) }
n= 1.388
Therefore n= 2.
Cut-off Frequency:
Ωc = Ωp = Ω1 = 0.157 radsec
Normalized Transfer Function:
H(s)=[bo / 1+ έ2
] / [ s2
+b1s+b0]
= 0.505/[ s2
+0.8s+0.036]
Denormalized Transfer Function:
H(s)= Hn(s) |s-s/Ωc H(s)= Hn(s) |s-s/0.157
H(s) = 0.0125 / [s2
+0.125s+0.057]
Apply BLT:
H(Z) = H(s)|s=(2/T)[(1-z-1)/(1+z-1)]
H(Z) = 0.0125+0.025Z-1
+ 0.0125 Z-2
4.2769-7.96Z-1
+ 3.76Z-2
H(Z) = 0.0029+0.0052Z-1
+ 0.0029 Z-2
1-1.86Z-1
+ 0.88Z-2
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) 5th
Sem KSSEM, Bangalore
Dept of ECE Page | 41
MATLAB CODE:
% Experiment 12B : Design of IIR Filter (Chebyshev Filter)
clear all; close all; clc;
% Accept Input Parameters from user
Rp = input('Enter Passband Attenuation in dB : ');
Rs = input('Enter Stopband Attenuation in dB : ');
fp = input('Enter Passband Frequency in Hz : ');
fs = input('Enter Stopband Frequency in Hz : ');
Fs = input('Enter Sampling Frequency in Hz : ');
% Calculate Sampled Frequency values
Wp=2* fp / Fs ;
Ws=2* fs / Fs ;
% Calculate Chebyshev filter order and cutoff Frequency:
% N = Minimum order of Filter Wn = Cutoff Frequencies
[N,Wn]=cheb1ord(Wp,Ws,Rp,Rs);
% Chebyshev Filter Design (z = zeros p = poles)
[z,p]=cheby1(N,Rp,Wn);
% Display Filter parameters :
disp('Order of Chebyshev Filter : ');
disp(N);
disp('Chebyshev Window Cutoff Frequency : ');
disp(Wn);
% Plot Frequency Response of Filter :
freqz(z,p);
title('Chebyshev Frequency response');
OUTPUT:
Enter Passband Attenuation in dB : 1
Enter Stopband Attenuation in dB : 15
Enter Passband Frequency in Hz : 1500
Enter Stopband Frequency in Hz : 2000
Enter Sampling Frequency in Hz : 8000
Order of Chebyshev Filter :
4
Chebyshev Window Cutoff Frequency :
0.3750
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) 5th
Sem KSSEM, Bangalore
Dept of ECE Page | 42
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) 5th
Sem KSSEM, Bangalore
Dept of ECE Page | 43
PART B:
Exercises using the
DSP Kit
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) V Semester KSSEM, Bangalore
Dept of ECE Page | 44
TMS320C6748 DSP
BOARD
Package content:
The C6748 DSP Experimenter Kit packaged for Universities (TMDSEXPL138-UNV)
provides everything academics need to get started with teaching and projects using the TI
TMS320C6000 DSP. The TI TMS320C6000 family of DSPs is popular for use in Real-time DSP
coursesThe Experimenter Kit for Universities is a low-cost, flexible development platform for the
OMAP-L138 which is a low-power dual core processor based on C6748 DSP plus an ARM926EJ-S
32-bit RISC MPU.
The C6748 DSP kit has a TMS320C6748 DSP onboard that allows full-speed verification of
code with Code Composer Studio. The C6748 DSP kit provides:
A USB Interface
128MB DDRAM and ROM
An analog interface circuit for Data conversion
(AIC) An I/O port
Embedded JTAG emulation support
Connectors on the C6748 DSP kit provide DSP external memory interface (EMIF) and
peripheral signals that enable its functionality to be expanded with custom or third party daughter
boards.
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) V Semester KSSEM, Bangalore
Dept of ECE Page | 45
The C6748 DSP kit includes a stereo codec. This analog interface circuit (AIC) has the
following characteristics:
High-Performance Stereo Codec
• Interfaces directly to digital or analog microphones
• Supports 8-96 ksps sampling rates
• High SNR (100-102dB DAC, 92dB ADC)
• Integrated PLL supporting a wide range of audio clocks
• Low-power headphone, speaker and playback modes for portable systems
• Programmable digital audio effectsinclude 3D sound, bass, treble, EQ and de-emphasis
Software Control Via TI McASP-Compatible Multiprotocol Serial Port.Glueless
Interface to TI McASPs.
Audio-Data Input/Output Via TI McASP-Compatible Programmable Audio Interface
16/20/24/32-Bit Word Lengths.
The C6748DSP kit has the following features:
The 6748 DSP KIT kit is a low-cost standalone development platform that enables customers
to evaluate and develop applications for the TI C67XX DSP family. The DSP KIT also serves
as a hardware reference design for the TMS320C6748 DSP. Schematics, logic equations and
application notes are available to ease hardware development and reduce time to market.
An on-board AIC3106 codec allows the DSP to transmit and receive analog signals.
McASP is used for the codec control interface and for data. Analog audio I/O is done through
two 3.5mm audio jacks that correspond to line input, and line. The analog output is driven to
the line out .McASP1 can be re-routed to the expansion connectors in software.
The DSP KIT includes 2 LEDs and 8 DIP switches as a simple way to provide the user with
interactive feedback.
An included 5V external power supply is used to power the board. On-board voltage
regulators provide the 1.26V DSP core voltage, 3.3V digital and 3.3V analog voltages. A
voltage supervisor monitors the internally generated voltage, and will hold the board in reset
until the supplies are within operating specifications and the reset button is released.
Code Composer communicates with the DSP KIT through an embedded JTAG emulator with a
USB host interface. The DSP KIT can also be used with an external emulator through the
external JTAG connector.
TMS320C6748 DSP Features
 Highest-Performance Floating-Point Digital Signal Processor (DSP):
 Eight 32-Bit Instructions/Cycle
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) V Semester KSSEM, Bangalore
Dept of ECE Page | 46
 32/64-Bit Data Word
 375/456-MHz C674x Fixed/Floating-Point
 Up to 3648/2746 C674x MIPS/MFLOPS
 Rich Peripheral Set, Optimized for Audio
 Highly Optimized C/C++ Compiler
 Extended Temperature Devices Available
 Advanced Very Long Instruction Word (VLIW) TMS320C67x™ DSP Core
 Eight Independent Functional Units:
 Two ALUs (Fixed-Point)
 Four ALUs (Floating- and Fixed-Point)
 Two Multipliers (Floating- and Fixed-Point)
 Load-Store Architecture With 64 32-Bit General-Purpose Registers
 Instruction Packing Reduces Code Size
 All Instructions Conditional
 Instruction Set Features
 Native Instructions for IEEE 754
 Single- and Double-Precision
 Byte-Addressable (8-, 16-, 32-Bit Data)
 8-Bit Overflow Protection
 Saturation; Bit-Field Extract, Set, Clear; Bit-Counting; Normalization
 67x cache memory.
 32K-Byte L1P Program Cache (Direct-Mapped)
 32K-Byte L1D Data Cache (2-Way)
 256K-Byte L2 unified Memory RAMCache.
 Real-Time Clock With 32 KHz Oscillator and Separate Power Rail.
 Three 64-Bit General-Purpose Timers
 Integrated Digital Audio Interface Transmitter (DIT) Supports:
 S/PDIF, IEC60958-1, AES-3, CP-430 Formats
 Up to 16 transmit pins
 Enhanced Channel Status/User Data
 Extensive Error Checking and Recovery
 Two Inter-Integrated Circuit Bus (I
2
C Bus™) .
 3 64-Bit General-Purpose Timers (each configurable as 2 32-bit timers)
 Flexible Phase-Locked-Loop (PLL) Based Clock Generator Module
 IEEE-1149.1 (JTAG ) Boundary-Scan-Compatible
 3.3-V I/Os, 1.2 -V Internal (GDP & PYP)
 3.3-V I/Os, 1.4-V Internal (GDP)(300 MHz only)
 LCD Controller
 Two Serial Peripheral Interfaces (SPI) Each With Multiple Chip-Selects
 Two Multimedia Card (MMC)/Secure Digital (SD) Card Interface with Secure Data I/O
(SDIO) Interfaces
 One Multichannel Audio Serial Port.
 Two Multichannel Buffered Serial Ports
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) V Semester KSSEM, Bangalore
Dept of ECE Page | 47
General Procedure to work on Code Composer Studio V4 for non-real
time projects
1. Launch ccs
Launch the CCS v4 icon from the Desktop or goto All Programs ->Texas Instruments -
>CCSv4
2.
Choose the location for the workspace, where your project will be saved.
3.
Click the CCS icon from the welcome page to go the workbench, it is marked in the below
picture.
DSPLab-ECEDepartment,KSSEM
Dept of ECE Page | 48
*
4. Configure ccs to your target
A. From the Target menu select New target Configuration
Target -> New target Configuration.
It will open a window like given below.
Specify any arbitrary target name. For Eg., 6748config.ccxml (Extension should be
.ccxml).. Click Finish then you will get configuration window for the created target.
B.
1. Select the Connection: Texas instruments XDS100v1 USB Emulator
2. Select the Device: TMS320C6748. To make search easier type 6748 in device block.
Check the box
TMS320C674
8 and finally
Click Save.
DSPLab-ECEDepartment,KSSEM
Dept of ECE Page | 49
C. Next goto Advanced tab give the suitable Gel file path as shown below.
Follow the path.
“C:6748supportc6748.gel”
D.
Go to view option and select the Target Configuration:
View->Target Configuration.
A wizard will open in the workspace expand the User Defined folder and you can find your
target, Right click on 6748config.ccxml and select the Launch Selected Configuration.
E. Connect CCS to the target
Goto Target -> Connect Target
Now our target is successfully configured and connected.
In future we no need to repeat these steps. If we are working with the same hardware we
can just open the already configured target and launch the selected configuration and
connect it.
DSPLab-ECEDepartment,KSSEM
Dept of ECE Page | 50
5. Creating the New Project
Step P1:
Change the Perspective Debug to C/C++ from the right corner of the CCS
Step P2:
Go to File  New  CCS Project.
Step P3:
Specify the name of the project in the
space provided .and Click Next
Eg., Project Name: Hello World
DSPLab-ECEDepartment,KSSEM
Dept of ECE Page | 51
Select the project type
Project Type: C6000
Click Next
*However our target is based on C6000 family, Based on the family we need to select the
Project
Type.
Set the project settings window as shown below.
Click finish
DSPLab-ECEDepartment,KSSEM
Dept of ECE Page | 52
6. To write the program select one new file.
A.Go to File  New  Source File.
B. Specify the arbitrary source file name. It should be in the source folder (current project
name.).
Note:
Extension of the source file must be the language what we preferred to write the code.
Eg:
For c-> .c
C++ -> .cpp
Assembly -> .asm
C.Type your C – Code
DSPLab-ECEDepartment,KSSEM
Dept of ECE Page | 53
7. BUILD
Build the program to check your code
Have any errors and
warnings. Go to
Project  Build active project.
If your code doesn‟t have any errors and warnings, a message will be printed in the console
window that
“Build Complete for the project”
Problems window display errors or warnings, if any.
DSPLab-ECEDepartment,KSSEM
Dept of ECE Page | 54
8. DEBUG
After successful Build, Debug your code. During this step ccs will connect to target and it
will
load program on to target.
Goto Target  Debug Active project.
During debug ccs will display following error message.
Now press reset button on the 6748 hardware , then click on retry.
Once you click on retry ccs will load program on to processor and then ccs will guide
us to debug mode, if it is not done automatically.
Change the Perspective C/C++ to Debug
from the right corner of the CCS.
DSPLab-ECEDepartment,KSSEM
Dept of ECE Page | 55
9.RUN
Now you can run the code, by selecting the option run from the dialog box else you can
Go to Target  Run
Once you run the program the output will be printed in the Console
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) V Semester KSSEM, Bangalore
Dept of ECE Page | 56
PROGRAM 1
LINEAR CONVOLUTION OF TWO GIVEN SEQUENCES
Aim: To write the C code to perform Linear Convolution upon two given discrete time
signals.
C Code:
/* PROGRAM TO IMPLEMENT LINEAR CONVOLUTION */
#include<stdio.h>
int y[20];
main()
{ int m=6; /*Length of i/p samples sequence*/
int n=6; /*Length of impulse response Coefficients*/
int i=0,j;
/*Input Signal Samples*/
int x[15]={1,2,3,4,5,6,0,0,0,0,0,0};
/*Impulse Response Coefficients*/
int h[15]={1,2,3,4,5,6,0,0,0,0,0,0};
/*Calculate Values*/
for(i=0;i<m+n-1;i++)
{
y[i]=0;
for(j=0;j<=i;j++)
y[i]+=x[j]*h[i-j];
}
/* Display Values*/
printf("Sequence 1: n");
for(i=0;i<m;i++)
printf("%dt",x[i]);
printf("nSequence 2: n");
for(i=0;i<n;i++)
printf("%dt",h[i]);
printf("nConvolved Sequence: n");
for(i=0;i<m+n-1;i++)
printf("%dt",y[i]);
}
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) V Semester KSSEM, Bangalore
Dept of ECE Page | 57
OUTPUT:
Sequence 1:
1 2 3 4 5 6
Sequence 2:
1 2 3 4 5 6
Convolved Sequence:
1 4 10 20 35 56 70 76 73 60 36
Procedure:
1. Open Code Composer Studio v4.
2. Connect the target (step 4).
3. Create new project with name as sine wave (step 5).
4. Create new source file and type the code linear.c and save it.(step 6)
5. Now perform steps 7, 8and 9.Once you run the program you can watch convolution
result in the console window.
6. To view the values in graph
a. Go to Tools  Graph  Single Time
7. Set the Graph Properties as shown
Buffer size : 11
DSP Data Type : 16-Bit Unsigned Int
Start Address: y
Display Data Size : 11
8. Click : Ok
9. Note down the output waveform.
NOTE : Follow the same procedure for the rest of the experiments.
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) V Semester KSSEM, Bangalore
Dept of ECE Page | 58
PROGRAM 2:
CIRCULAR CONVOLUTION OF TWO GIVEN SEQUENCES
Aim: To write the C code to perform Circular Convolution upon two given discrete time
signals.
C Code:
/* PROGRAM TO IMPLEMENT CIRCULAR CONVOLUTION */
#include<stdio.h>
int m,n,x[30],h[30],y[30],i,j,temp[30],k,x2[30],a[30];
void main()
{
printf("Enter the length of the first sequencen");
scanf("%d",&m);
printf("nEnter the length of the second sequencen");
scanf("%d",&n);
printf("nEnter the first sequencen");
for(i=0;i<m;i++)
scanf("%d",&x[i]);
printf("nEnter the second sequencen");
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;
}
/*Initialize Array of Zeros*/
for(i=m;i<n;i++)
x[i]=0;
m=n;
}
/* Convert linear sequence to circular sequence*/
y[0]=0;
a[0]=h[0];
for(j=1;j<n;j++) /* folding h(n) to h(-n) */
a[j]=h[n-j];
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) V Semester KSSEM, Bangalore
Dept of ECE Page | 59
/*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("nConvolved Sequence:n");
for(i=0;i<n;i++)
printf("%d t",y[i]);
}
OUTPUT:
Enter the length of the first sequence
4
Enter the length of the second sequence
4
Enter the first sequence
2 1 2 1
Enter the second sequence
1 2 3 4
Convolved Sequence:
14 16 14 16
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) V Semester KSSEM, Bangalore
Dept of ECE Page | 60
PROGRAM 3:
COMPUTATION OF N- POINT DFT OF A GIVEN SEQUENCE
Aim: Computation of N point DFT of a given sequence.
C Code:
#include<stdio.h>
#include<math.h>
int N,k,n,i;
float pi=3.1416,sumre=0, sumim=0,out_real[8]={0.0},
out_imag[8]={0.0};
int x[32];
void main(void)
{
printf("Enter the length of the sequencen");
scanf("%d",&N);
printf("nEnter the sequencen");
for(i=0;i<N;i++)
scanf("%d",&x[i]);
for(k=0;k<N;k++)
{
sumre=0;
sumim=0;
for(n=0;n<N;n++)
{
sumre=sumre+x[n]* cos(2*pi*k*n/N);
sumim=sumim-x[n]* sin(2*pi*k*n/N);
}
out_real[k]=sumre;
out_imag[k]=sumim;
printf("DFT of the Sequence :n");
printf("X([%d])=t%ft+t%fin",k,out_real[k],out_imag[k]);
}
}
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) V Semester KSSEM, Bangalore
Dept of ECE Page | 61
OUTPUT:
Enter the length of the sequence
4
Enter the sequence
0 1 2 3
DFT of the Sequence
6.0
-2.0 + 2.0i
-2.0 - 0.0i
-2.0 - 2.0i
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) V Semester KSSEM, Bangalore
Dept of ECE Page | 62
PROGRAM 4:
IMPULSE RESPONSE OF FIRST ORDER AND SECOND ORDER SYSTEM
Aim: To Calculate the Impulse Response of the First Order and Second Order Systems.
1. First Order System:
C Code:
#include <stdio.h>
#define Order 1 /*First Order Filter*/
#define Len 10 /*Length of Impulse Response*/
float y[Len] = {0,0,0}, sum;
main()
{
int j,k;
float b[Order+1]={1, 3}; /*Input Coefficients*/
float a[Order+1]={1, 0.2}; /*Output Coefficients*/
printf("Impulse Response Coefficients:n");
for(j=0;j<Len;j++)
{
sum = 0;
for (k=1;k<=Order;k++)
{
if ((j-k)>=0)
sum=sum+(b[k]*y[j-k]);
}
if(j<=Order)
y[j]=a[j]-sum;
else
y[j]=-sum;
printf("Response [%d] = %fn",j,y[j]);
}
}
OUTPUT:
Impulse Response Coefficients:
Response [0] = 1.000000
Response [1] = -2.800000
Response [2] = 8.400000
Response [3] = -25.199999
Response [4] = 75.599998
Response [5] = -226.799988
Response [6] = 680.399963
Response [7] = -2041.199951
Response [8] = 6123.599609
Response [9] = -18370.798828
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) V Semester KSSEM, Bangalore
Dept of ECE Page | 63
2. Second Order System:
C Code:
#include <stdio.h>
#define Order 2 /*Second Order Filter*/
#define Len 10 /*Length of Impulse Response*/
float y[Len] = {0,0,0}, sum;
main()
{
int j,k;
float b[Order+1]={1, 3, -0.12}; /*Input Coefficients*/
float a[Order+1]={1, 0.2, -1.5}; /*Output Coefficients*/
printf("Impulse Response Coefficients:n");
for(j=0;j<Len;j++)
{
sum = 0;
for (k=1;k<=Order;k++)
{
if ((j-k)>=0)
sum=sum+(b[k]*y[j-k]);
}
if(j<=Order)
y[j]=a[j]-sum;
else
y[j]=-sum;
printf("Response [%d] = %fn",j,y[j]);
}
}
OUTPUT:
Impulse Response Coefficients:
Response [0] = 1.000000
Response [1] = -2.800000
Response [2] = 7.020000
Response [3] = -21.396000
Response [4] = 65.030403
Response [5] = -197.658722
Response [6] = 600.779785
Response [7] = -1826.058350
Response [8] = 5550.268555
Response [9] = -16869.933594
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) V Semester KSSEM, Bangalore
Dept of ECE Page | 64
SAMPLE VIVA QUESTIONS:
1. What is sampling theorem?
2. What do you mean by process of reconstruction?
3. What are techniques of reconstructions?
4. What do you mean Aliasing? What is the condition to avoid aliasing for sampling?
5. Write the conditions of sampling.
6. How many types of sampling there?
7. Explain the statement- t= 0:0.000005:0.05
8. In the above example what does colon (:) and semicolon (;) denote?
9. What is a) Undersampling b) Nyquist Plot c) Oversampling.
10. Write the MATLAB program for Oversampling.
11. What is the use of command ‘legend’?
12. Write the difference between built in function, plot and stem describe the function.
13. What is the function of built in function and subplot?
14. What is linear convolution?
15. Explain how convolution syntax built in function works.
16. How to calculate the beginning and end of the sequence for the two sided
controlled output?
17. What is the total output length of linear convolution sum.
18. What is an LTI system?
19. Describe impulse response of a function.
20. What is the difference between convolution and filter?
21. Where to use command filter or impz, and what is the difference between these
two?
22. What is the use of function command ‘deconv’?
23. What is the difference between linear and circular convolution?
24. What do you mean by statement subplot (3,3,1).
25. What do you mean by command “mod” and where it is used?
26. What do you mean by Autocorrelation and Crosscorrelation sequences?
27. What is the difference between Autocorrelatio and Crsscorrelation.
28. List all the properties of autocorrelation and Crosscorrelaion sequence.
29. Where we use the inbuilt function ‘xcorr’ and what is the purpose of using this
function?
30. How to calculate output of DFT using MATLAB?
31. What do you mean by filtic command, explain.
32. How to calculate output length of the linear and circular convolution.
33. What do you mean by built in function ‘fliplr’ and where we need to use this.
34. What is steady state response?
35. Which built in function is used to solve a given difference equation?
36. Explain the concept of difference equation.
37. Where DFT is used?
DSPLab-ECEDepartment,KSSEM
DSP Laboratory (10ECL57) V Semester KSSEM, Bangalore
Dept of ECE Page | 65
38. What is the difference between DFT and IDFT?
39. What do you mean by built in function ‘abs’ and where it is used?
40. What do you mean by phase spectrum and magnitude spectrum/ give comparison.
41. How to compute maximum length N for a circular convolution using DFT and
IDFT.(what is command).
42. Explain the statement- y=x1.*x2
43. What is FIR and IIR filter define, and distinguish between these two.
44. What is filter?
45. What is window method? How you will design an FIR filter using window
method.
46. What are low-pass and band-pass filter and what is the difference between these
two?
47. Explain the command : N = ceil(6.6 *pi/tb)
48. Write down commonly used window function characteristics.
49. What is the MATLAB command for Hamming window? Explain.
50. What do you mea by cut-off frequency?
51. What do you mean by command butter, cheby1?
52. Explain the command in detail- [N,wc]=buttord(2*fp/fs,2*fstp/fs,rp,As)
53. What is CCS? Explain in detail to execute a program using CCS.
54. Why do we need of CCS?
55. How to execute a program using ‘dsk’ and ‘simulator’?
56. Which IC is used in CCS? Explain the dsk, dsp kit.
57. What do you mean by noise?
58. Explain the program for linear convolution for your given sequence.
59. Why we are using command ‘float’ in CCS programs.
60. Where we use ‘float’ and where we use ‘int’?
61. Explain the command- i= (n-k) % N
62. Explain the entire CCS program in step by step of execution.
63. What is MATLAB? What does it stand for?
DSPLab-ECEDepartment,KSSEM

Mais conteúdo relacionado

Mais procurados

digital signal-processing-lab-manual
digital signal-processing-lab-manualdigital signal-processing-lab-manual
digital signal-processing-lab-manualAhmed Alshomi
 
Discrete Fourier Transform
Discrete Fourier TransformDiscrete Fourier Transform
Discrete Fourier TransformAbhishek Choksi
 
DSP_2018_FOEHU - Lec 06 - FIR Filter Design
DSP_2018_FOEHU - Lec 06 - FIR Filter DesignDSP_2018_FOEHU - Lec 06 - FIR Filter Design
DSP_2018_FOEHU - Lec 06 - FIR Filter DesignAmr E. Mohamed
 
DSP_2018_FOEHU - Lec 02 - Sampling of Continuous Time Signals
DSP_2018_FOEHU - Lec 02 - Sampling of Continuous Time SignalsDSP_2018_FOEHU - Lec 02 - Sampling of Continuous Time Signals
DSP_2018_FOEHU - Lec 02 - Sampling of Continuous Time SignalsAmr E. Mohamed
 
FILTER DESIGN
FILTER DESIGNFILTER DESIGN
FILTER DESIGNnaimish12
 
Basics of Digital Filters
Basics of Digital FiltersBasics of Digital Filters
Basics of Digital Filtersop205
 
DSP_2018_FOEHU - Lec 03 - Discrete-Time Signals and Systems
DSP_2018_FOEHU - Lec 03 - Discrete-Time Signals and SystemsDSP_2018_FOEHU - Lec 03 - Discrete-Time Signals and Systems
DSP_2018_FOEHU - Lec 03 - Discrete-Time Signals and SystemsAmr E. Mohamed
 
DSP_2018_FOEHU - Lec 1 - Introduction to Digital Signal Processing
DSP_2018_FOEHU - Lec 1 - Introduction to Digital Signal ProcessingDSP_2018_FOEHU - Lec 1 - Introduction to Digital Signal Processing
DSP_2018_FOEHU - Lec 1 - Introduction to Digital Signal ProcessingAmr E. Mohamed
 
Fir filter design using windows
Fir filter design using windowsFir filter design using windows
Fir filter design using windowsSarang Joshi
 
DIGITAL SIGNAL PROCESSING: Sampling and Reconstruction on MATLAB
DIGITAL SIGNAL PROCESSING: Sampling and Reconstruction on MATLABDIGITAL SIGNAL PROCESSING: Sampling and Reconstruction on MATLAB
DIGITAL SIGNAL PROCESSING: Sampling and Reconstruction on MATLABMartin Wachiye Wafula
 
Dsp 2018 foehu - lec 10 - multi-rate digital signal processing
Dsp 2018 foehu - lec 10 - multi-rate digital signal processingDsp 2018 foehu - lec 10 - multi-rate digital signal processing
Dsp 2018 foehu - lec 10 - multi-rate digital signal processingAmr E. Mohamed
 
DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)
DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)
DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)Amr E. Mohamed
 
Classification of signals
Classification of signalsClassification of signals
Classification of signalschitra raju
 
Discrete fourier transform
Discrete fourier transformDiscrete fourier transform
Discrete fourier transformMOHAMMAD AKRAM
 
Design of FIR filters
Design of FIR filtersDesign of FIR filters
Design of FIR filtersop205
 

Mais procurados (20)

digital signal-processing-lab-manual
digital signal-processing-lab-manualdigital signal-processing-lab-manual
digital signal-processing-lab-manual
 
Sampling theorem
Sampling theoremSampling theorem
Sampling theorem
 
Discrete Fourier Transform
Discrete Fourier TransformDiscrete Fourier Transform
Discrete Fourier Transform
 
Z transfrm ppt
Z transfrm pptZ transfrm ppt
Z transfrm ppt
 
DSP_2018_FOEHU - Lec 06 - FIR Filter Design
DSP_2018_FOEHU - Lec 06 - FIR Filter DesignDSP_2018_FOEHU - Lec 06 - FIR Filter Design
DSP_2018_FOEHU - Lec 06 - FIR Filter Design
 
DSP_2018_FOEHU - Lec 02 - Sampling of Continuous Time Signals
DSP_2018_FOEHU - Lec 02 - Sampling of Continuous Time SignalsDSP_2018_FOEHU - Lec 02 - Sampling of Continuous Time Signals
DSP_2018_FOEHU - Lec 02 - Sampling of Continuous Time Signals
 
FILTER DESIGN
FILTER DESIGNFILTER DESIGN
FILTER DESIGN
 
Basics of Digital Filters
Basics of Digital FiltersBasics of Digital Filters
Basics of Digital Filters
 
DSP_2018_FOEHU - Lec 03 - Discrete-Time Signals and Systems
DSP_2018_FOEHU - Lec 03 - Discrete-Time Signals and SystemsDSP_2018_FOEHU - Lec 03 - Discrete-Time Signals and Systems
DSP_2018_FOEHU - Lec 03 - Discrete-Time Signals and Systems
 
DSP_2018_FOEHU - Lec 1 - Introduction to Digital Signal Processing
DSP_2018_FOEHU - Lec 1 - Introduction to Digital Signal ProcessingDSP_2018_FOEHU - Lec 1 - Introduction to Digital Signal Processing
DSP_2018_FOEHU - Lec 1 - Introduction to Digital Signal Processing
 
Fir filter design using windows
Fir filter design using windowsFir filter design using windows
Fir filter design using windows
 
DIGITAL SIGNAL PROCESSING: Sampling and Reconstruction on MATLAB
DIGITAL SIGNAL PROCESSING: Sampling and Reconstruction on MATLABDIGITAL SIGNAL PROCESSING: Sampling and Reconstruction on MATLAB
DIGITAL SIGNAL PROCESSING: Sampling and Reconstruction on MATLAB
 
Design of Filters PPT
Design of Filters PPTDesign of Filters PPT
Design of Filters PPT
 
Dsp 2018 foehu - lec 10 - multi-rate digital signal processing
Dsp 2018 foehu - lec 10 - multi-rate digital signal processingDsp 2018 foehu - lec 10 - multi-rate digital signal processing
Dsp 2018 foehu - lec 10 - multi-rate digital signal processing
 
Dif fft
Dif fftDif fft
Dif fft
 
DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)
DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)
DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)
 
Classification of signals
Classification of signalsClassification of signals
Classification of signals
 
Discrete fourier transform
Discrete fourier transformDiscrete fourier transform
Discrete fourier transform
 
Chapter 4
Chapter 4Chapter 4
Chapter 4
 
Design of FIR filters
Design of FIR filtersDesign of FIR filters
Design of FIR filters
 

Destaque

Digital Signal Processing Lab Manual ECE students
Digital Signal Processing Lab Manual ECE studentsDigital Signal Processing Lab Manual ECE students
Digital Signal Processing Lab Manual ECE studentsUR11EC098
 
Dsp manual completed2
Dsp manual completed2Dsp manual completed2
Dsp manual completed2bilawalali74
 
Signal Prosessing Lab Mannual
Signal Prosessing Lab Mannual Signal Prosessing Lab Mannual
Signal Prosessing Lab Mannual Jitendra Jangid
 
Digital signal processing (2nd ed) (mitra) solution manual
Digital signal processing (2nd ed) (mitra) solution manualDigital signal processing (2nd ed) (mitra) solution manual
Digital signal processing (2nd ed) (mitra) solution manualRamesh Sundar
 
MATLAB Programs For Beginners. | Abhi Sharma
MATLAB Programs For Beginners. | Abhi SharmaMATLAB Programs For Beginners. | Abhi Sharma
MATLAB Programs For Beginners. | Abhi SharmaAbee Sharma
 
Linear Convolution using Matlab Code
Linear Convolution  using Matlab CodeLinear Convolution  using Matlab Code
Linear Convolution using Matlab CodeBharti Airtel Ltd.
 
Digital signal processing computer based approach - sanjit k. mitra (2nd ed)
Digital signal processing   computer based approach - sanjit k. mitra (2nd ed)Digital signal processing   computer based approach - sanjit k. mitra (2nd ed)
Digital signal processing computer based approach - sanjit k. mitra (2nd ed)Surbhi Maheshwari
 
Butterworth filter design
Butterworth filter designButterworth filter design
Butterworth filter designSushant Shankar
 
DIGITAL SIGNAL PROCESSING
DIGITAL SIGNAL PROCESSINGDIGITAL SIGNAL PROCESSING
DIGITAL SIGNAL PROCESSINGSnehal Hedau
 
Application of code composer studio in digital signal processing
Application of code composer studio in digital signal processingApplication of code composer studio in digital signal processing
Application of code composer studio in digital signal processingIAEME Publication
 
Introduction to Signal Processing Orfanidis [Solution Manual]
Introduction to Signal Processing Orfanidis [Solution Manual]Introduction to Signal Processing Orfanidis [Solution Manual]
Introduction to Signal Processing Orfanidis [Solution Manual]slyhamm
 
modelling and simulation of second order mechanical system
modelling and simulation of second order mechanical systemmodelling and simulation of second order mechanical system
modelling and simulation of second order mechanical systemsanmudo
 
Solution manual for theory and applications of digital speech processing lawr...
Solution manual for theory and applications of digital speech processing lawr...Solution manual for theory and applications of digital speech processing lawr...
Solution manual for theory and applications of digital speech processing lawr...zammok
 
Digital signal processing By Er. Swapnil Kaware
Digital signal processing By Er. Swapnil KawareDigital signal processing By Er. Swapnil Kaware
Digital signal processing By Er. Swapnil KawareProf. Swapnil V. Kaware
 
Advanced Topics In Digital Signal Processing
Advanced Topics In Digital Signal ProcessingAdvanced Topics In Digital Signal Processing
Advanced Topics In Digital Signal ProcessingJim Jenkins
 
Robophonia[2]
Robophonia[2]Robophonia[2]
Robophonia[2]vivek091
 
Dsp U Lec01 Real Time Dsp Systems
Dsp U   Lec01 Real Time Dsp SystemsDsp U   Lec01 Real Time Dsp Systems
Dsp U Lec01 Real Time Dsp Systemstaha25
 

Destaque (20)

Digital Signal Processing Lab Manual ECE students
Digital Signal Processing Lab Manual ECE studentsDigital Signal Processing Lab Manual ECE students
Digital Signal Processing Lab Manual ECE students
 
Dsp manual completed2
Dsp manual completed2Dsp manual completed2
Dsp manual completed2
 
Signal Prosessing Lab Mannual
Signal Prosessing Lab Mannual Signal Prosessing Lab Mannual
Signal Prosessing Lab Mannual
 
Dsp lab manual
Dsp lab manualDsp lab manual
Dsp lab manual
 
Digital signal processing (2nd ed) (mitra) solution manual
Digital signal processing (2nd ed) (mitra) solution manualDigital signal processing (2nd ed) (mitra) solution manual
Digital signal processing (2nd ed) (mitra) solution manual
 
MATLAB Programs For Beginners. | Abhi Sharma
MATLAB Programs For Beginners. | Abhi SharmaMATLAB Programs For Beginners. | Abhi Sharma
MATLAB Programs For Beginners. | Abhi Sharma
 
Linear Convolution using Matlab Code
Linear Convolution  using Matlab CodeLinear Convolution  using Matlab Code
Linear Convolution using Matlab Code
 
Digital signal processing computer based approach - sanjit k. mitra (2nd ed)
Digital signal processing   computer based approach - sanjit k. mitra (2nd ed)Digital signal processing   computer based approach - sanjit k. mitra (2nd ed)
Digital signal processing computer based approach - sanjit k. mitra (2nd ed)
 
Butterworth filter design
Butterworth filter designButterworth filter design
Butterworth filter design
 
DIGITAL SIGNAL PROCESSING
DIGITAL SIGNAL PROCESSINGDIGITAL SIGNAL PROCESSING
DIGITAL SIGNAL PROCESSING
 
Application of code composer studio in digital signal processing
Application of code composer studio in digital signal processingApplication of code composer studio in digital signal processing
Application of code composer studio in digital signal processing
 
DSP Mat Lab
DSP Mat LabDSP Mat Lab
DSP Mat Lab
 
Introduction to Signal Processing Orfanidis [Solution Manual]
Introduction to Signal Processing Orfanidis [Solution Manual]Introduction to Signal Processing Orfanidis [Solution Manual]
Introduction to Signal Processing Orfanidis [Solution Manual]
 
modelling and simulation of second order mechanical system
modelling and simulation of second order mechanical systemmodelling and simulation of second order mechanical system
modelling and simulation of second order mechanical system
 
Dsp manual
Dsp manualDsp manual
Dsp manual
 
Solution manual for theory and applications of digital speech processing lawr...
Solution manual for theory and applications of digital speech processing lawr...Solution manual for theory and applications of digital speech processing lawr...
Solution manual for theory and applications of digital speech processing lawr...
 
Digital signal processing By Er. Swapnil Kaware
Digital signal processing By Er. Swapnil KawareDigital signal processing By Er. Swapnil Kaware
Digital signal processing By Er. Swapnil Kaware
 
Advanced Topics In Digital Signal Processing
Advanced Topics In Digital Signal ProcessingAdvanced Topics In Digital Signal Processing
Advanced Topics In Digital Signal Processing
 
Robophonia[2]
Robophonia[2]Robophonia[2]
Robophonia[2]
 
Dsp U Lec01 Real Time Dsp Systems
Dsp U   Lec01 Real Time Dsp SystemsDsp U   Lec01 Real Time Dsp Systems
Dsp U Lec01 Real Time Dsp Systems
 

Semelhante a DSP Lab Manual for Digital Signal Processing

DSP_FOEHU - MATLAB 01 - Discrete Time Signals and Systems
DSP_FOEHU - MATLAB 01 - Discrete Time Signals and SystemsDSP_FOEHU - MATLAB 01 - Discrete Time Signals and Systems
DSP_FOEHU - MATLAB 01 - Discrete Time Signals and SystemsAmr E. Mohamed
 
DSP_FOEHU - MATLAB 02 - The Discrete-time Fourier Analysis
DSP_FOEHU - MATLAB 02 - The Discrete-time Fourier AnalysisDSP_FOEHU - MATLAB 02 - The Discrete-time Fourier Analysis
DSP_FOEHU - MATLAB 02 - The Discrete-time Fourier AnalysisAmr E. Mohamed
 
Unit 2 signal &amp;system
Unit 2 signal &amp;systemUnit 2 signal &amp;system
Unit 2 signal &amp;systemsushant7dare
 
Module1_dsffffffffffffffffffffgggpa.pptx
Module1_dsffffffffffffffffffffgggpa.pptxModule1_dsffffffffffffffffffffgggpa.pptx
Module1_dsffffffffffffffffffffgggpa.pptxrealme6igamerr
 
STEP RESPONSE OF FIRST ORDER SYSTEM PART 1.pptx
STEP RESPONSE OF FIRST ORDER SYSTEM PART 1.pptxSTEP RESPONSE OF FIRST ORDER SYSTEM PART 1.pptx
STEP RESPONSE OF FIRST ORDER SYSTEM PART 1.pptxAnikendu Maitra
 
EC8553 Discrete time signal processing
EC8553 Discrete time signal processing EC8553 Discrete time signal processing
EC8553 Discrete time signal processing ssuser2797e4
 
Digital Signal Processing
Digital Signal ProcessingDigital Signal Processing
Digital Signal ProcessingPRABHAHARAN429
 
MSE280s Chapter1_Signals_and_Systems.pdf
MSE280s Chapter1_Signals_and_Systems.pdfMSE280s Chapter1_Signals_and_Systems.pdf
MSE280s Chapter1_Signals_and_Systems.pdfTranThanhNam8
 
control system Lab 01-introduction to transfer functions
control system Lab 01-introduction to transfer functionscontrol system Lab 01-introduction to transfer functions
control system Lab 01-introduction to transfer functionsnalan karunanayake
 
lecture1 (5).ppt
lecture1 (5).pptlecture1 (5).ppt
lecture1 (5).pptHebaEng
 

Semelhante a DSP Lab Manual for Digital Signal Processing (20)

DSP_FOEHU - MATLAB 01 - Discrete Time Signals and Systems
DSP_FOEHU - MATLAB 01 - Discrete Time Signals and SystemsDSP_FOEHU - MATLAB 01 - Discrete Time Signals and Systems
DSP_FOEHU - MATLAB 01 - Discrete Time Signals and Systems
 
DSP_FOEHU - MATLAB 02 - The Discrete-time Fourier Analysis
DSP_FOEHU - MATLAB 02 - The Discrete-time Fourier AnalysisDSP_FOEHU - MATLAB 02 - The Discrete-time Fourier Analysis
DSP_FOEHU - MATLAB 02 - The Discrete-time Fourier Analysis
 
Dsp manual
Dsp manualDsp manual
Dsp manual
 
P73
P73P73
P73
 
Unit 2 signal &amp;system
Unit 2 signal &amp;systemUnit 2 signal &amp;system
Unit 2 signal &amp;system
 
lecture4signals-181130200508.pptx
lecture4signals-181130200508.pptxlecture4signals-181130200508.pptx
lecture4signals-181130200508.pptx
 
Module1_dsffffffffffffffffffffgggpa.pptx
Module1_dsffffffffffffffffffffgggpa.pptxModule1_dsffffffffffffffffffffgggpa.pptx
Module1_dsffffffffffffffffffffgggpa.pptx
 
STEP RESPONSE OF FIRST ORDER SYSTEM PART 1.pptx
STEP RESPONSE OF FIRST ORDER SYSTEM PART 1.pptxSTEP RESPONSE OF FIRST ORDER SYSTEM PART 1.pptx
STEP RESPONSE OF FIRST ORDER SYSTEM PART 1.pptx
 
Dsp Lab Record
Dsp Lab RecordDsp Lab Record
Dsp Lab Record
 
Lecture 4: Classification of system
Lecture 4: Classification of system Lecture 4: Classification of system
Lecture 4: Classification of system
 
EC8553 Discrete time signal processing
EC8553 Discrete time signal processing EC8553 Discrete time signal processing
EC8553 Discrete time signal processing
 
Digital Signal Processing
Digital Signal ProcessingDigital Signal Processing
Digital Signal Processing
 
MSE280s Chapter1_Signals_and_Systems.pdf
MSE280s Chapter1_Signals_and_Systems.pdfMSE280s Chapter1_Signals_and_Systems.pdf
MSE280s Chapter1_Signals_and_Systems.pdf
 
476 293
476 293476 293
476 293
 
Signals & systems
Signals & systems Signals & systems
Signals & systems
 
control system Lab 01-introduction to transfer functions
control system Lab 01-introduction to transfer functionscontrol system Lab 01-introduction to transfer functions
control system Lab 01-introduction to transfer functions
 
Introduction to Adaptive filters
Introduction to Adaptive filtersIntroduction to Adaptive filters
Introduction to Adaptive filters
 
ACS 22LIE12 lab Manul.docx
ACS 22LIE12 lab Manul.docxACS 22LIE12 lab Manul.docx
ACS 22LIE12 lab Manul.docx
 
lecture1 (5).ppt
lecture1 (5).pptlecture1 (5).ppt
lecture1 (5).ppt
 
Dsp class 3
Dsp class 3Dsp class 3
Dsp class 3
 

Último

New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 

Último (20)

New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 

DSP Lab Manual for Digital Signal Processing

  • 1. K. S. SCHOOL OF ENGINEERING & MANAGEMENT # 15, Mallasandra, Off Kanakapura Road, Bangalore-560062, Karnataka, India. DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING Digital Signal Processing Lab Manual Sub Code: 10ECL57 Sem : V Prepared By Mrs. Vidhya R., Asst. Professor Mr. Ravikiran B. A., Asst. Professor
  • 2. Table of Contents PART – A 1 Verification of Sampling theorem. 1 2 Impulse response of a given system 4 3 Linear convolution of two given sequences. 7 4 Circular convolution of two given sequences 11 5 Autocorrelation of a given sequence and verification of its properties. 15 6 Cross-correlation of given sequences and verification of its properties. 18 7 Solving a given difference equation. 21 8 Computation of N point DFT of a given sequence and to plot magnitude and phase spectrum. 23 9 Linear convolution of two sequences using DFT and IDFT. 26 10 Circular convolution of two given sequences using DFT and IDFT 29 11 Design and implementation of FIR filter to meet given specifications. 32 12 Design and implementation of IIR filter to meet given specifications. 36 DSPLab-ECEDepartment,KSSEM
  • 3. PART – B About the DSP Trainer Kit 44 Using Code Composer Studio 47 1 Linear convolution of two given sequences. 56 2 Circular convolution of two given sequences 58 3 Computation of N point DFT of a given sequence. 60 4 Impulse Response of the First Order and Second Order Systems 62 Viva Questions 64 DSPLab-ECEDepartment,KSSEM
  • 4. DSP Laboratory (10ECL57) 5th Sem KSSEM, Bangalore Dept of ECE Page | 1 PROGRAM 1 VERIFICATION OF SAMPLING THEOREM Aim: To write the MATLAB code for verifying Sampling Theorem. Generate a sinusoidal wave of 1kHz. Calculate the Nyquist frequency, and verify Sampling Theorem, showing output waveforms for undersampled, oversampled and right sampled cases. Theory: Sampling is the process of converting an continuous time signal into a discrete time signal. In sampling, the values of the continuous time signal is recorded at discrete intervals of time (usually equidistant). The number of samples taken during one second is called the sampling rate. Sampling is described by the relation: 𝑥(𝑛) = 𝑥 𝑎(𝑛𝑇) − ∞ < 𝑛 < ∞ Where 𝑥(𝑛) is the discrete-time signal obtained by sampling the analog signal every T seconds. 𝐹𝑠 = 1/𝑇 is known as the Sampling Frequency. The Sampling Theorem states that : “A bandlimited signal can be reconstructed exactly if it is sampled at a rate atleast twice the maximum frequency component in it." Assume a band-limited signal 𝑥(𝑡) = 𝐴 sin(𝜔𝑡) = 𝐴 sin(2𝜋𝐹𝑡) with maximum frequency component ′𝜔′. The theorem says that, for a good reconstruction of the original continuous time signal, the sampling frequency must be at least 2𝜔. This frequency is known as the “Nyquist Rate”. Sampling this signal at 𝐹𝑠 gives us the discrete time signal: 𝑥 𝑎(𝑛𝑇) = 𝐴 sin � 2𝜋𝑛𝐹 𝐹𝑠 � Now, assuming the sampling frequency is more than the Nyquist Frequency, the continuous time signal can be reconstructed accurately using the interpolation function: 𝑔(𝑡) = sin 2𝜋𝐹𝑡 2𝜋𝐹𝑡 Then, approximated recovered signal can be written as: 𝑥′ 𝑎(𝑡) = � 𝑥 𝑎 � 𝑛 𝐹𝑠 � ∞ 𝑛=−∞ 𝑔 �𝑡 − 𝑛 𝐹𝑠 � DSPLab-ECEDepartment,KSSEM
  • 5. DSP Laboratory (10ECL57) 5th Sem KSSEM, Bangalore Dept of ECE Page | 2 Whenever the Sampling frequency 𝐹𝑠 is greater than or equal to the Nyquist Frequency, the signal can be reconstructed faithfully, capturing all the essential properties of the original continuous-time signal. However, when 𝐹𝑠 < 2𝐹, we encounter a problem called “Aliasing”, where distortion is caused by high frequencies overlapping low frequencies. A lot of data is lost in this process and the signal cannot be recovered. MATLAB CODE: % Experiment 1 : Sampling Theorem Verification clear all; close all; clc; % Signal Parameters f = 1000; % Signal Frequency = 1kHz T = 1/f; % Signal Period t = 0:0.01*T:2*T; % Time index % Generate the original signal and plot it: x = cos(2*pi*t*f); % Signal : 2*pi*f*t subplot(2,2,1); plot(t,x); title('Continuous signal'); xlabel('t'); ylabel('x(t)'); %Oversampling Condition: fs1 = 10*f; % Oversampling (fs > 2f) n1 = 0:1/fs1:2*T; % Time scale x1 = cos(2*pi*f*n1); % Generating sampled signal subplot(2,2,2); stem(n1,x1); hold on; plot(n1,x1,'r'); hold off; title('Oversampling Condition : Fs = 10F'); xlabel('n'); ylabel('x(n)'); % Right Sampling Condition: fs2 = 2*f; % Nyquist Rate Sampling (fs = 2f) n2 = 0:1/fs2:2*T; x2 = cos(2*pi*f*n2); subplot(2,2,3); stem(n2,x2); hold on; plot(n2,x2,'r'); hold off; title('Sampling at Nyquist Frequency : Fs = 2F'); xlabel('n'); ylabel('x(n)'); DSPLab-ECEDepartment,KSSEM
  • 6. DSP Laboratory (10ECL57) 5th Sem KSSEM, Bangalore Dept of ECE Page | 3 % Under Sampling Condition: fs3 = 1.5*f; % Undersampling (fs < 2f) n3 = 0:1/fs3:2*T; x3 = cos(2*pi*f*n3); subplot(2,2,4); stem(n3,x3); hold on; plot(n3,x3,'r'); hold off; title('Undersampling Condition : Fs = 1.5 f'); xlabel('n'); ylabel('x(n)'); OUTPUT: DSPLab-ECEDepartment,KSSEM
  • 7. DSP Laboratory (10ECL57) 5th Sem KSSEM, Bangalore Dept of ECE Page | 4 PROGRAM 2 IMPULSE RESPONSE OF A GIVEN SYSTEM Aim: To write the MATLAB code to find the impulse response of a given second-order system whose difference equation representation is given. Assume a second-order system represented by the following difference equation: 𝑦(𝑛) = 𝑏0 𝑥(𝑛) + 𝑏1 𝑥(𝑛 − 1) + 𝑏20 𝑥(𝑛 − 2) + 𝑎1 𝑦(𝑛 − 1) + 𝑎2 𝑦(𝑛 − 2) Theory: Impulse response of a system is defined as the output of a given system, when the input applied to the system, is in the form of an unit impulse, or a Dirac delta function. The impulse response completely characterizes the behaviour of any LTI system. The impulse response is often determined from knowledge of the system configuration and dynamics, or can be measured by applying and approximate impulse to the system input. Discrete-time LTI systems can also be described using Difference Equations. A linear constant-coefficient difference equation can be of the form: � 𝑎 𝑘 𝑦[𝑛 − 𝑘] = 𝑁 𝑘=0 � 𝑏 𝑘 𝑦[𝑛 − 𝑘] 𝑀 𝑘=0 Where the integer N is termed the order of the difference equation, and corresponds to the maximum memory involving the system output. The order generally represents the number of energy storage devices in a physical system. We can calculate the impulse response of the system using Z-transforms as shown in the following example: Consider a difference equation: 𝑦(𝑛) = 𝑥(𝑛) + 0.2 𝑥(𝑛 − 1) − 1.5 𝑥(𝑛 − 2) − 3 𝑦(𝑛 − 1) + 0.12 𝑦(𝑛 − 2) This can be rewritten in the standard form as: 𝑦(𝑛) + 3 𝑦(𝑛 − 1) − 0.12 𝑦(𝑛 − 2) = 𝑥(𝑛) + 0.2 𝑥(𝑛 − 1) − 1.5 𝑥(𝑛 − 2) Finding the Z-transform of the equation: 𝑌(𝑍) + 3 𝑍−1 𝑌(𝑍) − 0.12 𝑍−2 𝑌(𝑍) = 𝑋(𝑍) + 0.2 𝑍−1 𝑋(𝑍) − 1.5 𝑍−2 𝑋(𝑍) Or: 𝑌(𝑍)[1 + 3 𝑍−1 − 0.12 𝑍−2 ] = 𝑋(𝑍)[1 + 0.2 𝑍−1 − 1.5 𝑍−2 ] DSPLab-ECEDepartment,KSSEM
  • 8. DSP Laboratory (10ECL57) 5th Sem KSSEM, Bangalore Dept of ECE Page | 5 Transfer Function of the system can be obtained as : 𝐻(𝑍) = 𝑌(𝑍) 𝑋(𝑍) = [1 + 3 𝑍−1 − 0.12 𝑍−2 ] [1 + 0.2 𝑍−1 − 1.5 𝑍−2] By long division, we get : 𝐻(𝑍) = 1 − 2.8 𝑍−1 + 7.02 𝑍−2 − 21.4 𝑍−3 + 65.03 𝑍−4 By taking Inverse-Z transform, we can obtain the Impulse Response as: ℎ[𝑛] = [1 − 2.8 7.02 21.4 65.03] MATLAB CODE: % Experiment 2 : Impulse Response of a Given Second-Order System clear all; close all; clc; % Accept Input and Output signal Co-efficients: b = input('Enter the coefficients of x(n) in 1-D Matrix Form: '); a = input('Enter the coefficients of y(n) in 1-D Matrix Form: '); N = input('Enter the number of samples of impulse response desired: '); % Calculate Impulse Response using IMPZ function: % [H,T] = IMPZ(B,A,N) computes N samples of the impulse response, using % coefficients B and A from difference equation representation. [h,t] = impz(b,a,N); %Plot and Display impulse response co-efficients: stem(t,h); title('Impulse Response Plot'); ylabel('h(n)'); xlabel('n'); disp('Impulse Response Coefficients:'); disp(h); OUTPUT: Enter the coefficients of x(n) in 1-D Matrix Form: [1 0.2 -1.5] Enter the coefficients of y(n) in 1-D Matrix Form: [1 3 -0.12] Enter the number of samples of impulse response desired: 5 Impulse Response Coefficients: 1.0000 -2.8000 7.0200 -21.3960 65.0304 DSPLab-ECEDepartment,KSSEM
  • 9. DSP Laboratory (10ECL57) 5th Sem KSSEM, Bangalore Dept of ECE Page | 6 DSPLab-ECEDepartment,KSSEM
  • 10. DSP Laboratory (10ECL57) 5th Sem KSSEM, Bangalore Dept of ECE Page | 7 PROGRAM 3 LINEAR CONVOLUTION OF TWO GIVEN SEQUENCES Aim: To write the MATLAB code to perform Linear Convolution upon two given discrete time signals. Theory: Convolution is the process used to find the response of a Linear Time Invariant system to a given input, assuming we already know the impulse response of that system. In case of continuous-time signals, we can find the system response using the Convolution Integral, while in case of discrete-time systems, the response can be calculated using the Convolution Sum. Let 𝑥1(𝑛) and 𝑥2(𝑛) be two discrete-time signals. The convolution sum of the two signals can be calculated using the formula: 𝑦(𝑛) = 𝑥1(𝑛) ∗ 𝑥2(𝑛) = � 𝑥1(𝑘) 𝑥2(𝑛 − 𝑘) ∞ 𝑘=−∞ If 𝑥1(𝑛) is a M- point sequence and 𝑥2(𝑛) is an N – point sequence, then the convolved sequence, 𝑦(𝑛) is a (M+N-1) – point sequence. We can perform the convolution by different methods: 1. Using MATLAB’s “CONV” function : MATLAB has a built-in function called “conv” function, which basically performs a linear convolution of any two given sequences. 2. Using the Linear Convolution Sum formula : Here, we use the convolution sum formula and substitute values of 𝑛 and 𝑘 in the expression, and calculate the values of the convolved signal. Alternatively, we can perform the signal inversion-time shift-superposition method, by which we can calculate the resultant signal values. Assume two discrete-time sequences 𝑥1 and 𝑥2 in a Linear Time Invariant System, given by: 𝑥1(𝑛) = {1, 2, −1, 3} and 𝑥2(𝑛) = {2,3, −2} We see that length of sequence 𝑥1 is (M = 4) and that of sequence 𝑥2 is (N = 3). Therefore, the length of the convolved sequence will be (M+N-1 = 6). Using any of the above given methods, we see that the resultant convolved sequence can be given by: 𝑦(𝑛) = 𝑥1(𝑛) ∗ 𝑥2(𝑛) = { 2 7 2 − 1 11 − 6} DSPLab-ECEDepartment,KSSEM
  • 11. DSP Laboratory (10ECL57) 5th Sem KSSEM, Bangalore Dept of ECE Page | 8 MATLAB CODE: 1. Using “conv” function: %% Linear Convolution using CONV command clear all; close all; clc; % Accept input signal sequences x1 = input('Enter Input Sequence for Signal x1(n): '); x2 = input('Enter Input Sequence for Signal x2(n): '); %Perform Linear Convolution using CONV command y=conv(x1,x2); %Plot Input and Convolved Signals subplot(3,1,1); stem(x1); title('Input Signal x1(n)'); xlabel('n'); ylabel('x1(n)'); subplot(3,1,2); stem(x2); title('Input Signal x2(n)'); xlabel('n'); ylabel('x2(n)'); subplot(3,1,3); stem(y); title('Convolved Signal y(n) = x1(n)*x2(n)'); xlabel('n'); ylabel('y(n)'); % Display the convolved Sequence in Command Window disp('Convolved sequence:'); disp(y); 2. Using Convolution Sum formula: %% Linear Convolution without using CONV command clear all; close all; clc; x1 = input('Enter Input Sequence for Signal x1(n): '); n1 = length(x1); x2 = input('Enter Input Sequence for Signal x2(n): '); n2=length(x2); N = n1+n2-1; %Length of Convolved Sequence T = 1:N; % Create Time Index %Zero padding to make sequences of length N x1=[x1 zeros(1,N-n1)]; x2=[x2 zeros(1,N-n2)]; %Initializing Output sequence of zeros. y = zeros(1,N); %Performing Linear Convolution: DSPLab-ECEDepartment,KSSEM
  • 12. DSP Laboratory (10ECL57) 5th Sem KSSEM, Bangalore Dept of ECE Page | 9 for n = 1:N % y(n) = 0R; for k = 1:n y(n)=y(n)+x1(k)*x2(n-k+1); end end % Plot Input and Output Sequences: subplot(3,1,1); stem(T,x1); title('Input Signal x1(n)'); xlabel('n'); ylabel('x1(n)'); subplot(3,1,2); stem(T,x2); title('Input Signal x2(n)'); xlabel('n'); ylabel('x2(n)'); subplot(3,1,3); stem(T,y); title('Convolved Signal y(n) = x1(n)*x2(n)'); xlabel('n'); ylabel('y(n)'); % Display the convolved Sequence in Command Window disp('Convolved sequence:'); disp(y); OUTPUT: Enter Input Sequence for Signal x1(n): [1 2 -1 3] Enter Input Sequence for Signal x2(n): [2 3 -2] Convolved sequence: 2 7 2 -1 11 -6 DSPLab-ECEDepartment,KSSEM
  • 13. DSP Laboratory (10ECL57) 5th Sem KSSEM, Bangalore Dept of ECE Page | 10 DSPLab-ECEDepartment,KSSEM
  • 14. DSP Laboratory (10ECL57) 5th Sem KSSEM, Bangalore Dept of ECE Page | 11 PROGRAM 4 CIRCULAR CONVOLUTION OF TWO GIVEN SEQUENCES Aim: To write the MATLAB code to perform Circular Convolution upon two given discrete time signals. Theory: The Circular convolution, also known as cyclic convolution, of two aperiodic functions occurs when one of them is convolved in the normal way with a periodic summation of the other function. Circular convolution is only defined for finite length functions (usually equal in length), continuous or discrete in time. In circular convolution, it is as if the finite length functions repeat in time, periodically. Because the input functions are now periodic, the convolved output is also periodic. Circular convolution sum can be calculated using the formula: 𝑦(𝑛) = 𝑥1(𝑛) ∗ 𝑥2(𝑛) = � 𝑥1(𝑛) 𝑥2�(𝑚 − 𝑛)� 𝑁 𝑁−1 𝑛=0 For 𝑚 = 0,1, … . , 𝑁 − 1 Circular convolution can be performed in different ways : 1. Using the expression for linear convolution sum, but assuming the signal repeats periodically. This can be done by changing the negative indices of (n-k) to repetitions of the latter portions of the original aperiodic signal. 2. Convolution in time domain corresponds to multiplication in frequency domain. To make use of this property, we can calculate the DTFT of each of the aperiodic signals, multiply these in the frequency domain, and find the IDFT of the product, to get the periodic convolved signal in time domain. Let us take the case of two discrete-time aperiodic signals given by: 𝑥1(𝑛) = {2,1,2,1} and 𝑥2(𝑛) = {1,2,3,4} Using the formula with N = 4. For m = 0: 𝑦(0) = � 𝑥1(𝑛) 𝑥2�(−𝑛)�4 3 𝑛=0 = 14 For m = 1: 𝑦(1) = � 𝑥1(𝑛) 𝑥2�(1 − 𝑛)�4 3 𝑛=0 = 16 For m = 2: DSPLab-ECEDepartment,KSSEM
  • 15. DSP Laboratory (10ECL57) 5th Sem KSSEM, Bangalore Dept of ECE Page | 12 𝑦(2) = � 𝑥1(𝑛) 𝑥2�(2 − 𝑛)�4 3 𝑛=0 = 14 For m = 3: 𝑦(3) = � 𝑥1(𝑛) 𝑥2�(3 − 𝑛)�4 3 𝑛=0 = 16 So, we get the circular convolution sum as: 𝑦(𝑛) = {14,16,14,16} MATLAB CODE: 1. Using Convolution Sum Formula: %% Circular Convolution using Formula clear all; close all; clc; x1 = input('Enter Input Sequence for Signal x1(n): '); n1 = length(x1); x2 = input('Enter Input Sequence for Signal x2(n): '); n2=length(x2); N = max(n1,n2); % Length of Convolved Sequence T = 1:N; % Create Time Index %Zero padding to make sequences of length N x1=[x1 zeros(1,N-n1)]; x2=[x2 zeros(1,N-n2)]; %Initializing Output sequence of zeros. y = zeros(1,N); %Performing Linear Convolution: for m=1:N for n=1:N i=m-n+1; %(m-n+1) since we're taking index from 1 if(i<=0) i=N+i; end y(m)=y(m)+x1(n)*x2(i); %Convolution Sum Formula end end % Plot Input and Output Sequences: subplot(3,1,1); stem(T,x1); title('Input Signal x1(n)'); xlabel('n'); ylabel('x1(n)'); subplot(3,1,2); stem(T,x2); DSPLab-ECEDepartment,KSSEM
  • 16. DSP Laboratory (10ECL57) 5th Sem KSSEM, Bangalore Dept of ECE Page | 13 title('Input Signal x2(n)'); xlabel('n'); ylabel('x2(n)'); subplot(3,1,3); stem(T,y); title('Convolved Signal y(n) = x1(n)*x2(n)'); xlabel('n'); ylabel('y(n)'); % Display the convolved Sequence in Command Window disp('Convolved sequence:'); disp(y); 2. Using “cconv” function. %% Circular Convolution using CCONV command clear all; close all; clc; % Accept input signal sequences x1 = input('Enter Input Sequence for Signal x1(n): '); x2 = input('Enter Input Sequence for Signal x2(n): '); n=max(length(x1),length(x2)); %Perform Linear Convolution using CONV command y=cconv(x1,x2,n); %Plot Input and Convolved Signals subplot(3,1,1); stem(x1); title('Input Signal x1(n)'); xlabel('n'); ylabel('x1(n)'); subplot(3,1,2); stem(x2); title('Input Signal x2(n)'); xlabel('n'); ylabel('x2(n)'); subplot(3,1,3); stem(y); title('Convolved Signal y(n) = x1(n)*x2(n)'); xlabel('n'); ylabel('y(n)'); % Display the convolved Sequence in Command Window disp('Convolved sequence:'); disp(y); OUTPUT: Enter Input Sequence for Signal x1(n): [2 1 2 1] Enter Input Sequence for Signal x2(n): [1 2 3 4] Convolved sequence: 14 16 14 16 DSPLab-ECEDepartment,KSSEM
  • 17. DSP Laboratory (10ECL57) 5th Sem KSSEM, Bangalore Dept of ECE Page | 14 DSPLab-ECEDepartment,KSSEM
  • 18. DSP Laboratory (10ECL57) 5th Sem KSSEM, Bangalore Dept of ECE Page | 15 PROGRAM 5 AUTOCORRELATION OF A GIVEN SEQUENCE Aim: To write the MATLAB code to perform Autocorrelation on a given signal and to verify its properties. Theory: In signal processing, Correlation is a measure of similarity of two waveforms, as a function of a time-lag applied to one of them. This is also known as a sliding dot product or sliding inner-product. It is commonly used for searching a long-signal for a shorter, known feature. Auto-correlation is a special form of Correlation, in which a signal is cross-convolved with itself. It is a mathematical tool for finding repeating patterns, such as the presence of a periodic signal which has been buried under noise, or identifying the missing fundamental frequency in a signal implied by its harmonic frequencies. It is often used in signal processing for analyzing functions or series of values, such as time domain signals. Auto-correlation of a signal 𝑥(𝑛) is given by the formula: 𝑟𝑥𝑥(𝑙) = � 𝑥(𝑛)𝑥(𝑛 − 𝑙) 𝑙 = 0, ±1, ±2, … ∞ 𝑛=−∞ In case of finite-duration signals, we can write: 𝑟𝑥 𝑥(𝑙) = � 𝑥(𝑛)𝑥(𝑛 − 𝑙) 𝑁−|𝑘|−1 𝑛=𝑖 Where 𝑖 = 𝑙, 𝑘 = 0 𝑓𝑜𝑟 𝑙 ≥ 0 and 𝑖 = 0, 𝑘 = 𝑙 𝑓𝑜𝑟 𝑙 < 0. Assuming our signal is of the form 𝑎𝑥(𝑛) + 𝑏𝑥(𝑛 − 𝑙) Energy in the signal is given by: � [𝑎𝑥(𝑛) + 𝑏𝑥(𝑛 − 𝑙)]2 ∞ 𝑛=−∞ = 𝑎2 � 𝑥2 ∞ 𝑛=−∞ (𝑛) + 𝑏2 � 𝑥2 ∞ 𝑛=−∞ (𝑛 − 𝑙) + 2𝑎𝑏 � 𝑥 ∞ 𝑛=−∞ (𝑛)𝑥(𝑛 − 𝑙) = 𝑎2 𝑟𝑥 𝑥(0)+𝑏2 𝑟𝑥 𝑥(0) + 2𝑎𝑏 𝑟𝑥 𝑥(𝑙) ≥ 0 This can be written as: |𝑟𝑥𝑥(𝑙)| ≤ |𝑟𝑥𝑥(0)| = 𝐸 𝑥. That is, autocorrelation sequence of a signal attains its maximum value at zero lag. This is consistent with the notion that a signal matches perfectly with itself at zero shift. Assume a signal 𝑥(𝑛) = {1,2,3,4}. Its autocorrelation sequence can be calculated as: 𝑟𝑥 𝑥(𝑙) = {4,11,20,30, 20,11,4} DSPLab-ECEDepartment,KSSEM
  • 19. DSP Laboratory (10ECL57) 5th Sem KSSEM, Bangalore Dept of ECE Page | 16 Energy of the signal is given by: 𝐸 = � 𝑥(𝑛)2 3 𝑛=0 = 12 + 22 + 32 + 42 = 30 = 𝑟𝑥 𝑥(0) Hence, it is an energy signal. We see that the Total energy of the signal is equal to the amplitude of the autocorrelation signal at the origin. MATLAB CODE: % Experiment 5 : Autocorrelation of a Signal. clear all; close all; clc; % Accept user-defined input sequence and define time index x = input('Enter a finite-length signal sequence : '); n = 0:length(x)-1; % Perform Autocorrelation using xcorr function. rxx = xcorr(x,x); % Generate Time Index for Autocorrelation sequence, about origin n2 = -length(x)+1:length(x)-1; disp('Autocorrelation Sequence : '); disp(int8(rxx)); % Plot the Original Signal and Autocorrelation Sequence subplot(2,1,1); stem(n,x); title('Input Signal'); xlabel('n'); ylabel('x(n)'); subplot(2,1,2); stem(n2,rxx); title('Autocorrelation Sequence'); xlabel('n'); ylabel('rxx(l)'); grid on; % Verifying Autocorrelation properties: E = sum(x.^2); % Energy of signal. mid = ceil(length(rxx)/2); % Find index of centre of sequence E0 = rxx(mid); % Detect Amplitude of Sequence midpoint fprintf('Energy of Input Signal : %dn',E); fprintf('Amplitude of Midpoint of Autocorrelation Sequence : %dn',E0); % Verify Autocorrelation Property by comparing Energy values if int8(E0) == int8(E) %Type conversion for approximation disp('Autocorrelation Energy Property is verified'); else disp('Autocorrelation Energy Property is not verified'); end % Verify that the Signal is even. rxx_r = rxx(mid:length(rxx)); %Right Side of AC Sequence DSPLab-ECEDepartment,KSSEM
  • 20. DSP Laboratory (10ECL57) 5th Sem KSSEM, Bangalore Dept of ECE Page | 17 rxx_l = rxx(mid:-1:1); %Left Side of AC Sequence if rxx_r == rxx_l disp('Autocorrelation Sequence is Even. Hence, verified.'); else disp('Autocorrelation Sequence is not Even. Hence, not verified.'); end OUTPUT: Enter a finite-length signal sequence : [1 2 3 4] Autocorrelation Sequence : 4 11 20 30 20 11 4 Energy of Input Signal : 30 Amplitude of Midpoint of Autocorrelation Sequence : 30 Autocorrelation Energy Property is verified Autocorrelation Sequence is Even. Hence, verified. DSPLab-ECEDepartment,KSSEM
  • 21. DSP Laboratory (10ECL57) 5th Sem KSSEM, Bangalore Dept of ECE Page | 18 PROGRAM 6 CROSS - CORRELATION OF A GIVEN SEQUENCE Aim: To write the MATLAB code to perform cross-correlation on a given signal and to verify its properties. Theory: Cross-correlation is a process, in which a signal is convolved with another signal. It is commonly used for searching a long-signal for a shorter, known feature. It also has applications in pattern recognition, single particle analysis, electron tomographic averaging, cryptanalysis, and neurophysiology. Cross-correlation of two signals 𝑥1(𝑛) and 𝑥2(𝑛) is given by the formula: 𝑟𝑥 𝑦(𝑙) = � 𝑥(𝑛)𝑦(𝑛 − 𝑙) 𝑙 = 0, ±1, ±2, … ∞ 𝑛=−∞ In case of finite-duration signals, we can write: 𝑟𝑥 𝑦(𝑙) = � 𝑥(𝑛)𝑦(𝑛 − 𝑙) 𝑁−|𝑘|−1 𝑛=𝑖 Where 𝑖 = 𝑙, 𝑘 = 0 𝑓𝑜𝑟 𝑙 ≥ 0 and 𝑖 = 0, 𝑘 = 𝑙 𝑓𝑜𝑟 𝑙 < 0. Assuming our signal is of the form 𝑎𝑥(𝑛) + 𝑏𝑦(𝑛 − 𝑙) Energy in the signal is given by: � [𝑎𝑥(𝑛) + 𝑏𝑦(𝑛 − 𝑙)]2 ∞ 𝑛=−∞ = 𝑎2 � 𝑥2 ∞ 𝑛=−∞ (𝑛) + 𝑏2 � 𝑦2 ∞ 𝑛=−∞ (𝑛 − 𝑙) + 2𝑎𝑏 � 𝑥 ∞ 𝑛=−∞ (𝑛)𝑦(𝑛 − 𝑙) = 𝑎2 𝑟𝑥𝑥(0)+𝑏2 𝑟𝑦𝑦(0) + 2𝑎𝑏 𝑟𝑥𝑦(𝑙) ≥ 0 This can be written as: �𝑟𝑥 𝑦(𝑙)� ≤ � 𝑟𝑥 𝑥(0)𝑟𝑦𝑦(0) = � 𝐸 𝑥 𝐸 𝑦. Note that the shape of the autocorrelation sequence does not change with amplitude scaling of input signals. Only the amplitude of the autocorrelation sequence changes accordingly. Cross-correlation satisfies the property: 𝑟𝑥𝑦(𝑙) = 𝑟𝑦𝑥(−𝑙) DSPLab-ECEDepartment,KSSEM
  • 22. DSP Laboratory (10ECL57) 5th Sem KSSEM, Bangalore Dept of ECE Page | 19 MATLAB CODE: % Experiment 6 : Cross-correlation of two Signals. clear all; close all; clc; % Accept user-defined input sequences and define time index for it x1 = input('Enter a finite-length signal sequence X1(n): '); n1 = 0:length(x1)-1; x2 = input('Enter a finite-length signal sequence X2(n): '); n2 = 0:length(x2)-1; x= max(x1,x2); % Perform Cross - Correlation using xcorr function. rxy = xcorr(x1,x2); % rxy(l) ryx = xcorr(x2,x1); % ryx(l) % Generate Time Index for Cross - Correlation sequence, about origin n3 = -length(x)+1:length(x)-1; disp('Cross - Correlation Sequence rxy(l): '); disp(int8(rxy)); disp('Cross - Correlation Sequence ryx(l): '); disp(int8(ryx)); % Plot the Original Signal and Cross - Correlation Sequence subplot(3,1,1); stem(n1,x1); title('Input Signal 1'); xlabel('n'); ylabel('x1(n)'); subplot(3,1,2); stem(n2,x2); title('Input Signal 2'); xlabel('n'); ylabel('x2(n)'); subplot(3,1,3); stem(n3,rxy); title('Cross - Correlation Sequence'); xlabel('n'); ylabel('rxy(l)'); grid on; % Verifying Cross-correlation properties: E1 = sum(x1.^2); % Energy of signal 1. E2 = sum(x2.^2); % Energy of signal 2. mid = ceil(length(rxy)/2); % Find index of centre of sequence E0 = abs(max(rxy)); % Detect Max Amplitude of Sequence fprintf('Energy of Input Signal X1 : %dn',E1); fprintf('Energy of Input Signal X2 : %dn',E2); fprintf('Max Amplitude of Cross - Correlation Sequence : %dn',E0); % Verify Cross - Correlation Property by comparing Energy values % Max amplitude of Sequence should be less than sqrt(E1*E2). if int8(E0) <= int8(sqrt(E1*E2)) %Type conversion to 8-bit int disp('Cross - Correlation Energy Property is verified'); else disp('Cross - Correlation Energy Property is not verified'); end DSPLab-ECEDepartment,KSSEM
  • 23. DSP Laboratory (10ECL57) 5th Sem KSSEM, Bangalore Dept of ECE Page | 20 % Verify Signal property : rxy(l)=ryx(-l). if rxy == fliplr(ryx) disp('Since rxy(l) = ryx(-l), Cross - Correlation property is verified.'); else disp('Cross - Correlation property is not verified.'); end OUTPUT: Enter a finite-length signal sequence X1(n): [4 3 2 1] Enter a finite-length signal sequence X2(n): [1 2 3 4] Cross - Correlation Sequence rxy(l): 16 24 25 20 10 4 1 Cross - Correlation Sequence ryx(l): 1 4 10 20 25 24 16 Energy of Input Signal X1 : 30 Energy of Input Signal X2 : 30 Max Amplitude of Cross - Correlation Sequence : 25 Cross - Correlation Energy Property is verified Since rxy(l) = ryx(-l), Cross - Correlation property is verified. DSPLab-ECEDepartment,KSSEM
  • 24. DSP Laboratory (10ECL57) 5th Sem KSSEM, Bangalore Dept of ECE Page | 21 PROGRAM 7 SOLVING A GIVEN DIFFERENCE EQUATION Aim: To write the MATLAB code to solve a given difference equation, given the co-efficients and initial values. Let us consider the difference equation as y (n) – 3/2 y (n-1) + ½ y (n-2) = x (n). Given x(n) = (1/4)n *u(n). Assume initial conditions as y(-1) = 4, y(-2) = 10. Theory: Consider x(n) = (1/4)n *u(n). Let n take values from 0 to 5, n=0:5 n=0, x(0)=1 n=1, x(1)=0.25 n=2, x(2)=0.0625 n=3, x(3)=0.0156 n=4, x(4)=0.0039 n=5, x(5)=0.0010 For n=0; y(0) - 3/2 y(0-1) + 1/2 y(0-2) = x(0) Substituting the initial conditions and the value of x(0) in the above equation we get, y(0) = 1 + 6 - 5 = 2 Similarly, For n=1; y(1) = 0.25 + 3 - 2 = 1.2500 For n=2; y(2) = 0.0625 + 1.875 -1 = 0.9375 For n=3; y(3) = 0.0156 + 1.40625 - 0.625 = 0.7969 For n=4; y(4) = 0.0039 + 1.19535 - 0.46625 = 0.7365 For n=5; y(5) = 0.0010 + 1.09575 - 0.3982 = 0.6982 MATLAB CODE: %Experiment 7 : Difference Equation Solving clear all; close all; clc; %Accept Difference Equation Coefficients from Input b = input('Enter the coefficients of input x(n) : '); a = input('Enter the coefficients of output y(n) : '); y = input('Enter the initial conditions y(-1), y(-2),... : '); %Calculate Initial Conditions using filtic z = filtic(b,a,y); %Enter Input sequence samples. x = [1 1/4 1/16 1/64 1/256 1/1024]; n = 0:length(x)-1; %Time Base for plotting DSPLab-ECEDepartment,KSSEM
  • 25. DSP Laboratory (10ECL57) 5th Sem KSSEM, Bangalore Dept of ECE Page | 22 %Calculate output using initial conditions Yout = filter(b,a,x,z); %Display output sequence disp('Difference Equation Solution : y(n) : '); disp(Yout); %Plot Input and Output subplot(2,1,1); stem(n,x); title('Input Sequence x(n)'); xlabel('n'); ylabel('x(n)'); subplot(2,1,2); stem(n,Yout); grid on; title('Output Sequence y(n)'); xlabel('n'); ylabel('y(n)'); OUTPUT: Enter the coefficients of input x(n) : 1 Enter the coefficients of output y(n) : [1 -3/2 1/2] Enter the initial conditions y(-1), y(-2),... : [4 10] Difference Equation Solution : y(n) : 2.0000 1.2500 0.9375 0.7969 0.7305 0.6982 DSPLab-ECEDepartment,KSSEM
  • 26. DSP Laboratory (10ECL57) 5th Sem KSSEM, Bangalore Dept of ECE Page | 23 PROGRAM 8 COMPUTATION OF N- POINT DFT Aim: Computation of N point DFT of a given sequence and to plot magnitude and phase spectrum. Theory: DFT stands for Discrete Fourier Transform. It is used to find the amplitude and phase spectrum of a discrete time sequence. The N-point DFT of a finite-length sequence x(n) of length N, is given by X(k) as x(n) X(k) Basic equation to find the DFT of a sequence is given below. 𝑋(𝑘) = � 𝑥(𝑛)𝑒 −𝑗� 2𝜋 𝑁 �𝑘𝑛 𝑁−1 𝑛=0 For example: Find the DFT of the sequence x(n) = {0,1,2,3} In this case N=4. For k=0, 𝑋(0) = � 𝑥(𝑛)𝑒0 = 𝑥(0) + 𝑥(1) + 𝑥(2) + 𝑥(3) = 0 + 1 + 2 + 3 = 6 4−1 𝑛=0 For k=1, 𝑋(1) = � 𝑥(𝑛)𝑒 −𝑗� 2𝜋 𝑁 �𝑛 = 𝑥(1)𝑒 −𝑗� 2𝜋 4 �.0 + 𝑥(1)𝑒 −𝑗� 2𝜋 4 �1 + 𝑥(2)𝑒 −𝑗� 2𝜋 4 �2 + 𝑥(3)𝑒 −𝑗� 2𝜋 4 �3 4−1 𝑛=0 = - j- 2 + 3j = -2 + j2 Similarly, For k=2, 𝑋(2) = � 𝑥(𝑛)𝑒 −𝑗� 2𝜋 4 �2𝑛 = 𝑥(1)𝑒−𝑗𝜋.0 + 𝑥(1)𝑒−𝑗𝜋1 + 𝑥(2)𝑒−𝑗𝜋2 + 𝑥(3)𝑒−𝑗𝜋3 4−1 𝑛=0 = 0-1+2-3 = -2 For k=3, X(3) = -2 –j2 Hence, X(k) = {6, -2+j2, -2, -2-j2} N-DFT DSPLab-ECEDepartment,KSSEM
  • 27. DSP Laboratory (10ECL57) 5th Sem KSSEM, Bangalore Dept of ECE Page | 24 MATLAB CODE: %Experiment 8 : N-Point DFT clear all; close all; clc; %Accept Input sequence from user xn = input ('Enter the sequence x(n) : '); xn=xn'; N = length(xn); Xk = zeros(N, 1); %Initialize zero matrix for DFT sequence %Calculate DFT using formula n = 0:N-1; for k = 0:N-1 Xk(k+1) = exp(-j*2*pi*k*n/N)*xn; end %Display DFT Sequence disp('DSP Sequence : X(k) :'); disp(Xk); %Plot Signals n = 0:N-1; %Time base % Input Sequence subplot (2,2,[1:2]); stem(n, xn); title('Input Sequence x(n)'); xlabel('n');ylabel('x(n)'); % Output Magnitude Plot subplot (2,2,3); stem(n, abs(Xk)); grid on; title('Magnitude Plot of DFT : |X(k)|'); xlabel('n');ylabel('|X(k)|'); % Output Phase Plot subplot(2,2,4); stem(n, angle(Xk)'); grid on; title('Phase Plot of DFT : angle(X(k))'); xlabel('n');ylabel('Angle'); OUTPUT: Enter the sequence x(n) : [0 1 2 3] DSP Sequence : X(k) : 6.0000 -2.0000 + 2.0000i -2.0000 - 0.0000i -2.0000 - 2.0000i DSPLab-ECEDepartment,KSSEM
  • 28. DSP Laboratory (10ECL57) 5th Sem KSSEM, Bangalore Dept of ECE Page | 25 DSPLab-ECEDepartment,KSSEM
  • 29. DSP Laboratory (10ECL57) 5th Sem KSSEM, Bangalore Dept of ECE Page | 26 PROGRAM 9 LINEAR CONVOLUTION USING DFT AND IDFT Aim: To calculate the Linear Convolution of two sequences using DFT and IDFT Theory: An interesting property of the Discrete Fourier Transforms, is the effect it has on convolution. Convolution of two signals in the time domain translates to a multiplication of their Fourier transforms in the frequency domain. In this procedure, we find the discrete Fourier transforms of the individual signals, multiply them, and apply an Inverse Fourier Transform upon the product, to get the convolved signal in the time domain. If x(n) and h(n) are the two sequences of length ‘l’ and ‘m’ respectively. then X(k) and H(k) their DFT’s of length N=L+M-1. Y(k)=x(k)h(k) Therefore the linear convolution of two sequence is the N point IDFT of Y(k). Ex: Find the linear convolution of x(n)={1,2} and h(n)={1,2,3} using DFT and IDFT method. Soln: Given, x(n)={1,2} h(n)={1,2,3} here L = 2, M = 3 N=L+M-1 Therefore, N=4 x(n)={1,2,0,0} and h(n)={1,2,3,0} Finding X(k) using DIT FFT algorithm: X(k) = {3 , 1-2j , -1 , 1+2j } Finding H(k) using DIT FFT algorithm H(k) = {6 , -2-2j , 2 , -2+2j } Product Y(k) is calculated as : Y(k) = X(k)H(k) 𝑌(𝑘) = { 18 , −6 + 2j , −2 , 6 − 2j } Finding y(n) using DIT FFT algorithm: y(n) = { 1 , 4 , 7 , 6 } DSPLab-ECEDepartment,KSSEM
  • 30. DSP Laboratory (10ECL57) 5th Sem KSSEM, Bangalore Dept of ECE Page | 27 MATLAB CODE % Experiment 9 : Linear Convolution using Fourier Transforms clear all; close all; clc; %Accept input sequences x1 = input('Enter Input Sequence for Signal x1(n): '); n1 = length(x1); x2 = input('Enter Input Sequence for Signal x2(n): '); n2=length(x2); N = n1+n2-1; % Length of convolved sequence T = 1:N; %Calculate N-point DFT and IDFT. y1=fft(x1,N); % N-point DFT of x1 y2=fft(x2,N); % N-point DFT of x2 y3=y1.*y2; % Multiplication in time domain y=ifft(y3,N); % N-point IDFT of y to recover result % Plot Input and Output Sequences: subplot(3,1,1); stem(T,x1); title('Input Signal x1(n)'); xlabel('n'); ylabel('x1(n)'); subplot(3,1,2); stem(T,x2); title('Input Signal x2(n)'); xlabel('n'); ylabel('x2(n)'); subplot(3,1,3); stem(T,y); title('Convolved Signal y(n) = x1(n)*x2(n)'); xlabel('n'); ylabel('y(n)'); % Display the convolved Sequence in Command Window disp('Convolved sequence:'); disp(y); OUTPUT Enter Input Sequence for Signal x1(n): [1 2] Enter Input Sequence for Signal x2(n): [1 2 3] Convolved sequence: 1 4 7 6 DSPLab-ECEDepartment,KSSEM
  • 31. DSP Laboratory (10ECL57) 5th Sem KSSEM, Bangalore Dept of ECE Page | 28 DSPLab-ECEDepartment,KSSEM
  • 32. DSP Laboratory (10ECL57) 5th Sem KSSEM, Bangalore Dept of ECE Page | 29 PROGRAM 10 CIRCULAR CONVOLUTION USING DFT AND IDFT Aim: To calculate the Circular Convolution of two sequences using DFT and IDFT Theory: Convolution in time domain corresponds to multiplication in frequency domain. To make use of this property, we can calculate the DTFT of each of the aperiodic signals, multiply these in the frequency domain, and find the IDFT of the product, to get the periodic convolved signal in time domain. Example: Find the circular convolution of x(n)={1,2,3,4} and h(n)={4,3,2} using DFT and IDFT method. Solution: Given two signals, x(n)={1,2,3,4} and h(n)={4,3,2} Finding X(k) using DIT FFT algorithm X(k) = {10 , -2-2j , -2 , -2-2j } Finding H(k) using DIT FFT algorithm H(k) = { 9 , 2-3j , 3 , 2+3j } Y(k) = X(k)H(k) Y(k) ={ 90 , 2+10j , -6 , 2-10j } Finding y(n) using DIT FFT algorithm y(n) = { 22 , 19 , 20 , 29 } MATLAB CODE % Experiment 10 - Circular Convolution using Fourier Transforms clear all; close all; clc; %Accept input sequences x1 = input('Enter Input Sequence for Signal x1(n): '); n1 = length(x1); x2 = input('Enter Input Sequence for Signal x2(n): '); n2=length(x2); N=max(n1,n2); % Length of convolved sequence T = 1:N; x1=[x1 zeros(1,N-n1)]; x2=[x2 zeros(1,N-n2)]; DSPLab-ECEDepartment,KSSEM
  • 33. DSP Laboratory (10ECL57) 5th Sem KSSEM, Bangalore Dept of ECE Page | 30 %Calculate N-point DFT and IDFT. y1=fft(x1,N); % N-point DFT of x1 y2=fft(x2,N); % N-point DFT of x2 y3=y1.*y2; % Multiplication in time domain y=ifft(y3,N); % N-point IDFT of y to recover result % Plot Input and Output Sequences: subplot(3,1,1); stem(T,x1); title('Input Signal x1(n)'); xlabel('n'); ylabel('x1(n)'); subplot(3,1,2); stem(T,x2); title('Input Signal x2(n)'); xlabel('n'); ylabel('x2(n)'); subplot(3,1,3); stem(T,y); title('Convolved Signal y(n) = x1(n)*x2(n)'); xlabel('n'); ylabel('y(n)'); grid on; % Display the convolved Sequence in Command Window disp('Convolved sequence:'); disp(y); OUTPUT Enter Input Sequence for Signal x1(n): [1 2 3 4] Enter Input Sequence for Signal x2(n): [4 3 2] Convolved sequence: 22 19 20 29 DSPLab-ECEDepartment,KSSEM
  • 34. DSP Laboratory (10ECL57) 5th Sem KSSEM, Bangalore Dept of ECE Page | 31 DSPLab-ECEDepartment,KSSEM
  • 35. DSP Laboratory (10ECL57) 5th Sem KSSEM, Bangalore Dept of ECE Page | 32 PROGRAM 11 DESIGN AND IMPLEMENTATION OF FIR FILTER Aim: To design and implement a FIR Filter for the given specifications. Theory: A linear-phase is required throughout the passband of the filter to preserve the shape of the given signal in the passband. A causal IIR filter cannot give linear-phase characteristics and only special types of FIR filters that exhibit center symmetry in its impulse response give the linear-space. An FIR filter with impulse response h(n) can be obtained as follows: h(n) = hd(n) 0≤n≤N-1 = 0 otherwise ……………….(a) The impulse response hd(n) is truncated at n = 0, since we are interested in causal FIR Filter. It is possible to write above equation alternatively as h(n) = hd(n)w(n) ……………….(b) where w(n) is said to be a rectangular window defined by w(n) = 1 0≤n≤N-1 = 0 otherwise Taking DTFT on both the sides of equation(b), we get H(ω) = Hd(ω)*W(ω) Hamming window: The impulse response of an N-term Hamming window is defined as follows: 𝑤 𝐻𝑎𝑚(𝑛) = � 0.54 – 0.46𝑐𝑜𝑠(2п𝑛 / (𝑁 − 1)) 0 ≤ 𝑛 ≤ 𝑁 − 1 0 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒 Problem: Using MATLAB design an IIR filter to meet the following specifications choosing Hamming window: • Window length, N = 27 • Stop band attenuation = 50dB • Cut-off frequency = 100 Hz • Sampling frequency = 1000 Hz DSPLab-ECEDepartment,KSSEM
  • 36. DSP Laboratory (10ECL57) 5th Sem KSSEM, Bangalore Dept of ECE Page | 33 MATLAB CODE % Experiment 11 : Designing a FIR Filter (Hamming Window) close all; clear all; clc; % Accept Filter Parameters from User N = input('Enter the window length N : '); fc = input('Enter the cut-off frequency fc (Hz) : '); Fs = input('Enter the sampling frequency Fs (Hz) : '); Wc = 2*fc/ Fs; %Nyquist Frequency Wh = hamming(N); %Create a N-point symmetric Hamming window % Generate a FIR filter based on Hamming Window created b = fir1(N-1, Wc ,Wh); % Calculate Frequency Response of Filter designed. % h - Frequency Response values w = Frequencies [h,w] = freqz(b,1,256); mag = 20*log10(abs(h)); %Magnitude of Response % Display Values disp('Hamming Window Co-efficients : '); disp(Wh); disp('Unit Sample Response of FIR Filter h(n) : '); disp(b); % Plot Frequency response of Butterworth Filter. freqz(b); title('Hamming Filter Frequency Response'); OUTPUT Enter the window length N : 27 Enter the cut-off frequency fc (Hz) : 100 Enter the sampling frequency Fs (Hz) : 1000 Hamming Window Co-efficients : 0.0800 0.0934 0.1327 0.1957 0.2787 0.3769 0.4846 0.5954 0.7031 0.8013 DSPLab-ECEDepartment,KSSEM
  • 37. DSP Laboratory (10ECL57) 5th Sem KSSEM, Bangalore Dept of ECE Page | 34 0.8843 0.9473 0.9866 1.0000 0.9866 0.9473 0.8843 0.8013 0.7031 0.5954 0.4846 0.3769 0.2787 0.1957 0.1327 0.0934 0.0800 Unit Sample Response of FIR Filter h(n) : Columns 1 through 7 0.0019 0.0023 0.0022 -0.0000 -0.0058 -0.0142 -0.0209 Columns 8 through 14 -0.0185 0.0000 0.0374 0.0890 0.1429 0.1840 0.1994 Columns 15 through 21 0.1840 0.1429 0.0890 0.0374 0.0000 -0.0185 -0.0209 Columns 22 through 27 -0.0142 -0.0058 -0.0000 0.0022 0.0023 0.0019 DSPLab-ECEDepartment,KSSEM
  • 38. DSP Laboratory (10ECL57) 5th Sem KSSEM, Bangalore Dept of ECE Page | 35 DSPLab-ECEDepartment,KSSEM
  • 39. DSP Laboratory (10ECL57) 5th Sem KSSEM, Bangalore Dept of ECE Page | 36 PROGRAM 12 DESIGN AND IMPLEMENTATION OF IIR FILTER Aim: To design and implement a IIR Filter for the given specifications. Theory: A desired frequency response is approximated by a transfer function expressed as a ratio of polynomials. This type of transfer function yields an impulse response of infinite duration. Therefore, the analog filters are commonly referred to as infinite impulse response (IIR) filters. The main classes of analog filters are - 1.Butterworth Filter. 2.Chebyshev Filter. These filters differ in the nature of their magnitude responses as well as in their design and implementation. BUTTERWORTH FILTERS: Butterworth filters have very smooth passband, which we pay for with a relatively wide transition region. A Butterworth filter is characterized by its magnitude frequency response, | 𝐻(𝑗𝛺) | = 1 / [1 + (𝛺/𝛺𝑐)2𝑁]1/2 where N is the order of the filter and Ωc is defined as the cutoff frequency where the filter magnitude is 1/√2 times the dc gain (Ω=0) DSPLab-ECEDepartment,KSSEM
  • 40. DSP Laboratory (10ECL57) 5th Sem KSSEM, Bangalore Dept of ECE Page | 37 Butterworth filter tables N=1; (s + 1) N=2; (s2 +0.5 s +1) N=3; (s2 +s+1)(s+1) N=4; (s2 +0.76536s+1)(s2 +1.864776s+2) N=5; (s+1)( s2 +0.6180s+1)( s2 +1.6180s+1) CHEBYSHEV FILTERS: Chebyshev filters are equiripple in either the passband or stopband. Hence the magnitude response oscillates between the permitted minimum and maximum values in the band a number of times depending upon the order of filters. There are two types of chebyshev filters. The chebyshev I filter is equiripple in passband and monotonic in the stopband, whereas Chebyshev II is just the opposite. The Chebyshev low-pass filter has a magnitude response given by DSPLab-ECEDepartment,KSSEM
  • 41. DSP Laboratory (10ECL57) 5th Sem KSSEM, Bangalore Dept of ECE Page | 38 PROBLEM 1: BUTTERWORTH FILTER: Using MATLAB design an IIR filter with passband edge frequency 1500Hz and stop band edge at 2000Hz for a sampling frequency of 8000Hz, variation of gain within pass band 1db and stopband attenuation of 15 db. Use Butterworth prototype design and Bilinear Transformation. MATLAB CODE : % Experiment 12 : Design of IIR Filter (Butterworth Filter) clear all; close all; clc; % Accept Input Parameters from user Rp = input('Enter Passband Attenuation in dB : '); Rs = input('Enter Stopband Attenuation in dB : '); fp = input('Enter Passband Frequency in Hz : '); fs = input('Enter Stopband Frequency in Hz : '); Fs = input('Enter Sampling Frequency in Hz : '); % Calculate Sampled Frequency values Wp=2* fp / Fs ; Ws=2* fs / Fs ; % Calculate Butterworth filter order and cutoff frequency: % N = Minimum order of Filter Wn = Cutoff Frequencies [N,Wn] = buttord(Wp,Ws,Rp,Rs); % Butterworth Filter Design (z = zeros p = poles) [z,p] = butter(N,Wn); % Display Filter parameters : disp('Order of Butterworth Filter : '); disp(N); disp('Butterworth Window Cutoff Frequency : '); disp(Wn); % Plot Frequency Response of Filter freqz(z,p); title('Butterworth frequency response'); OUTPUT: Enter Passband Attenuation in dB : 1 Enter Stopband Attenuation in dB : 15 Enter Passband Frequency in Hz : 1500 Enter Stopband Frequency in Hz : 2000 Enter Sampling Frequency in Hz : 8000 Order of Butterworth Filter : DSPLab-ECEDepartment,KSSEM
  • 42. DSP Laboratory (10ECL57) 5th Sem KSSEM, Bangalore Dept of ECE Page | 39 6 Butterworth Window Co-efficient : 0.4104 PROBLEM 2: CHEBYSHEV FILTER: Using MATLAB design an IIR filter with passband edge frequency 1500Hz and stop band edge at 2000Hz for a sampling frequency of 8000Hz, variation of gain within pass band 1 db and stopband attenuation of 15 db. Use Chebyshev prototype design and Bilinear Transformation. DESIGN: W1 = (2*pi* F1 )/ Fs = 2*pi*100)/4000 = 0.05Π rad W2 = (2*pi* F2 )/ Fs = 2*pi*500)/4000 =0.25Π rad Prewarp: T=1sec Ω1 = 2/T tan (w1/2) = 0.157 rad/sec Ω2 = 2/T tan (w2/2) = 0.828 rad/sec Order: DSPLab-ECEDepartment,KSSEM
  • 43. DSP Laboratory (10ECL57) 5th Sem KSSEM, Bangalore Dept of ECE Page | 40 έ =�10− 𝐴𝑝 10 − 1 έ = 0.765 A= 10-As/20 , A = 1020/20 , A=10 g= (A2 - 1) / έ , g = 13.01 Ωr= Ω2 / Ω1 Ωr=0.828/0.157 = 5.27 radsec n = log10 �𝐠 + �(𝐠𝟐 − 𝟏) � / log10{Ωr + √(𝜴 𝒓 𝟐 – 𝟏) } n= 1.388 Therefore n= 2. Cut-off Frequency: Ωc = Ωp = Ω1 = 0.157 radsec Normalized Transfer Function: H(s)=[bo / 1+ έ2 ] / [ s2 +b1s+b0] = 0.505/[ s2 +0.8s+0.036] Denormalized Transfer Function: H(s)= Hn(s) |s-s/Ωc H(s)= Hn(s) |s-s/0.157 H(s) = 0.0125 / [s2 +0.125s+0.057] Apply BLT: H(Z) = H(s)|s=(2/T)[(1-z-1)/(1+z-1)] H(Z) = 0.0125+0.025Z-1 + 0.0125 Z-2 4.2769-7.96Z-1 + 3.76Z-2 H(Z) = 0.0029+0.0052Z-1 + 0.0029 Z-2 1-1.86Z-1 + 0.88Z-2 DSPLab-ECEDepartment,KSSEM
  • 44. DSP Laboratory (10ECL57) 5th Sem KSSEM, Bangalore Dept of ECE Page | 41 MATLAB CODE: % Experiment 12B : Design of IIR Filter (Chebyshev Filter) clear all; close all; clc; % Accept Input Parameters from user Rp = input('Enter Passband Attenuation in dB : '); Rs = input('Enter Stopband Attenuation in dB : '); fp = input('Enter Passband Frequency in Hz : '); fs = input('Enter Stopband Frequency in Hz : '); Fs = input('Enter Sampling Frequency in Hz : '); % Calculate Sampled Frequency values Wp=2* fp / Fs ; Ws=2* fs / Fs ; % Calculate Chebyshev filter order and cutoff Frequency: % N = Minimum order of Filter Wn = Cutoff Frequencies [N,Wn]=cheb1ord(Wp,Ws,Rp,Rs); % Chebyshev Filter Design (z = zeros p = poles) [z,p]=cheby1(N,Rp,Wn); % Display Filter parameters : disp('Order of Chebyshev Filter : '); disp(N); disp('Chebyshev Window Cutoff Frequency : '); disp(Wn); % Plot Frequency Response of Filter : freqz(z,p); title('Chebyshev Frequency response'); OUTPUT: Enter Passband Attenuation in dB : 1 Enter Stopband Attenuation in dB : 15 Enter Passband Frequency in Hz : 1500 Enter Stopband Frequency in Hz : 2000 Enter Sampling Frequency in Hz : 8000 Order of Chebyshev Filter : 4 Chebyshev Window Cutoff Frequency : 0.3750 DSPLab-ECEDepartment,KSSEM
  • 45. DSP Laboratory (10ECL57) 5th Sem KSSEM, Bangalore Dept of ECE Page | 42 DSPLab-ECEDepartment,KSSEM
  • 46. DSP Laboratory (10ECL57) 5th Sem KSSEM, Bangalore Dept of ECE Page | 43 PART B: Exercises using the DSP Kit DSPLab-ECEDepartment,KSSEM
  • 47. DSP Laboratory (10ECL57) V Semester KSSEM, Bangalore Dept of ECE Page | 44 TMS320C6748 DSP BOARD Package content: The C6748 DSP Experimenter Kit packaged for Universities (TMDSEXPL138-UNV) provides everything academics need to get started with teaching and projects using the TI TMS320C6000 DSP. The TI TMS320C6000 family of DSPs is popular for use in Real-time DSP coursesThe Experimenter Kit for Universities is a low-cost, flexible development platform for the OMAP-L138 which is a low-power dual core processor based on C6748 DSP plus an ARM926EJ-S 32-bit RISC MPU. The C6748 DSP kit has a TMS320C6748 DSP onboard that allows full-speed verification of code with Code Composer Studio. The C6748 DSP kit provides: A USB Interface 128MB DDRAM and ROM An analog interface circuit for Data conversion (AIC) An I/O port Embedded JTAG emulation support Connectors on the C6748 DSP kit provide DSP external memory interface (EMIF) and peripheral signals that enable its functionality to be expanded with custom or third party daughter boards. DSPLab-ECEDepartment,KSSEM
  • 48. DSP Laboratory (10ECL57) V Semester KSSEM, Bangalore Dept of ECE Page | 45 The C6748 DSP kit includes a stereo codec. This analog interface circuit (AIC) has the following characteristics: High-Performance Stereo Codec • Interfaces directly to digital or analog microphones • Supports 8-96 ksps sampling rates • High SNR (100-102dB DAC, 92dB ADC) • Integrated PLL supporting a wide range of audio clocks • Low-power headphone, speaker and playback modes for portable systems • Programmable digital audio effectsinclude 3D sound, bass, treble, EQ and de-emphasis Software Control Via TI McASP-Compatible Multiprotocol Serial Port.Glueless Interface to TI McASPs. Audio-Data Input/Output Via TI McASP-Compatible Programmable Audio Interface 16/20/24/32-Bit Word Lengths. The C6748DSP kit has the following features: The 6748 DSP KIT kit is a low-cost standalone development platform that enables customers to evaluate and develop applications for the TI C67XX DSP family. The DSP KIT also serves as a hardware reference design for the TMS320C6748 DSP. Schematics, logic equations and application notes are available to ease hardware development and reduce time to market. An on-board AIC3106 codec allows the DSP to transmit and receive analog signals. McASP is used for the codec control interface and for data. Analog audio I/O is done through two 3.5mm audio jacks that correspond to line input, and line. The analog output is driven to the line out .McASP1 can be re-routed to the expansion connectors in software. The DSP KIT includes 2 LEDs and 8 DIP switches as a simple way to provide the user with interactive feedback. An included 5V external power supply is used to power the board. On-board voltage regulators provide the 1.26V DSP core voltage, 3.3V digital and 3.3V analog voltages. A voltage supervisor monitors the internally generated voltage, and will hold the board in reset until the supplies are within operating specifications and the reset button is released. Code Composer communicates with the DSP KIT through an embedded JTAG emulator with a USB host interface. The DSP KIT can also be used with an external emulator through the external JTAG connector. TMS320C6748 DSP Features  Highest-Performance Floating-Point Digital Signal Processor (DSP):  Eight 32-Bit Instructions/Cycle DSPLab-ECEDepartment,KSSEM
  • 49. DSP Laboratory (10ECL57) V Semester KSSEM, Bangalore Dept of ECE Page | 46  32/64-Bit Data Word  375/456-MHz C674x Fixed/Floating-Point  Up to 3648/2746 C674x MIPS/MFLOPS  Rich Peripheral Set, Optimized for Audio  Highly Optimized C/C++ Compiler  Extended Temperature Devices Available  Advanced Very Long Instruction Word (VLIW) TMS320C67x™ DSP Core  Eight Independent Functional Units:  Two ALUs (Fixed-Point)  Four ALUs (Floating- and Fixed-Point)  Two Multipliers (Floating- and Fixed-Point)  Load-Store Architecture With 64 32-Bit General-Purpose Registers  Instruction Packing Reduces Code Size  All Instructions Conditional  Instruction Set Features  Native Instructions for IEEE 754  Single- and Double-Precision  Byte-Addressable (8-, 16-, 32-Bit Data)  8-Bit Overflow Protection  Saturation; Bit-Field Extract, Set, Clear; Bit-Counting; Normalization  67x cache memory.  32K-Byte L1P Program Cache (Direct-Mapped)  32K-Byte L1D Data Cache (2-Way)  256K-Byte L2 unified Memory RAMCache.  Real-Time Clock With 32 KHz Oscillator and Separate Power Rail.  Three 64-Bit General-Purpose Timers  Integrated Digital Audio Interface Transmitter (DIT) Supports:  S/PDIF, IEC60958-1, AES-3, CP-430 Formats  Up to 16 transmit pins  Enhanced Channel Status/User Data  Extensive Error Checking and Recovery  Two Inter-Integrated Circuit Bus (I 2 C Bus™) .  3 64-Bit General-Purpose Timers (each configurable as 2 32-bit timers)  Flexible Phase-Locked-Loop (PLL) Based Clock Generator Module  IEEE-1149.1 (JTAG ) Boundary-Scan-Compatible  3.3-V I/Os, 1.2 -V Internal (GDP & PYP)  3.3-V I/Os, 1.4-V Internal (GDP)(300 MHz only)  LCD Controller  Two Serial Peripheral Interfaces (SPI) Each With Multiple Chip-Selects  Two Multimedia Card (MMC)/Secure Digital (SD) Card Interface with Secure Data I/O (SDIO) Interfaces  One Multichannel Audio Serial Port.  Two Multichannel Buffered Serial Ports DSPLab-ECEDepartment,KSSEM
  • 50. DSP Laboratory (10ECL57) V Semester KSSEM, Bangalore Dept of ECE Page | 47 General Procedure to work on Code Composer Studio V4 for non-real time projects 1. Launch ccs Launch the CCS v4 icon from the Desktop or goto All Programs ->Texas Instruments - >CCSv4 2. Choose the location for the workspace, where your project will be saved. 3. Click the CCS icon from the welcome page to go the workbench, it is marked in the below picture. DSPLab-ECEDepartment,KSSEM
  • 51. Dept of ECE Page | 48 * 4. Configure ccs to your target A. From the Target menu select New target Configuration Target -> New target Configuration. It will open a window like given below. Specify any arbitrary target name. For Eg., 6748config.ccxml (Extension should be .ccxml).. Click Finish then you will get configuration window for the created target. B. 1. Select the Connection: Texas instruments XDS100v1 USB Emulator 2. Select the Device: TMS320C6748. To make search easier type 6748 in device block. Check the box TMS320C674 8 and finally Click Save. DSPLab-ECEDepartment,KSSEM
  • 52. Dept of ECE Page | 49 C. Next goto Advanced tab give the suitable Gel file path as shown below. Follow the path. “C:6748supportc6748.gel” D. Go to view option and select the Target Configuration: View->Target Configuration. A wizard will open in the workspace expand the User Defined folder and you can find your target, Right click on 6748config.ccxml and select the Launch Selected Configuration. E. Connect CCS to the target Goto Target -> Connect Target Now our target is successfully configured and connected. In future we no need to repeat these steps. If we are working with the same hardware we can just open the already configured target and launch the selected configuration and connect it. DSPLab-ECEDepartment,KSSEM
  • 53. Dept of ECE Page | 50 5. Creating the New Project Step P1: Change the Perspective Debug to C/C++ from the right corner of the CCS Step P2: Go to File  New  CCS Project. Step P3: Specify the name of the project in the space provided .and Click Next Eg., Project Name: Hello World DSPLab-ECEDepartment,KSSEM
  • 54. Dept of ECE Page | 51 Select the project type Project Type: C6000 Click Next *However our target is based on C6000 family, Based on the family we need to select the Project Type. Set the project settings window as shown below. Click finish DSPLab-ECEDepartment,KSSEM
  • 55. Dept of ECE Page | 52 6. To write the program select one new file. A.Go to File  New  Source File. B. Specify the arbitrary source file name. It should be in the source folder (current project name.). Note: Extension of the source file must be the language what we preferred to write the code. Eg: For c-> .c C++ -> .cpp Assembly -> .asm C.Type your C – Code DSPLab-ECEDepartment,KSSEM
  • 56. Dept of ECE Page | 53 7. BUILD Build the program to check your code Have any errors and warnings. Go to Project  Build active project. If your code doesn‟t have any errors and warnings, a message will be printed in the console window that “Build Complete for the project” Problems window display errors or warnings, if any. DSPLab-ECEDepartment,KSSEM
  • 57. Dept of ECE Page | 54 8. DEBUG After successful Build, Debug your code. During this step ccs will connect to target and it will load program on to target. Goto Target  Debug Active project. During debug ccs will display following error message. Now press reset button on the 6748 hardware , then click on retry. Once you click on retry ccs will load program on to processor and then ccs will guide us to debug mode, if it is not done automatically. Change the Perspective C/C++ to Debug from the right corner of the CCS. DSPLab-ECEDepartment,KSSEM
  • 58. Dept of ECE Page | 55 9.RUN Now you can run the code, by selecting the option run from the dialog box else you can Go to Target  Run Once you run the program the output will be printed in the Console DSPLab-ECEDepartment,KSSEM
  • 59. DSP Laboratory (10ECL57) V Semester KSSEM, Bangalore Dept of ECE Page | 56 PROGRAM 1 LINEAR CONVOLUTION OF TWO GIVEN SEQUENCES Aim: To write the C code to perform Linear Convolution upon two given discrete time signals. C Code: /* PROGRAM TO IMPLEMENT LINEAR CONVOLUTION */ #include<stdio.h> int y[20]; main() { int m=6; /*Length of i/p samples sequence*/ int n=6; /*Length of impulse response Coefficients*/ int i=0,j; /*Input Signal Samples*/ int x[15]={1,2,3,4,5,6,0,0,0,0,0,0}; /*Impulse Response Coefficients*/ int h[15]={1,2,3,4,5,6,0,0,0,0,0,0}; /*Calculate Values*/ for(i=0;i<m+n-1;i++) { y[i]=0; for(j=0;j<=i;j++) y[i]+=x[j]*h[i-j]; } /* Display Values*/ printf("Sequence 1: n"); for(i=0;i<m;i++) printf("%dt",x[i]); printf("nSequence 2: n"); for(i=0;i<n;i++) printf("%dt",h[i]); printf("nConvolved Sequence: n"); for(i=0;i<m+n-1;i++) printf("%dt",y[i]); } DSPLab-ECEDepartment,KSSEM
  • 60. DSP Laboratory (10ECL57) V Semester KSSEM, Bangalore Dept of ECE Page | 57 OUTPUT: Sequence 1: 1 2 3 4 5 6 Sequence 2: 1 2 3 4 5 6 Convolved Sequence: 1 4 10 20 35 56 70 76 73 60 36 Procedure: 1. Open Code Composer Studio v4. 2. Connect the target (step 4). 3. Create new project with name as sine wave (step 5). 4. Create new source file and type the code linear.c and save it.(step 6) 5. Now perform steps 7, 8and 9.Once you run the program you can watch convolution result in the console window. 6. To view the values in graph a. Go to Tools  Graph  Single Time 7. Set the Graph Properties as shown Buffer size : 11 DSP Data Type : 16-Bit Unsigned Int Start Address: y Display Data Size : 11 8. Click : Ok 9. Note down the output waveform. NOTE : Follow the same procedure for the rest of the experiments. DSPLab-ECEDepartment,KSSEM
  • 61. DSP Laboratory (10ECL57) V Semester KSSEM, Bangalore Dept of ECE Page | 58 PROGRAM 2: CIRCULAR CONVOLUTION OF TWO GIVEN SEQUENCES Aim: To write the C code to perform Circular Convolution upon two given discrete time signals. C Code: /* PROGRAM TO IMPLEMENT CIRCULAR CONVOLUTION */ #include<stdio.h> int m,n,x[30],h[30],y[30],i,j,temp[30],k,x2[30],a[30]; void main() { printf("Enter the length of the first sequencen"); scanf("%d",&m); printf("nEnter the length of the second sequencen"); scanf("%d",&n); printf("nEnter the first sequencen"); for(i=0;i<m;i++) scanf("%d",&x[i]); printf("nEnter the second sequencen"); 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; } /*Initialize Array of Zeros*/ for(i=m;i<n;i++) x[i]=0; m=n; } /* Convert linear sequence to circular sequence*/ y[0]=0; a[0]=h[0]; for(j=1;j<n;j++) /* folding h(n) to h(-n) */ a[j]=h[n-j]; DSPLab-ECEDepartment,KSSEM
  • 62. DSP Laboratory (10ECL57) V Semester KSSEM, Bangalore Dept of ECE Page | 59 /*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("nConvolved Sequence:n"); for(i=0;i<n;i++) printf("%d t",y[i]); } OUTPUT: Enter the length of the first sequence 4 Enter the length of the second sequence 4 Enter the first sequence 2 1 2 1 Enter the second sequence 1 2 3 4 Convolved Sequence: 14 16 14 16 DSPLab-ECEDepartment,KSSEM
  • 63. DSP Laboratory (10ECL57) V Semester KSSEM, Bangalore Dept of ECE Page | 60 PROGRAM 3: COMPUTATION OF N- POINT DFT OF A GIVEN SEQUENCE Aim: Computation of N point DFT of a given sequence. C Code: #include<stdio.h> #include<math.h> int N,k,n,i; float pi=3.1416,sumre=0, sumim=0,out_real[8]={0.0}, out_imag[8]={0.0}; int x[32]; void main(void) { printf("Enter the length of the sequencen"); scanf("%d",&N); printf("nEnter the sequencen"); for(i=0;i<N;i++) scanf("%d",&x[i]); for(k=0;k<N;k++) { sumre=0; sumim=0; for(n=0;n<N;n++) { sumre=sumre+x[n]* cos(2*pi*k*n/N); sumim=sumim-x[n]* sin(2*pi*k*n/N); } out_real[k]=sumre; out_imag[k]=sumim; printf("DFT of the Sequence :n"); printf("X([%d])=t%ft+t%fin",k,out_real[k],out_imag[k]); } } DSPLab-ECEDepartment,KSSEM
  • 64. DSP Laboratory (10ECL57) V Semester KSSEM, Bangalore Dept of ECE Page | 61 OUTPUT: Enter the length of the sequence 4 Enter the sequence 0 1 2 3 DFT of the Sequence 6.0 -2.0 + 2.0i -2.0 - 0.0i -2.0 - 2.0i DSPLab-ECEDepartment,KSSEM
  • 65. DSP Laboratory (10ECL57) V Semester KSSEM, Bangalore Dept of ECE Page | 62 PROGRAM 4: IMPULSE RESPONSE OF FIRST ORDER AND SECOND ORDER SYSTEM Aim: To Calculate the Impulse Response of the First Order and Second Order Systems. 1. First Order System: C Code: #include <stdio.h> #define Order 1 /*First Order Filter*/ #define Len 10 /*Length of Impulse Response*/ float y[Len] = {0,0,0}, sum; main() { int j,k; float b[Order+1]={1, 3}; /*Input Coefficients*/ float a[Order+1]={1, 0.2}; /*Output Coefficients*/ printf("Impulse Response Coefficients:n"); for(j=0;j<Len;j++) { sum = 0; for (k=1;k<=Order;k++) { if ((j-k)>=0) sum=sum+(b[k]*y[j-k]); } if(j<=Order) y[j]=a[j]-sum; else y[j]=-sum; printf("Response [%d] = %fn",j,y[j]); } } OUTPUT: Impulse Response Coefficients: Response [0] = 1.000000 Response [1] = -2.800000 Response [2] = 8.400000 Response [3] = -25.199999 Response [4] = 75.599998 Response [5] = -226.799988 Response [6] = 680.399963 Response [7] = -2041.199951 Response [8] = 6123.599609 Response [9] = -18370.798828 DSPLab-ECEDepartment,KSSEM
  • 66. DSP Laboratory (10ECL57) V Semester KSSEM, Bangalore Dept of ECE Page | 63 2. Second Order System: C Code: #include <stdio.h> #define Order 2 /*Second Order Filter*/ #define Len 10 /*Length of Impulse Response*/ float y[Len] = {0,0,0}, sum; main() { int j,k; float b[Order+1]={1, 3, -0.12}; /*Input Coefficients*/ float a[Order+1]={1, 0.2, -1.5}; /*Output Coefficients*/ printf("Impulse Response Coefficients:n"); for(j=0;j<Len;j++) { sum = 0; for (k=1;k<=Order;k++) { if ((j-k)>=0) sum=sum+(b[k]*y[j-k]); } if(j<=Order) y[j]=a[j]-sum; else y[j]=-sum; printf("Response [%d] = %fn",j,y[j]); } } OUTPUT: Impulse Response Coefficients: Response [0] = 1.000000 Response [1] = -2.800000 Response [2] = 7.020000 Response [3] = -21.396000 Response [4] = 65.030403 Response [5] = -197.658722 Response [6] = 600.779785 Response [7] = -1826.058350 Response [8] = 5550.268555 Response [9] = -16869.933594 DSPLab-ECEDepartment,KSSEM
  • 67. DSP Laboratory (10ECL57) V Semester KSSEM, Bangalore Dept of ECE Page | 64 SAMPLE VIVA QUESTIONS: 1. What is sampling theorem? 2. What do you mean by process of reconstruction? 3. What are techniques of reconstructions? 4. What do you mean Aliasing? What is the condition to avoid aliasing for sampling? 5. Write the conditions of sampling. 6. How many types of sampling there? 7. Explain the statement- t= 0:0.000005:0.05 8. In the above example what does colon (:) and semicolon (;) denote? 9. What is a) Undersampling b) Nyquist Plot c) Oversampling. 10. Write the MATLAB program for Oversampling. 11. What is the use of command ‘legend’? 12. Write the difference between built in function, plot and stem describe the function. 13. What is the function of built in function and subplot? 14. What is linear convolution? 15. Explain how convolution syntax built in function works. 16. How to calculate the beginning and end of the sequence for the two sided controlled output? 17. What is the total output length of linear convolution sum. 18. What is an LTI system? 19. Describe impulse response of a function. 20. What is the difference between convolution and filter? 21. Where to use command filter or impz, and what is the difference between these two? 22. What is the use of function command ‘deconv’? 23. What is the difference between linear and circular convolution? 24. What do you mean by statement subplot (3,3,1). 25. What do you mean by command “mod” and where it is used? 26. What do you mean by Autocorrelation and Crosscorrelation sequences? 27. What is the difference between Autocorrelatio and Crsscorrelation. 28. List all the properties of autocorrelation and Crosscorrelaion sequence. 29. Where we use the inbuilt function ‘xcorr’ and what is the purpose of using this function? 30. How to calculate output of DFT using MATLAB? 31. What do you mean by filtic command, explain. 32. How to calculate output length of the linear and circular convolution. 33. What do you mean by built in function ‘fliplr’ and where we need to use this. 34. What is steady state response? 35. Which built in function is used to solve a given difference equation? 36. Explain the concept of difference equation. 37. Where DFT is used? DSPLab-ECEDepartment,KSSEM
  • 68. DSP Laboratory (10ECL57) V Semester KSSEM, Bangalore Dept of ECE Page | 65 38. What is the difference between DFT and IDFT? 39. What do you mean by built in function ‘abs’ and where it is used? 40. What do you mean by phase spectrum and magnitude spectrum/ give comparison. 41. How to compute maximum length N for a circular convolution using DFT and IDFT.(what is command). 42. Explain the statement- y=x1.*x2 43. What is FIR and IIR filter define, and distinguish between these two. 44. What is filter? 45. What is window method? How you will design an FIR filter using window method. 46. What are low-pass and band-pass filter and what is the difference between these two? 47. Explain the command : N = ceil(6.6 *pi/tb) 48. Write down commonly used window function characteristics. 49. What is the MATLAB command for Hamming window? Explain. 50. What do you mea by cut-off frequency? 51. What do you mean by command butter, cheby1? 52. Explain the command in detail- [N,wc]=buttord(2*fp/fs,2*fstp/fs,rp,As) 53. What is CCS? Explain in detail to execute a program using CCS. 54. Why do we need of CCS? 55. How to execute a program using ‘dsk’ and ‘simulator’? 56. Which IC is used in CCS? Explain the dsk, dsp kit. 57. What do you mean by noise? 58. Explain the program for linear convolution for your given sequence. 59. Why we are using command ‘float’ in CCS programs. 60. Where we use ‘float’ and where we use ‘int’? 61. Explain the command- i= (n-k) % N 62. Explain the entire CCS program in step by step of execution. 63. What is MATLAB? What does it stand for? DSPLab-ECEDepartment,KSSEM