DSP Lab Manual (10ECL57) - VTU Syllabus

69
 K. S. SCHOOL OF ENGINEERING & MANAGEMENT # 15, Mallas andra , Off Kanak apur a Road, Ban gal ore -56006 2, Kar nat aka , India. DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING Digit al Si gna l Processin g Lab Manual Sub Code: 10ECL57 Sem:V Prepared By Mr. Ravikiran B. A., Asst. Professor Mrs. Vidhya R., Asst. Professor

description

Lab Manual for DSP Lab (10ECL57), according to VTU Syllabus. Created by Mr. Ravikiran B. A. and Mrs. Vidhya R., Dept of ECE, KSSEM, Bangalore.

Transcript of DSP Lab Manual (10ECL57) - VTU Syllabus

# 15, Mallasandra, Off Kanakapura Road,
Bangalore-560062, Karnataka, India.
Sub Code: 10ECL57
Mrs. Vidhya R., Asst. Professor
 
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
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
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
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
Sem KSSEM, Bangalore
PROGRAM 1
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
( ) = −
 
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:
% Signal Parameters
f2 = 1900; % Signal 2 Frequency = 1.4 kHz
fmax = max(f1,f2); % Maximum frequency component of signal
T = 1/min(f1,f2); % Signal Period should cover entire length
t = 0:0.01*T:2*T; % Time index
% Generate the original signal and plot it:
x = cos(2*pi*t*f1)+ cos(2*pi*t*f2); % Composite Signal
subplot(2,2,1);
n1 = 0:1/fs1:2*T; % Time scale
x1 = cos(2*pi*f1*n1)+cos(2*pi*f2*n1); % Generating sampled signal
subplot(2,2,2);
stem(n1,x1);
n2 = 0:1/fs2:2*T;
subplot(2,2,3);
stem(n2,x2);
xlabel('n');
ylabel('x(n)');
Sem KSSEM, Bangalore
% Under Sampling Condition:
n3 = 0:1/fs3:2*T;
subplot(2,2,4);
stem(n3,x3);
xlabel('n');
ylabel('x(n)');
OUTPUT:
Sem KSSEM, Bangalore
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:
( ) = ( ) + ( − 1) + ( − 2) + ( − 1) + ( − 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 a 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:
[   −   ] =   [   −   ]
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:
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   ( ) − 0.12   ( ) =   ( ) + 0.2   ( ) − 1.5   ( )
 
Sem KSSEM, Bangalore
Transfer Function of the system can be obtained as :
( ) = ( )
By long division, we get:
( ) = 1 − 2.8 + 7.02 − 21.4 + 65.03
By taking Inverse-Z transform, we can obtain the Impulse Response as:
[ ] = [1 − 2.8 7.02 21.4 65.03]
MATLAB CODE:
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);
stem(t,h);
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:
Sem KSSEM, Bangalore
 
Sem KSSEM, Bangalore
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   ( ) and   ( ) 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:
 
Sem KSSEM, Bangalore
MATLAB CODE:
% Accept input signal sequences
%Perform Linear Convolution using CONV command
y=conv(x1,x2);
subplot(3,1,1);
stem(x1);
xlabel('n'); ylabel('y(n)');
disp('Convolved sequence:');
%% Linear Convolution without using CONV command
clear all; close all; clc;
x1 = input('Enter Input Sequence for Signal x1(n): ');
n1 = length(x1);
n2=length(x2);
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)];
y = zeros(1,N);
Sem KSSEM, Bangalore
for n = 1:N
end
end
subplot(3,1,1);
stem(T,x1);
xlabel('n'); ylabel('y(n)');
disp('Convolved sequence:');
Enter Input Sequence for Signal x1(n): [1 2 -1 3]
Enter Input Sequence for Signal x2(n): [2 3 -2]
Convolved sequence:
 
Sem KSSEM, Bangalore
 
Sem KSSEM, Bangalore
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  (   −   )
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:
For m = 2:
Sem KSSEM, Bangalore
For m = 3:
So, we get the circular convolution sum as:   ( ) = {14,16,14,16}
MATLAB CODE:
%% Circular Convolution using Formula
x1 = input('Enter Input Sequence for Signal x1(n): ');
n1 = length(x1);
n2=length(x2);
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)];
y = zeros(1,N);
from 1
if(i<=0)
end
end
subplot(3,1,1);
stem(T,x1);
Sem KSSEM, Bangalore
title('Input Signal x2(n)');
xlabel('n'); ylabel('y(n)');
disp('Convolved sequence:');
% Accept input signal sequences
n=max(length(x1),length(x2));
y=cconv(x1,x2,n);
subplot(3,1,1);
stem(x1);
xlabel('n'); ylabel('y(n)');
disp('Convolved sequence:');
Enter Input Sequence for Signal x1(n): [2 1 2 1]
Enter Input Sequence for Signal x2(n): [1 2 3 4]
Convolved sequence:
Sem KSSEM, Bangalore
 
Sem KSSEM, Bangalore
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, …
( ) =   ( ) (   −   )
| |
Assuming our signal is of the form   ( ) + ( − )
Energy in the signal is given by:
[   ( ) +   (   −   )] =   ( ) +   (   −   ) + 2   ( )   ( − )
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}
Sem KSSEM, Bangalore
Energy of the signal is given by:
= ( ) = 1 + 2 + 3 + 4 = 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.
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;
rxx = xcorr(x,x);
n2 = -length(x)+1:length(x)-1;
subplot(2,1,1);
stem(n,x);
mid = ceil(length(rxx)/2); % Find index of centre of sequence
E0 = rxx(mid); % Detect Amplitude of Sequence
midpoint
%d\n',E0);
disp('Autocorrelation Energy Property is verified');
else
end
rxx_r = rxx(mid:length(rxx)); %Right Side of AC Sequence
 
Sem KSSEM, Bangalore
rxx_l = rxx(mid:-1:1); %Left Side of AC Sequence
if rxx_r == rxx_l
else
verified.');
end
OUTPUT:
Autocorrelation Sequence :
Energy of Input Signal : 30
Amplitude of Midpoint of Autocorrelation Sequence : 30
Autocorrelation Energy Property is verified
Autocorrelation Sequence is Even. Hence, verified.
 
Sem KSSEM, Bangalore
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:
( ) =   ( ) (   −   )
| |
Assuming our signal is of the form   ( ) + ( − )
Energy in the signal is given by:
[   ( ) +   (   −   )] =   ( ) +   (   −   ) + 2   ( )   ( − )
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:
Sem KSSEM, Bangalore
MATLAB CODE:
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;
n2 = 0:length(x2)-1;
x= max(x1,x2);
rxy = xcorr(x1,x2); % rxy(l)
ryx = xcorr(x2,x1); % ryx(l)
n3 = -length(x)+1:length(x)-1;
subplot(3,1,1);
stem(n1,x1);
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 : %d\n',E1);
fprintf('Energy of Input Signal X2 : %d\n',E2);
fprintf('Max Amplitude of Cross - Correlation Sequence : %d\n',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
else
end
Sem KSSEM, Bangalore
if rxy == fliplr(ryx)
verified.');
else
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):
Cross - Correlation Sequence ryx(l):
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.
 
Sem KSSEM, Bangalore
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
Theory:
n=0:5
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,
MATLAB CODE:
%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); %Ignore if No Initial Conditions
%Enter Input sequence samples.
n = 0:length(x)-1; %Time Base for plotting
 
Sem KSSEM, Bangalore
Yout = filter(b,a,x,z); %Use filter(b,a,x) if no IC
%Display output sequence
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) :
0.6982
Sem KSSEM, Bangalore
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)
( ) =   ( )
For example: Find the DFT of the sequence x(n) = {0,1,2,3}
In this case N=4.
For k=0,
(0) =   ( )   =   (0) +   (1) +   (2) +   (3) = 0 + 1 + 2 + 3 = 6
For k=1,
Similarly,
= 0-1+2-3 = -2
For k=3,
X(3) = -2 –  j2
 
Sem KSSEM, Bangalore
MATLAB CODE:
xn = input ('Enter the sequence x(n) : ');
xn=xn';
N = length(xn);
%Calculate DFT using formula
end
xlabel('n');ylabel('|X(k)|');
xlabel('n');ylabel('Angle');
OUTPUT:
DSP Sequence : X(k) :
Sem KSSEM, Bangalore
 
Sem KSSEM, Bangalore
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}
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)
y(n) = { 1 , 4 , 7 , 6 }
 
Sem KSSEM, Bangalore
MATLAB CODE
clear all; close all; clc;
%Accept input sequences
n1 = length(x1);
n2=length(x2);
T = 1:N;
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(x1);
xlabel('n'); ylabel('y(n)');
disp('Convolved sequence:');
Enter Input Sequence for Signal x2(n): [1 2 3]
Convolved sequence:
Sem KSSEM, Bangalore
 
Sem KSSEM, Bangalore
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.
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(n) = { 22 ,19 , 20 , 29 }
MATLAB CODE
clear all; close all; clc;
%Accept input sequences
n1 = length(x1);
n2=length(x2);
T = 1:N;
Sem KSSEM, Bangalore
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(x1);
xlabel('n'); ylabel('y(n)'); grid on;
disp('Convolved sequence:');
Enter Input Sequence for Signal x1(n): [1 2 3 4]
Enter Input Sequence for Signal x2(n): [4 3 2]
Convolved sequence:
Sem KSSEM, Bangalore
 
Sem KSSEM, Bangalore
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:
Sem KSSEM, Bangalore
MATLAB CODE
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
b = fir1(N-1, Wc ,Wh);
[h,w] = freqz(b,1,256);
% Display Values
disp(b);
freqz(b);
Enter the cut-off frequency fc (Hz) : 100
Enter the sampling frequency Fs (Hz) : 1000
Hamming Window Co-efficients :
Sem KSSEM, Bangalore
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
Columns 1 through 7
Columns 8 through 14
Columns 15 through 21
Columns 22 through 27
 
Sem KSSEM, Bangalore
 
Sem KSSEM, Bangalore
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.
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,
 
Sem KSSEM, Bangalore
Butterworth filter tables
2 +1.864776s+2)
2 +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.
 
Sem KSSEM, Bangalore
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.
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 ;
% N = Minimum order of Filter Wn = Cutoff Frequencies
[N,Wn] = buttord(Wp,Ws,Rp,Rs);
[z,p] = butter(N,Wn);
freqz(z,p);
Order of Butterworth Filter :
Sem KSSEM, Bangalore
Butterworth Window Co-efficient :
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:
 
Sem KSSEM, Bangalore
Order:
-As/20 , A = 10
20/20 , A=10
g= (A2 - 1) / , g = 13.01 Ωr= Ω2 / Ω1 Ωr=0.828/0.157 = 5.27 rad \sec
n = log10   + ( − )  / log10{Ωr + √( – ) }
Normalized Transfer Function:
2 +b1s+b0]
Denormalized Transfer Function:
Apply BLT:
H(Z) = 0.0125+0.025Z -1
Sem KSSEM, Bangalore
MATLAB CODE:
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 ;
% N = Minimum order of Filter Wn = Cutoff Frequencies
[N,Wn]=cheb1ord(Wp,Ws,Rp,Rs);
[z,p]=cheby1(N,Rp,Wn);
freqz(z,p);
Order of Chebyshev Filter :
Sem KSSEM, Bangalore
 
Sem KSSEM, Bangalore
PART B:
Dept of ECE Page | 44
TMS320C6748 DSP BOARD
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
(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.
Dept of ECE Page | 45
The C6748 DSP kit includes a stereo codec. This analog interface circuit (AIC) has the
following characteristics:
• 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.
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
  Eight 32-Bit Instructions/Cycle
Dept of ECE Page | 46
  32/64-Bit Data Word
  375/456-MHz C674x Fixed/Floating-Point
  Rich Peripheral Set, Optimized for Audio
  Highly Optimized C/C++ Compiler
  Extended Temperature Devices Available
  Eight Independent Functional Units:
  Load-Store Architecture With 64 32-Bit General-Purpose Registers
  Instruction Packing Reduces Code Size
  All Instructions Conditional
  Instruction Set Features
  Single- and Double-Precision
  8-Bit Overflow Protection
  67x cache memory.
  256K-Byte L2 unified Memory RAM\Cache.
  Real-Time Clock With 32 KHz Oscillator and Separate Power Rail.
  Three 64-Bit General-Purpose Timers
  S/PDIF, IEC60958-1, AES-3, CP-430 Formats
  Up to 16 transmit pins
  Enhanced Channel Status/User Data
  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
  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
 
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.
 
*
A. From the Target menu select New target Configuration
Target -> New target Configuration.
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
Dept of ECE Page | 49
C. Next goto Advanced tab give the suitable Gel file path as shown below.
Follow the path.
“C:\6748support\c6748.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.
Step P1:
Change the Perspective Debug to C/C++ from the right corner of the CCS
Step P2:
Step P3:
Specify the name of the project in the space provided .and Click Next
Eg., Project Name: Hello World
 
Select the project type
Click  Next
*However our target is based on C6000 family, Based on the family we need to select the
Project
Type.
Click finish
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:
7. BUILD
Have any errors and
Project Build active project.
If your code  doesn thave any errors and warnings, a message will be printed in the console
window that
Problems window display errors or warnings, if any.
 
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.
 
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
 
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.
#include<stdio.h>
int i=0,j;
/*Input Signal Samples*/
}
Dept of ECE Page | 57
OUTPUT:
Sequence 2:
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
Start Address: y
9. Note down the output waveform.
 
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.
#include<stdio.h>
int m,n,x[30],h[30],y[30],i,j,temp[30],k,x2[30],a[30];
void main()
scanf("%d",&m);
scanf("%d",&n);
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
{
y[0]=0;
a[j]=h[n-j];
Dept of ECE Page | 59
/*Circular convolution*/
for(k=1;k<n;k++)
}
}
4
4
Dept of ECE Page | 60
PROGRAM 3:
Aim: Computation of N point DFT of a given sequence.
C Code:
#include<stdio.h>
#include<math.h>
int N,k,n,i;
out_imag[8]={0.0};
int x[32];
scanf("%d",&N);
for(i=0;i<N;i++)
sumim=sumim-x[n]* sin(2*pi*k*n/N);
}
printf("DFT of the Sequence :\n");
}
}
 
Dept of ECE Page | 61
OUTPUT:
4
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:
#define Len 10 /*Length of Impulse Response*/
float y[Len] = {0,0,0}, sum;
main()
printf("Impulse Response Coefficients:\n");
}
else
}
}
Dept of ECE Page | 63
2. Second Order System:
#define Len 10 /*Length of Impulse Response*/
float y[Len] = {0,0,0}, sum;
main()
printf("Impulse Response Coefficients:\n");
}
else
}
}
Dept of ECE Page | 64
SAMPLE VIVA QUESTIONS:
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?
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?
 
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?
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?