Observation 20 Assessment I 20 Assessment II 20: Digital Signal Processing Dept of ECE
Observation 20 Assessment I 20 Assessment II 20: Digital Signal Processing Dept of ECE
Marks Allotment
Marks
Internal 60
Observation 20
Assessment I 20
Assessment II 20
External 40
Anchor, Chairperson,
Digital signal Processing Dept of ECE
1
Subject Code: UE18EC255
CYCLE II
LIST OF EXPERIMENTS USING DSP PROCESSOR (6748)
1. Week 9:
a. To find Impulse response of first order and second order system
b. Computation of N- Point DFT of a given sequence and IDFT
2. Week 10: Linear convolution and Circular convolution of two given sequences.
3. Week 14: Realization of an FIR filter (any type) to meet given
specifications. The input can be a signal from function generator / speech
signal.
Reference Books:
1. “Digital signal processing using MATLAB”, Sanjeet Mitra, TMH, 2001
2. “Digital signal processing using MATLAB”, J.G.Proakis & Ingle, MGH, 2000
3. “Digital signal processors”, B.Venkataramani and Bhaskar, TMH, 2002
2
DSP USING MATLAB
MATLAB is a high-level language and interactive environment that enables you to perform
computationally intensive tasks faster than with traditional programming languages such as C, C++
etc. The key features of MATLAB are as follows
• High-level language for technical computing
• Development environment for managing code, files, and data
• Interactive tools for iterative exploration, design, and problem solving
• Mathematical functions for linear algebra, statistics, Fourier analysis, filtering, optimization, and
numerical integration
• 2-D and 3-D graphics functions for visualizing data
• Tools for building custom graphical user interfaces
• MATLAB (MATrix LABoratory) is a special purpose computer program optimized to perform
engineering and scientific calculations.
• The MATLAB program implements the MATLAB language, and provides a very extensive library
of predefined functions to make technical programming tasks easier and more efficient.
• The extremely wide variety of functions makes it much easier to solve technical problems in
MATLAB than in other languages such as FORTRAN or C.
• The advantages of using MATLAB for technical programming are:
Ease of use
Platform independence
Predefined functions
Device-independent plotting
Graphical User Interface
MATLAB Compiler
MATLAB is a huge program, with an incredibly rich variety of functions. There are more
than 1000 functions in the basic MATLAB.
The disadvantages of MATLAB are:
It is interpreted language, and therefore can execute more slowly than compiled languages.
Cost. (Student version of MATLAB is available for low cost with almost identical feature)
full copy of MATLAB is 5 TO 10 times more expensive than a conventional C or
FORTRAN compiler.
The functional unit of data in any MATLAB program is the array. An array is a collection of
data values organized into rows and columns.
When MATLAB executes, it can display several types of windows that accept commands or
display information. The three most important types of windows are command windows,
where commands may be entered: figure windows, which display plots and graphs: and
edit/debug windows which permit a user to create and modify MATLAB programs.
The major tools within or accessible from the MATLAB desktop are:
The command window: a user can enter interactive commands at the command
prompt (>>) in the command window and they will be executed on the spot. Instead
of typing commands directly in the command window, a series of commands may be
placed in to a single file and the entire file may be executed by typing its name in the
command window. Such files are called script files. Script files are also called M-
Files because they have file extension of “. M”.
The command history window: the command history window displays a list of the
commands that a user has entered in the command window.
The launch pad: it is a special tool that collects references to the documentation,
demos, and related tools for MATLAB itself and for each toolkit that you own.
The edit/debug window: used to create new M-Files, or to modify existing ones. An
edit/debug window is created automatically when you create a new M-File or open
an existing one. The edit/debug window is essentially a programming text editor,
3
with the MATLAB languages features highlighted in different colors. Comments in
an M-File appear in green, variables and numbers appear in black, character strings
appear in red, and language keywords appear in blue.
Figure windows: used to display MATLAB graphics. A figure can be two or three-
dimensional plot of data, an image or a GUI.
The MATLAB workspace: it is a collection of all the variables and arrays that can be
used by MATLAB when a particular command, M-File, or function is executing. All
commands executed in the command window share a common workspace, so they
can all share variables. (Clear deletes all variables from the current workspace).
The workspace browser: it provides a graphic display of the same information as
whos command, and the display is dynamically updated whenever the contents of
workspace change. The workspace browser also allows user to change the contents
of any variables in the workspace. (A list of the variables and arrays in the current
workspace can be generated with the whos command)
• Getting help: by selecting the? Help icon bar from the desktop tool bar, or by typing
helpdesk or helpwin in the command window. The other way of obtaining help is by using
lookfor command. Help command searches for an exact function name match, whereas the
lookfor command searches the quick summary information in each function for a match.
Lookfor is slower than help but it improves the chances of getting useful information.
• For new users of MATLAB, a few demonstrations may help to give you a feel for its
capabilities. To run MATLAB’s built in demonstrations, type demo in the command
window, or select “demos” from the launch pad.
• The contents of the command window can be cleared at any time using the clc command,
and the contents of the current figure window can be cleared at any time using the clf
command. The variables in the workspace can be cleared with the clear command. It is a
good idea to issue the clear command at the start of each new independent calculation.
• Another important command is the abort command. If an m-file appears to be running for
too long, it might contain an infinite loop, and it will never terminate. In this case the user
can regain the control by typing control-c (^c) in the command window. When MATLAB
detects a ^c, it interrupts the running program and returns a command prompt.
• After diary command is typed, a copy of all input and most output typed in the command
window is echoed in the diary file. The command diary off suspends input in to the diary
file, and the command diary on resumes input again.
• MATLAB includes a special command (which) to help you to find out just which version of
a file is being executed. and where it is located. The format of this command is which
functionname, where functionname is the name of the function that you are trying to locate.
The path related function include:
4
• The functional unit of data in any MATLAB program is the array. An array is a collection of
data values organized into rows and columns, and known by a single name.
• MATLAB variable is a region of memory containing an array, which is known by a user-
specified name. MATLAB variable names must begin with a letter, followed by any
combination of letters, numbers, and the underscore( _ ) character. Only the first 31
characters are significant; if more than 31 are used, the remaining characters will be ignored.
If two variables are declared with names that only differ in the 32nd character, MATLAB
will treat them as same variable.
• Spaces cannot be used in MATLAB variable names, underscore letters can be substituted to
create meaningful names.
• It is important to include a data dictionary in the header of any program that you write. A
data dictionary lists the definition of each variable used in a program. The definition should
include both a description of the contents of the item and the units in which it is measured.
• MATLAB language is case-sensitive. It is customary to use lower-case letters for ordinary
variable names.
• The most common types of MATLAB variables are double and char.
• MATLAB is weakly typed language. Variables are not declared in a program before it is
used.
• MATLAB variables are created automatically when they are initialized. There are three
common ways to initialize variables in MATLAB:
Assign data to the variable in an assignment system.
Input data into the variable from the keyboard.
Read data from a file.
• The semicolon at the end of each assignment statement suppresses the automatic echoing of
values that normally occurs whenever an expression is evaluated in an assignment
statement.
5
EXPERIMENT No. 1: Verification of Sampling theorem
Theory: Sampling is a process of converting a continuous time signal (analog signal) x(t) into a
discrete time signal x[n], which is represented as a sequence of numbers. (A/D
converter)Converting back x[n] into analog (resulting in the process of reconstruction.)
(D/A converter)
For the reconstructed signal to be exactly the same as x(t), sampling theorem is used to get x(n)
from x(t). The sampling frequency fs determines the spacing between samples.
Aliasing - A high frequency signal is converted to a lower frequency, results due to
under sampling. Though it is undesirable in ADCs, it finds practical applications in
stroboscope and sampling oscilloscopes.
Algorithm:
1. Input the desired frequency f1,f2 and generate y (for which sampling theorem is to be verified).
2. Input the Sampling Frequency fs.
3. Generate oversampled, Nyquist & under sampled discrete time signals.
4. Plot the waveforms and hence prove sampling theorem.
%% Program
clc; % clears the command window
clear all; %clears variables in workspace
close all; %close all fig windows
t=0:0.001:0.2; %analog time axis
xa=cos(2*pi*f1*t)+cos(2*pi*f2*t);
fm=max(f1,f2);
% For Right sampling fs=2*fm
% For Over sampling fs>2*fm so let fs=fm
% For Under sampling fs<2*fm so let fs=4*fm
fs=2*fm; %fs = sampling freequency
ts=1/fs;
n=0:1:(0.2*fs);
xd=cos(2*pi*f1*(n*ts))+cos(2*pi*f2*(n*ts));
figure;
subplot(3,1,1);
plot(t,xa);
xlabel('t in s');
ylabel('amp');
title('Analog Signal and Discrete Signal');
hold on;
stem(n*ts,xd);
hold off;
legend('Continuous xa(t)','xd(n)');
%% Plot only Discrete signal
6
subplot(3,1,2);
stem(n,xd,'r');
xlabel('n samples');
ylabel('xd[n]');
title('Discrete Signal');
%% Reconstruction by using the formula:
% xr(t) = sum over n=0,...,N-1: x(nT)*sin(pi*(t-nT)/T)/(pi*(t-
nT)/T)
% Note that sin(pi*(t-nT)/T)/(pi*(t-nT)/T) = sinc((t-nT)/T)
% sinc(x) = sin(pi*x)/(pi*x) according to MATLAB
xr=xd*sinc((t-(n'*ts))/ts);
subplot(3,1,3);
plot(t,xr);
xlabel('t in s');
ylabel('xr(t)');
title('Right Sampling'); %or /Over Sampling/ Under Sampling
%%%%%%%%%%%%%%%%%%%%
OUTPUT:
Right Sampling:
Enter the input frequency1 = 10
Enter the input frequency2 = 20
7
Over Sampling:
Under Sampling:
8
EXPERIMENT No.2 : Program to solve difference equation and program to find the Impulse
response of the system
%y(n)-0.25y(n-1)-0.125y(n-2)=x(n)+0.5x(n-1)
%x(n)=u(n)-u(n-2)
%y(-1)=1 and y(-2)=2 (enter the values as [2 1])
M=length(b)-1;
N=length(a)-1;
IC=input('Enter the initial conditions for y: ');
n=[-N:20];%number of terms
%x[n]=u[n]-u[n-2]
x=[(n>=0)]-[(n>=2)];
subplot(211);
stem(n,x);
y=[IC zeros(1,length(n)-N)];
for k=0:M
sumx=sumx+(b(k+1)*x(n-k));
end
for k=1:N
sumy=sumy+(a(k+1)*y(n-k));
end
y(n)=sumx-sumy;
end
n=[-N:20];%number of terms
subplot(212);
stem(n,y);
9
OUTPUT:
2.0000 1.0000 1.5000 2.0000 1.1875 0.5469 0.2852 0.1396 0.0706 0.0351
0.0176 0.0088 0.0044
Columns 14 through 23
%y(n)-0.25y(n-1)-0.125y(n-2)=x(n)+0.5x(n-1)
%x(n)=u(n)-u(n-2)
%y(-1)=1 and y(-2)=2 , (enter the values as [2 1])
10
b=input('Enter the coefficients of x: ');
a=input('Enter the coefficients of y: ');
M=length(b)-1;
N=length(a)-1;
IC=input('Enter the initial conditions for y: ');
%x[n]=u[n]-u[n-2]
x=[(n>=0)]-[(n>=2)];
y=filter(b, a, x, ic);
subplot(211);
stem(n,x);
subplot(212);
stem(n,y);
OUTPUT:
y[n]=
Columns 1 through 13
1.5000 2.0000 1.1875 0.5469 0.2852 0.1396 0.0706 0.0351 0.0176 0.0088
0.0044 0.0022 0.0011
Columns 14 through 21
11
With zero initial conditions
x=double([n==0]);
12
IC =[0 0];
13
EXPERIMENT No. 3: (a) Computation of N point DFT of a given sequence x(n) and to plot
magnitude and phase spectrum (b) Computation N-pt IDFT of the given X(k).
(a) Computation of N point DFT of a given sequence x(n) and to plot magnitude and phase
spectrum
function [Xk]=calcdft(xn, N)
L=length(xn);
if(N<L)
error('N must be >=L');
end
x1=[xn zeros(1,N-L)];
for k=0:1:N-1;
for n=0:1:N-1;
p=exp(-i*2*pi*n*k/N);
T(k+1,n+1)=p;
end
end
disp('Transformation Matrix for dft')
disp(T);
Xk=T*x1.';
end
OUTPUT:
14
enter the input sequence: [0 1 2 3]
enter the number of points: 8
x1 =
0 1 2 3 0 0 0 0
Columns 5 through 8
DFT X(K)=
6.0000 + 0.0000i
-1.4142 - 4.8284i
-2.0000 + 2.0000i
1.4142 - 0.8284i
-2.0000 - 0.0000i
1.4142 + 0.8284i
-2.0000 - 2.0000i
-1.4142 + 4.8284i
15
%%Program to find idft
clc;
clear all;
close all;
%%input sequence
Xk=input('enter the input sequence');
xn=calcidft(Xk);
N=length(xn);
disp('x(n)=');
disp(xn);
n=0:N-1;
stem(n,xn);
title('ifft sequence');
xlabel('time');
ylabel('amplitude');
OUTPUT:
enter the input sequence[6.0000 + 0.0000i -1.4142 - 4.8284i -2.0000 + 2.0000i 1.4142 - 0.8284i -
2.0000 - 0.0000i 1.4142 + 0.8284i -2.0000 - 2.0000i -1.4142 + 4.8284i]
Transformation Matrix for idft
Columns 1 through 4
16
Columns 5 through 8
x(n)=
0.0000 + 0.0000i
1.0000 - 0.0000i
2.0000 - 0.0000i
3.0000 - 0.0000i
-0.0000 + 0.0000i
0.0000 + 0.0000i
-0.0000 - 0.0000i
0.0000 + 0.0000i
17
EXPERIMENT No. 4: Linear convolution and circular convolution of two sequences.
%% Main Program
clc; %clears the console window
clear all;%deletes the user defined variable in variable browser
close all;%close the figure window
function [y]=calcconv(x,h)
l1=length(x);
l2=length(h);
N = l1+l2-1; %length of linear convolution
%-----------------------------------------------------------
%y=linear convolution of x[n] and h[n]
%note: in matlab index starts with 1 and not 0
for n=1:1:N
y(n)=0;
18
for k=1:1:l1
if(n-k+1>=1 & n-k+1<=l2) % to avoid negative index
y(n)=y(n)+x(k)*h(n-k+1);
end
end
end
end
OUTPUT:
y=
5 14 31 48 40 32
5 14 31 48 40 32
-3 -2 -1 0 1 2
19
%Circular convolution without using inbuilt function
clc; %clears the console window
clear all;%deletes the user defined variable in variable browser
close all;%close the figure window
x= input('Enter x[n]: '); %read input x[n]
h= input('Enter h[n]: '); % read impulse response h[n]
N= input('Enter N: ');
l1=length(x);
l2=length(h);
x=[x zeros(1,(N-l1))]
h=[h zeros(1,(N-l2))]
%inbuilt function
%y=cconv(x,h,N);
%-----------------------------------------------------------
%y=Circular convolution of x[n] and h[n]
%note: in matlab index starts with 1 and not 0
for n=1:1:N
y(n)=0;
for k=1:1:N
y(n)=y(n)+x(k)*h(mod((n-k),N)+1);
end
end
%end
%-----------------------------------------------------------
disp('The circular convolution of two given sequence');
n=0:N-1;
figure;
subplot(3,1,1);
stem(n,x);
xlabel('Time');
ylabel('Amplitude');
title('1st sequence');
subplot(3,1,2);
stem(n,h);
xlabel('Time');
ylabel('Amplitude');
title('2nd sequence');
subplot(3,1,3);
stem(n,y);
xlabel('Time');
ylabel('Amplitude');
title('circular convolution');
disp(y);
disp(n);
20
OUTPUT:
Enter x[n]: [1 2 3 4]
Enter h[n]: [1 2 2 1]
Enter N: 4
x=
1 2 3 4
h=
1 2 2 1
0 1 2 3
21
EXPERIMENT No.5.(a) Autocorrelation of a given sequence and verification of its
properties. (b)Cross correlation of given sequences and verification of its properties.
Verification of properties
• rxx[l] = r ∗ xx [−l]
• rxx[0] =Ex
• |rxx[l]| ≤ rxx[0]
• rxy[l] = r ∗ xy [−l]
%% Main Program
x=input('enter the sequence x= ');
nx=input('enter the index for sequence nx= ');
[rxx,nrxx]=findconv(x,nx,flip(x),-flip(nx));
%using inbuilt function
%[rxx,nrxx]= xcorr(x);
E=sum(x.^2);
disp('energy');
disp(E);
disp(rxx);
disp(nrxx);
if(rxx(ceil(length(rxx)/2))==max(rxx))
disp('Rxx(0) is the maximum value; proved');
else
disp('Rxx(0) is the maximum value; not proved');
end;
if (rxx(ceil(length(rxx)/2))==E)
disp('Rxx(0)gives energy; proved');
else
disp('Rxx(0)gives energy; not proved');
end
if (rxx==flip(rxx))
disp('symmetric property satisfied');
else
disp('symmetric property not satisfied');
end
subplot(2,1,1);
stem(nx,x);
xlabel('n');
ylabel('x[n]');
22
subplot(2,1,2);
stem(nrxx,rxx);
xlabel('l');
ylabel('r[l]');
title('auto correlation');
%%function
function [y,ny]=findconv(x,nx,h,nh)
nyb=nx(1)+nh(1);
nye=nx(length(nx))+nh(length(nh));
ny=nyb:nye;
y=conv(x,h);
end
OUTPUT:
enter the sequence x= [1 1 1 1 1 1 1 1 1 1]
enter the index for sequence nx= [1:10]
energy
10
Columns 1 through 15
1 2 3 4 5 6 7 8 9 10 9 8 7 6 5
Columns 16 through 19
4 3 2 1
Columns 1 through 15
-9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5
Columns 16 through 19
6 7 8 9
23
(b)Cross correlation of given sequences and verification of its properties.
%% Main Program
disp('rxy=');
disp(rxy);
disp(nrxy);
disp('ryx=');
disp(ryx);
disp(nryx);
if (rxy==flip(ryx))
disp('Rxy(lag)=Ryx(-lag) satisfied');
else
disp('Rxy(lag)=Ryx(-lag) not satisfied');
end
figure;
subplot(3,1,1);
stem(nx,x);
xlabel('Time');
ylabel('Amplitude');
title('1st seq');
subplot(3,1,2);
stem(ny,y);
xlabel('Time');
ylabel('Amplitude');
title('2nd seq');
subplot(3,1,3);
stem(ny,y);
disp(y);
disp(ny);
xlabel('Time');
ylabel('Amplitude');
title('cross correlation convolution');
%%function
function [y,ny]=findconv(x,nx,h,nh)
nyb=nx(1)+nh(1);
nye=nx(length(nx))+nh(length(nh));
ny=nyb:nye;
24
y=conv(x,h);
end
OUTPUT:
-3 -2 -1 0 1 2 3
ryx=
0 0 1 2 0 3 6
-3 -2 -1 0 1 2 3
Rxy(lag)=Ryx(-lag) satisfied
1 0 0 3
0 1 2 3
25
EXPERIMENT No. 6: To find Linear and circular convolution of two sequences using DFT
and IDFT.
OUTPUT:
Enter the 1st Sequence: [1 2 3 4]
Linear convolution
3.0000
8.0000
17.0000
26
26.0000
20.0000
16.0000
27
figure;
subplot(3,1,1);
stem(0:length(x)-1,x);
xlabel('Time');
ylabel('Amplitude');
title('1st seq');
subplot(3,1,2);
stem(0:length(h)-1, h);
xlabel('Time');
ylabel('Amplitude');
title('2nd seq');
subplot(3,1,3);
stem(0:N-1,real(y));
xlabel('Time');
ylabel('Amplitude');
title('circular convolution');
disp('circular convolution');
disp(real(y));
OUTPUT:
Circular convolution
17
15
13
15
28
EXPERIMENT No. 7:
a. Design and implementation of Analog Butterworth and Chebyshev Filters to
meet the given specifications.
b. Design and implementation of IIR, Butterworth and Chebyshev Filters to
meet the given specifications.
------------------------------------------------------------------------------------------------------------------
a. Design and implementation of Analog Butterworth and Chebyshev Filters to
meet the given specifications.
i. Design an analog low pass Butterworth filter for the following specifications.
a. Pass band ripple=-3dB
b. Stop band ripple=-40dB
c. Pass band frequency=1000Hz
d. Stop band frequency=2000Hz
Show all the design steps plot and verify the same using MATLAB.
clc;
clear all;
close all;
ap=-3;%%db
as=-40;%%db
fp=1000;%%Hz
fs=2000;%%Hz
%oc=op/((10^(-ap/10)-1)^(1/(2*N))); %or
oc=os/((10^(-as/10)-1)^(1/(2*N)));
disp('Cutoff freq,oc=');
disp(oc);
% %using inbuilt function
% [N,oc]=buttord(op,os,-ap,-as,'s');
[b,a]=butter(N,oc,'s');
29
fr=0:100:4000;
wr=2*pi*fr;
[H,w]=freqs(b,a,wr);
f=w/(2*pi);
H_mag=20*log10(abs(H));
figure;
plot(f,H_mag);
grid on;
xlabel('Frequency in Hz');
ylabel('Magnitude in dB');
title('Magnitude Response');
Transferfunc=tf(b,a)
OUTPUT:
Orderofthefilter,N= 7
Cutoff freq,oc= 6.5088e+03
Transferfunc =
4.949e26
------------------------------------------------------------------------------
s^7 + 2.925e04 s^6 + 4.278e08 s^5 + 4.024e12 s^4 + 2.619e16 s^3 + 1.18e20 s^2
+ 3.417e23 s + 4.949e26
30
ii. Design an analog low pass Chebyshev type 1 filter for the following specifications.
a. Pass band ripple=-3dB
b. Stop band ripple=-40dB
c. Pass band frequency=1000Hz
d. Stop band frequency=2000Hz
Show all the design steps plot and verify the same using MATLAB.
clc;
clear all;
close all;
ap=-3;%%db
as=-40;%%db
fp=1000;%%Hz
fs=2000;%%Hz
epsilon=sqrt(10^(-ap/10)-1);
A=sqrt(10^(-as/10));
31
g=sqrt((A^2-1)/(epsilon^2));
N=log10(g+sqrt(g^2-1))/log10(omegar+sqrt(omegar^2-1))%%or
%%N=acosh(g)/acosh(omegar);
N=ceil(N);
disp('Orderofthefilter,N=');
disp(N);
fr=0:100:4000;
wr=2*pi*fr;
[H,w]=freqs(b,a,wr);
f=w/(2*pi);
H_mag=20*log10(abs(H));
figure;
plot(f,H_mag);
grid on;
xlabel('Frequency in Hz');
ylabel('Magnitude in dB');
title('Magnitude Response');
Transferfunc=tf(b,a)
OUTPUT:
N=
4.0249
Orderofthefilter,N=
5
Transferfunc =
6.135e17
--------------------------------------------------------------------
s^5 + 3610 s^4 + 5.586e07 s^3 + 1.362e11 s^2 + 6.358e14 s + 6.135e17
32
b. Design and implementation of IIR, Butterworth and Chebyshev Filters to
meet the given specifications.
iii. Design a low pass Butterworth filter (using bilinear transformation) for the following
specifications.
a. Pass band ripple=3.01dB
b. Stop band ripple=15dB
c. Pass band frequency=500Hz
d. Stop band frequency=750Hz
e. Sampling frequency=2kHz
Show all the design steps plot and verify the same using MATLAB.
clc;
clear all;
close all;
rp=input('Enter the pass band ripple (in dB)');
rs=input('Enter the stop band ripple (in dB)');
fs=input('Enter the sampling frequency (in Hz)');
fp=input('Enter the pass band frequency (in Hz)');
fst=input('Enter the stop band frequency (in Hz)');
fn=fs/2;%normalized sampling frequency
fpn=fp/fn;%normalized pass band frequency
fstn=fst/fn;%normalized stop band frequency
[N,wc]=buttord(fpn,fstn,rp,rs);
33
[b,a]=butter(N,wc);
[H,f]=freqz(b,a,256,fs);
Transferfunc=tf(b,a,(1/fs))
H_mag=20*log10(abs(H));
figure;
plot(f,H_mag);
grid on;
xlabel('Frequency in Hz');
ylabel('Magnitude in dB');
title('Magnitude Response');
OUTPUT:
Transferfunc =
34
iv. Design a low pass Chebyshev filter type-1 (using bilinear transformation) for the following
specifications.
a. Pass band ripple=3dB
b. Stop band ripple=20dB
c. Pass band frequency=1200Hz
d. Stop band frequency=1800Hz
e. Sampling frequency=8kHz
Show all the design steps. Plot and verify the same using MATLAB.
clc;
clear all;
close all;
rp=input('Enter the pass band ripple (in dB)');
rs=input('Enter the stop band ripple (in dB)');
fs=input('Enter the sampling frequency (in Hz)');
fp=input('Enter the pass band frequency (in Hz)');
fst=input('Enter the stop band frequency (in Hz)');
fn=fs/2;%normalized sampling frequency
fpn=fp/fn;%normalized pass band frequency
fstn=fst/fn;%normalized stop band frequency
[N,wc]=cheb1ord(fpn,fstn,rp,rs);
[b,a]=cheby1(N,rp,wc);
35
Transferfunc=tf(b,a,(1/fs))
[H,f]=freqz(b,a,256,fs);
H_mag=20*log10(abs(H));
figure;
plot(f,H_mag);
grid on;
xlabel('Frequency in Hz');
ylabel('Magnitude in dB');
title('Magnitude Response');
OUTPUT:
Enter the pass band ripple (in dB)3
Enter the stop band ripple (in dB)20
Enter the sampling frequency (in Hz)8000
Enter the pass band frequency (in Hz)1200
Enter the stop band frequency (in Hz)1800
Transferfunc =
EXPERIMENT No.8 .Design and implementation of FIR filter to meet given specifications.
36
%%Designing Low Pass filter with pass band edge frequency=1500hz
minimum stop band attenuation is 50dB Transition bandwidth is
0.5khz sampling frequency is 8khz
clear all;
close all;
clc;
fs=8000; %%sampling frequency
fp=1500; %%pass band edge frequency
fst=2000;%%stop band edge frequency
wp=(2*pi*fp)/fs;
ws=(2*pi*fst)/fs;
twn=(ws-wp)/pi;%%normalize transition width choose hamming window
To find
wc=wp+twn*pi/2;
%%LENGTH(TAPS) of filter (i.e M).The filter order is always equal
to the number of taps minus 1
N=ceil(8/twn);
%%To design type I FIR filter , taps=odd or order=even
if(mod(N,2)==0)
N=N+1;
end
alpha=(N-1)/2;
er=0.001;
for n=0:1:N-1
hd(:,n+1)=(sin(wc*(n-alpha+er)))./(pi*(n-alpha+er));
end
%disp(hd)
figure;
whm=hamming(N);%%hamming window
disp('Hammind window coeff');
disp(whm);
stem(whm);
title('Hamming window');
hn=hd.*whm';
[H,f]=freqz(hn,1,1000,fs);
H_mag=20*log10(abs(H));
figure;
plot(f,H_mag);
xlabel('Normalized frequency');
ylabel('Magnitude');
OUTPUT:
37
FIR Filter coeff hn
Columns 1 through 8
Columns 9 through 16
Columns 17 through 24
Columns 25 through 32
Columns 33 through 40
Columns 41 through 48
Columns 49 through 56
Columns 57 through 64
Column 65
0.0000
38
B. Frequency sampling technique.
39
%%Design a linear phase FIR low pass filter using
%%frequency sampling method. Let M=17(order)
%%and cutoff frequency is wc=pi/2 rad/sample
%%Desired frequency response
%%Hd(w)= exp(-%j*w(M-1)/2) for 0<=w<=pi/2
%% = 0 for pi/2<=w<=pi
clc;
clear all;
close all;
kc = floor(wc*(M/(2*pi)));
k=0:(M-1)/2;
subplot(3,1,2);
stem(k,abs(Hk));
title('Sampled Magnitude response Hd_w');
xlabel('k');
ylabel('|H(k)|');
40
%% Taking idft of H(k) to find h(n)
for n=0:(M-1)
sumHk=0;
for k=1:(M-1)/2
sumHk = sumHk+real(Hk(k+1)*exp(i*2*pi*k*n/M));
end
hn(n+1)=(1/M)*(Hk(1)+2*sumHk);
end
n=0:(M-1);
subplot(3,1,3);
stem(n,hn);
title('Impulse response h(n) of filter')
xlabel('n');
ylabel('hn');
[H,f]=freqz(hn,1,1000);
H_mag=20*log10(abs(H));
figure;
plot(f,H_mag);
xlabel('Normalized frequency');
ylabel('Magnitude');
OUTPUT:
Hk =
Columns 1 through 4
Columns 5 through 8
Column 9
0.0000 + 0.0000i
41
FIR Filter coeff hn
Columns 1 through 8
Columns 9 through 16
Column 17
0.0398
42
43
CYCLE II LIST OF EXPERIMENTS USING DSP PROCESSOR
44
Click on Finish.
45
The Connection should be “Texas Instruments XDS100V3 Debug Probe”. The Board
or Device should be LCDKC6748.
Click on Save and then Test Connection. If your connection is OK, then a message as
“JTAGDR
integrity test succeeded” will appear.
Click on the “Advanced” tab and then Click on C674x_0, verify the GEL file path.
Without the proper GEL file, hardware will not be connected to CCSv5.
Close “Target Configuration” window and Right Click on My_target and select SET AS
DEFAULT and then LAUNCH SELECTED CONFIGURATION.
46
Debug window will be launched.
Make the changes as follows. Please note that the connection field can be “Texas
Instruments XDS100v3 Debug Probe” if you are using one.
47
Click on FINISH.
48
5. Save
6. Test connection-> wait for message “JTAG INTEGRITY SCAN TEST SUCCEEDED”
7. Right click on configuration file and set the configuration file as “default” and “launch selected
configuration”.
8. To open new project: (In Edit mode) Go to Project-> New CCS project
a. Target-LCDK 6748
b. Connection type- TIXDS100V3
c. Name the project- eg: test123
d. Output type: EXCE
e. Output format- Legacycoff
f. Linker command- c6748.cmd
g. Runtime- rts6740.lib
h. Finish
9. Type code in main.c
10. Build, Debug (Debug mode) and Run the code
49
Experiment No. 1:-Impulse response
#include<stdio.h>
float x[5]={1,0,0,0,0};
float y[5]={0,0,0,0,0};
void main()
{
int i,j;
printf("\nTo calculate impulse response\n");
for(i=0;i<5;i++)
{
if(i==0)
y[i]=x[i]*0.1311;
if(i==1)
y[i]=x[i]*0.1311+0.2622*x[i-1]+0.7488*y[i-1];
if(i>=2)
y[i]=x[i]*0.1311+0.2622*x[i-1]+0.7488*y[i-1]-0.2722*y[i-
2];
}
for(j=0;j<5;j++)
printf("\n %f",y[j]);
}
50
Experiment No. 2:- N point DFT and IDFT
#include <stdio.h>
#include <math.h>
float x[4]={0,1,2,3}; //input only real sequence
float Yreal[4],Yimag[4];
//for 4 point DFT to store real & imaginary
float theta;
int n,k,N=4,xlen=4;
void main()
{
for(k=0;k<N;k++)
{
Yreal[k]=0;
Yimag[k]=0; //initialize real & imag parts
for(n=0;n<xlen;n++)
{
theta = -2*3.141592*k*n/N;
//careful about minus sign
Yreal[k]=Yreal[k]+x[n]*cos(theta);
Yimag[k]=Yimag[k]+x[n]*sin(theta);
}
printf("%0.2f+j%0.2f \n", Yreal[k], Yimag[k]);
}
}//end of main
#include<stdio.h>
#include<math.h>
float x[4],XReal[4],XImag[4],theta;
int k,n,N;
void main()
{
printf("\t\tInverse Discrete Fourier Transform(IDFT)\n");
printf("\nEnter the length of the DFT N = ");
scanf("%d",&N);
// length of the DFT
printf("\nEnter the real amd imaginary parts of X(k) as
follows\n"
"X(k) = Re{X(k)} Im{X(k)}\n");
for(k = 0; k < N; k++)
{
printf("X(%1.0f) = ",k);
// enter values of DFT
scanf("%f %f",&XReal[k],&XImag[k]);
}
// next part of the program computes inverse DFT
51
for(n = 0; n < N; n++)
{
x[n] = 0;
for(k = 0; k < N; k++)
// this loop computes one value of x(n)
{
theta=(2*3.141592*k*n)/N;
x[n] = x[n] + XReal[k]*cos(theta)
- XImag[k]*sin(theta);
}
x[n] = x[n]/N;
}
// Next part of program displays x(n) on the screen
printf("\nThe sequence x(n) is as follows...");
for(n = 0; n < N; n++)
// displaying x(n) on the screen
printf("\nx(%1.0f) = %0.2f",n,x[n]);
}
Linear convolution
#include<stdio.h>
int x[20]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int h[20]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int y[20]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int l1,l2,N;
int i,n,k;
void main()
{
printf("Enter length of x: ");
scanf("%d",&l1);
printf("Enter x[20]:\n ");
for(i=0;i<l1;i++)
scanf("%d",&x[i]);
printf("Enter length of h: ");
scanf("%d",&l2);
printf("Enter h[20]:\n ");
for(i=0;i<l2;i++)
scanf("%d",&h[i]);
N=l1+l2-1;
52
for(n=0;n<N;n++)
{
y[n]=0;
for(k=0;k<l1;k++)
{
if(n-k>=0 && n-k<l2)
y[n]=y[n]+x[k]*h[n-k];
}
}
printf("Convolution result y[n]= \n");
for(n=0;n<N;n++)
printf("%d\n",y[n]);
Circular convolution
#include<stdio.h>
int x[20]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int h[20]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int y[20]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int m,N,sum;
int i,n,k;
void main()
{
printf("Enter N: ");
scanf("%d",&N);
printf("Enter x[20]:\n ");
for(i=0;i<N;i++)
scanf("%d",&x[i]);
printf("Enter h[20]:\n ");
for(i=0;i<N;i++)
scanf("%d",&h[i]);
// Next nested for loop calculates circular convolution
printf("\nThe circular of convolution is...");
for(m = 0; m < N; m++)
{
53
sum = 0.0;
for(k = 0; k < N; k++) //computation of one value in circular
{//convolution
if((m-k)>= 0)
n = m-k;
//modulo index
else
n = m-k+N;
sum += x[k] * h[n];
}
y[m] = sum;
printf("\ny[%d] = %d",m,y[m]);
}
// displaying the value on screen
}
54
Experiment No. 4:-FIR LPF for 1khz cut off frequency
2) Two linker files are opened (linker_dsp.cmd & 6478.cmd) so delete old linker file with the
extension .cmd (eg: 6478.cmd)
4) Right click on project name and select properties, then select c6000 compiler include options and
add two files
55
In project Properties go to C6000 CompilerInclude Options, Add include search path
Browse for location-
• /board_support_lib/inc, click on OK
• /support_files, click on OK
Right click on project name, select properties, click on “C6000 linker”, select “file search path”
Browse
/mnt/LCDK_6748/MANUAL/DSPLAB/board_support_lib/lib/evmomapl138_bsl/evmomapl138_bs
l.lib and click ok
6) Reset the LCDK board, Select your project, build it, and debug it. Load and Run the program.
Connect the input signal of 500 Hz (less than 1volt amplitude) from signal generator to line in port.
You can also pass an audio input and hear the output signal through the speakers.
56
#include "L138_LCDK_aic3106_init.h"
#define N 31
in_buffer[0]=x;
for(i=30;i>0;i--)
in_buffer[i]=in_buffer[i-1];
for(i=0;i<32;i++)
output=output+h[i]*in_buffer[i];
return(output);
57
58
DIGITAL SIGNAL PROCESSING
LESSON PLAN
Subject Code: UE18EC253 Faculty: BNK / ST/ AW/ RM/ SML/ PD/ SB No. of Hours: 56
Chapter Title/ % Portions Covered
Class Portions to be Covered
Reference Literature Individual Cumulative
UNIT I
UNIT II
Efficient Computation of
DFT: Fast Fourier Direct computation of DFT, need for FFT,
Transform Algorithms Radix-2 FFT Algorithms, Decimation in Time
13-22
and Decimation in Frequency FFT Algorithms.
20 40
Text Book 1: chapter 8 Use of FFT in linear filtering.
8.1, 8.2
UNIT III
Analog filters
Introduction, design of Butterworth and
Text Book 1: Chapter 10
23-33 Chebyshev Type I filters, analog to analog
10.3
frequency transformations. 20 60
Text Book 2: Chapter 3
3.0, 3.1, 3.2
UNIT IV
Mapping of transfer function: Approximation of
derivative, bilinear transformation, impulse
Design of IIR filters from invariance, matched z-transform, verification for
analog filters stability and linearity during mapping.
Text Book 1: Chapters 9 & Realization of IIR filters: direct form I and form
34-44 II, cascade, parallel and lattice (all pole)
10 20 80
10.3, 10.4, 9.3 realizations.
Text Book 2: Chapter 5
5.1, 5.2, 5.3
1|3
UNIT V
Introduction to FIR filters, design of FIR filters
FIR filter design using window functions: rectangular, Hamming,
Hanning, Blackman, Bartlett and Kaiser
Text Book 1: Chapters 9 & windows, Hilbert transformer and FIR
45-56 10 differentiator, FIR filter design using frequency
20 100
10.2, 9.2 sampling technique. Introduction to group delay
Text Book 2: Chapter 2 and phase delay.
4.6
Realization of FIR filters: direct form, cascade,
and lattice realizations.
Literature:
Publisher Edition
Text Book 1 Digital Signal Processing: Principles, Pearson Education 4th Edition
Algorithms and Applications by
Proakis and Manolakis
Text Book 2 Fundamentals of Digital Signal John Wiley and Sons 1986
Processing by
L. C. Ludeman
Reference 1 Digital Signal Processing by S. K. TMH Publications 4th Edition
Mitra
Reference 2 Digital Signal Processing by PHI Publications 2003
Oppenheim and Schaffer
Reference 3 Analog and Digital Signal Processing Thomas Learning 1999
by Ashok Ambardar
Assessment
Marks
ISA 40
CBT- I 20
CBT- II 20
ESA 60
2|3
Subject Code: UE18EC255
16 -----------------------------ESA – VIVA-----------------------------------------
Assessment:
ISA Total Marks (60) ESA Total Marks (40)
Observation 20 Quiz 20
Assessment I 20 Viva 20
Assessment II 20
3|3