EC23401- DIGITAL SIGNAL
PROCESSING LABORATORY
LABORATORY MANUAL
MADRAS INSTITUTE OF TECHNOLOGY
ANNA UNIVERSITY
CHROMEPET, CHENNAI-44
EC23401- DIGITAL SIGNAL PROCESSING LABORATORY
Syllabus (Regulation-2023)
1. Generation of sequences
2. Linear and Circular Convolutions
3. Spectral analysis of signals using DFT
4. Pole Zero analysis of Discrete Time systems
5. IIR filter design
6. Frequency response of IIR system
7. FIR filter design
8. Frequency response of FIR system
9. Signal Processing based Mini Project
EX NO:
DATE: GENERATION OF SIGNALS IN MATLAB
Introduction
Signals are broadly classified into continuous and discrete signals. A continuous signal
will be denoted by x(t), in which the variable t can represent any physical quantity. A discrete
signal will be denoted x[n], in which the variable n is integer value. In this lab we will learn
to represent and operate on signals in MATLAB. The variables t and n are assumed to
represent time.
[Link] Time Signals
Run the following three lines and explain why the plots are different.
[Link] the snapshots of the plots for each step given below.
t=0:2*pi;
plot(t,sin(t));
title('CT Signal Plot');
xlabel('t(sec)');
ylabel('y(t)');
figure
t=0:0.2:2*pi;
plot(t,sin(t));
title('CT Signal Plot');
xlabel('t(sec)');
ylabel('y(t)');
figure
t=0:0.02:2*pi;
plot(t,sin(t));
title('CT Signal Plot');
xlabel('t(sec)');
ylabel('y(t)');
axis([0 2*pi -1.2 1.2]);
Explanation
By increasing the sampling rate the accuracy of the signal increases.
[Link] Two Plots On The Same Axis
t=0:0.2:2*pi;
plot(t,sin(t),t,sin(2*t));%two plots on same axis without hold
title('Two Plots On Same Axis');
xlabel('t(sec)');
ylabel('y(t)');
legend('sin(t)','sin(2t)');
axis([0 2*pi -1.2 1.2]);
[Link] A Plot Without Connecting The Points
t=0:0.2:2*pi;
plot(t,sin(t),'.');%only points
title('Plot Without Joining The Points');
xlabel('t(sec)');
ylabel('y(t)');
axis([0 2*pi -1.2 1.2]);
Try The Following Command
t=0:0.2:2*pi;
plot(t,sin(t),'r.');%red points
title('Plot With Red Points');
xlabel('t(sec)');
ylabel('y(t)');
axis([0 2*pi -1.2 1.2]);
Question 1: What does ‘r’ do?
'r' command plots sine wave in red.
Question 2: What does ‘hold’ do? Type doc hold at MATLAB command line for help.
'hold' command holds the figure to plot a second wave.
SYNTAX: hold on
hold off
[Link]-Time Signals
Use stem to plot the discrete-time step function.
n=-10:10;
f=n>=0;
stem(n,f);%discrete plot
title('DT Signal Plot');
xlabel('n--->');
ylabel('y(n)');
NOTE: In MATLAB to represent a sequence a vector array pointing to the position of
the samples in a sequence is also required .For example a sequence z(n) = { 2, 1,-1, 0, 1,
4, 3 7} can be represented in MATLAB by n= [ -3,-2,-1,0,1,2,3,4], x=[2,1,-1,0,1,4,3,7]
3. Elementary sequences in digital signal processing for analysis purposes
For each part below, provide an example using any input and also provide the plots of
input and output sequences using subplot.
a. Unit sample sequence in MATLAB
n=-1:1;
x=[(n)==0];%unit sample
stem(n,x);
title('DT Impulse Plot');
xlabel('n-->');
ylabel('y(n)');
b. Unit step sequence
n=-1:10;
x=[(n)>=0];%unit step
stem(n,x);
title('DT Unit Step Plot');
xlabel('n-->');
ylabel('y(n)');
c. Real Valued Exponential sequence
n=0:10;
x=0.9.^n;%exponential with a=0.9
stem(n,x);
title('DT Exponential Plot');
xlabel('n-->');
ylabel('y(n)');
d. Complex valued exponential sequence
x(n)= , for all n
n=0:10;
x=exp((2+3j)*n);%complex exponential
stem(n,abs(x));
title('DT Complex Exponential Plot');
xlabel('n-->');
ylabel('y(n)');
e. Sinusoidal Sequence
x(n)=cos( n+Θ),for all n
n=0:10;
x=3*cos(0.1*pi*n+pi/3)+2*sin(0.5*pi*n);%sum of sinusoids
stem(n,x);
title('Sum Of Sinusoids Plot');
xlabel('n-->');
ylabel('y(n)');
4. Operations on Sequence
a. Signal addition
It is implemented in MATLAB by the arithmetic operator “+”. However the lengths
of x1(n) and x2(n) must be the same. We can use the following function for addition.
function[z]=SignalAddition;
x=[1 2 3 4 5];
n1=-3:1;
y=[1 2 3 4 5];
n2=1:5;
[z,n]=sigadd(x,n1,y,n2);
subplot(3,1,3);%used to plot many outputs by subdividing area
stem(n,z);
title('DT Signal Addition Output');
xlabel('n-->');
ylabel('z(n)');
end
function[y,n]=sigadd(x1,n1,x2,n2)
n=min(min(n1),min(n2)):max(max(n1),max(n2));
y1=zeros(1,length(n));
y2=y1;
y1(find((n>=min(n1))&(n<=max(n1))==1))=x1;%equalising
subplot(3,1,1);
stem(n,y1);
title('DT Signal Addition Input 1');
xlabel('n-->');
ylabel('x(n)');
y2(find((n>=min(n2))&(n<=max(n2))==1))=x2;%equalising
subplot(3,1,2);
stem(n,y2);
title('DT Signal Addition Input 2');
xlabel('n-->');
ylabel('y(n)');
y=y1+y2;
end
b. Signal Multiplication
It is implemented in MATLAB by the array operator “.*”. To multiply sequences of
different lengths we can use the following function y(n) = x1(n) * x2(n).
function[z]=SignalMultiplication;
x=[1 2 3 2 1];
n1=-2:2;
y=[1 2 3 4 5];
n2=1:5;
[z,n]=sigmult(x,n1,y,n2);
subplot(3,1,3);stem(n,z);
title('DT Signal Multiplication Output');
xlabel('n-->');ylabel('z(n)');
end
function[y,n]=sigmult(x1,n1,x2,n2)
n=min(min(n1),min(n2)):max(max(n1),max(n2));
y1=zeros(1,length(n));y2=y1;
y1(find((n>=min(n1))&(n<=max(n1))==1))=x1;%length
adjustment
subplot(3,1,1);stem(n,y1);
title('DT Signal Multiplication Input 1');
xlabel('n-->');ylabel('x(n)');
y2(find((n>=min(n2))&(n<=max(n2))==1))=x2;%length
adjustment
subplot(3,1,2);stem(n,y2);
title('DT Signal Multiplication Input 2');
xlabel('n-->');ylabel('y(n)');
y=y1.*y2;
end
c. Shifting
o In this operation each sample of x(n) is shifted by an amount k to obtain a
shifted sequence.
• y(n).Y(n) = {x(n-k)}
o If we let m=n-k, then n=m+k and the above operation is given by
• Y(m+k) = {x(m)}
function[x]=SignalShifting;
x=[1 2 3 4 5];
ni=1:5;
subplot(3,1,1);
stem(ni,x);
title('DT Signal Input');
xlabel('n-->');ylabel('x(n)');
axis([-2 8 0 7]);
[z1,n1]=sigshift(x,ni,2);
subplot(3,1,2);
stem(n1,z1);
title('Delayed DT Signal Output x(n-2)');
xlabel('n-->');ylabel('z1(n)');
axis([-2 8 0 7]);
[z2,n2]=sigshift(x,ni,-2);
subplot(3,1,3);stem(n2,z2)
title('Advanced DT Signal Output x(n+2)');
xlabel('n-->');ylabel('z2(n)');
axis([-2 8 0 7]);
end
function[y,n]=sigshift(x,m,n0)
y=x;
n=m+n0;%changing n value
end
[Link]
In this operation each sample of x(n) is flipped around n=0 to obtain folded sequence.
Y(n) = {x(-n)}
function[x]=SignalFolding;
x=[1 2 3 4 5];
ni=1:5;
subplot(2,1,1);
stem(ni,x);
title('DT Signal Input');
xlabel('n-->');
ylabel('x(n)');
[z,n]=sigfold(x,ni);
subplot(2,1,2);
stem(n,z);
title('Folded DT Signal Output x(-n)');
xlabel('n-->');
ylabel('z(n)');
end
function[y,n]=sigfold(x,n)
y=fliplr(x);%reversing x
n=-fliplr(n);%reversing and inverting n
end
[Link] Of CT Signals
To generate Basic type of Continuous time signal like step,impulse,ramp,exponent,..
t=(0:0.01:1);
y=ones(101);%step function
subplot(2,3,1);
plot(t,y,'k-');
title('CT Step Plot');
xlabel('t(sec)');
ylabel('y(t)');
y=[1;zeros(100,1)];%impulse function
subplot(2,3,2)
plot(t,y,'k-');
title('CT Impulse Plot');
xlabel('t(sec)');
ylabel('y(t)');
y=t;%ramp function
subplot(2,3,3)
plot(t,y,'k-');
title('CT Ramp Plot');
xlabel('t(sec)');
ylabel('y(t)');
y=t.^2;%exponent function
subplot(2,3,4)
plot(t,y,'k-');
title('CT Exponent Plot');
xlabel('t(sec)');
ylabel('y(t)');
y=square(2*pi*4*t);%square function
subplot(2,3,5)
plot(t,y,'k-');
title('CT Square Plot');
xlabel('t(sec)');
ylabel('y(t)');
6. Generation Of DT Signals
To generate Basic type of Discrete time signal like step,impulse,ramp,exponent,..
n=([Link]);
y=ones(11);%step function
subplot(2,3,1);
stem(n,y,'k');
title('DT Step Plot');
xlabel('n-->');
ylabel('y(n)');
y=[1;zeros(10,1)];%impulse function
subplot(2,3,2);
stem(y,'k');
title('DT Impulse Plot');
xlabel('n-->');
ylabel('y(n)');
y=n;%ramp function
subplot(2,3,3);
stem(n,y,'k');
title('DT Ramp Plot');
xlabel('n-->');
ylabel('y(n)');
y=n.^2;%exponent function
subplot(2,3,4);
stem(n,y,'k');
title('DT Exponent Plot');
xlabel('n-->');
ylabel('y(n)');
y=square(2*pi*4*n);%square function
subplot(2,3,5);
stem(n,y,'k');
title('DT Square Plot');
xlabel('n-->');
ylabel('y(n)');
Exercises
Generate and plot each of the following sequences over the indicated interval. Provide
the scripts used to generate the plots.
Exercise 1(a)
Z(n)=2del(n+2)-del(n-4)
Code
n=[-5:5];
x1=[(n+2)==0]; %shifting delta function by -2
z1=2*x1; %multiplying x1 by scalar 2
subplot(3,1,1);stem(n,z1);
title('2*del(n+2)');
xlabel('n-->');ylabel('x(n)');
x2=[(n-4)==0]; %shifting delta function by 4
subplot(3,1,2);stem(n,x2);
title('del(n-4)');
xlabel('n-->');ylabel('z(n)');
z=z1-x2; %subtracting the two signals
subplot(3,1,3);stem(n,z);
title('2*del(n+2)-del(n-4)');
xlabel('n-->');ylabel('z(n)');
Exercise 1(b)
X(n)=n[u(n)-u(n-10)]+10exp(-0.3(n-10)[u(n-10)-u(n-20)]
Code
n=[0:20];
x1=[(n)>=0]; %unit step
x2=[(n-10)>=0]; %shifting unit step by 10
x3=x1-x2; %subtracting the signals
x4=n.*x3; %multiplying x3 by n
subplot(3,1,1);stem(n,x4);
title('n*[u(n)-u(n-10)]');
xlabel('n-->');ylabel('x(n)');
x5=[(n-10)>=0]; %shifting unit step by 10
x6=[(n-20)>=0]; %shifting unit step by 20
x7=x5-x6;
x8=exp(-0.3.*(n-10)); %finding exponent using exp function
x9=10.*x8.*x7; %multiplying x8,x7 and scalar 10
subplot(3,1,2);stem(n,x9);
title('10*exp(-0.3*(n-10))*[u(n-10)-u(n-20)]');
xlabel('n-->');ylabel('y(n)');
x=x4+x9;
subplot(3,1,3);stem(n,x);
title('n[u(n)-u(n-10)]+10exp(-0.3(n-10))[u(n-10)-u(n-20)]');
xlabel('n-->');ylabel('z(n)');
Exercise 2:x(n)={1,2,3,4,5,6,7,6,5,4,3,2,1)
Exercise 2(a)
X1(n)=2x(n-5)-3x(n+4)
Code
function[y,n]=exercise
n=[-2:10];
x=[1,2,3,4,5,6,7,6,5,4,3,2,1];
n0=5;
[x1,n1]=sigshift(x,n,n0)%shifting x(n) by 5
n0=-4;
[x2,n2]=sigshift(x,n,n0)%shifting x(n) by -4
x1=2.*x1;%multiplying x1 by 2
subplot(3,1,1);
stem(n1,x1);
title('2x(n-5)');
xlabel('n-->');
ylabel('a(n)');
x2=3.*x2;%multiplying x2 by 3
subplot(3,1,2);
stem(n2,x2);
title('3x(n+4)');
xlabel('n-->');
ylabel('b(n)');
[y,n]=sigsub(x1,n1,x2,n2)%subtracting x1 and x2
subplot(3,1,3);
stem(n,y);
title('2x(n-5)-3x(n+4)');
xlabel('n-->');
ylabel('c(n)');
end
function[y,n]=sigshift(x,m,n0)
y=x;
n=m+n0;
end
function[y,n]=sigsub(x1,n1,x2,n2)
n=min(min(n1),min(n2)):max(max(n1),max(n2));
y1=zeros(1,length(n));
y2=y1;
y1(find((n>=min(n1))&(n<=max(n1))==1))=x1;
y2(find((n>=min(n2))&(n<=max(n2))==1))=x2;
y=y1-y2;
end
Exercise 2(b)
X2(n)=x(3-n)+x(n)x(n-2)
Code
function[y,n]=exercise
n=[-2:10];
x=[1,2,3,4,5,6,7,6,5,4,3,2,1];
n0=-3;
[x1,n1]=sigshift(x,n,n0);%shifting x(n) by -3
[x1,n1]=sigfold(x1,n1);%fold x1
subplot(3,1,1);stem(n1,x1);
title('x(3-n)');
xlabel('n-->');ylabel('a(n)');
n0=2;
[x3,n3]=sigshift(x,n,n0);%shifting x(n) by 2
[x2,n2]=sigmult(x,n,x3,n3);%multiplying x3 with x(n)
subplot(3,1,2);stem(n2,x2);
title('x(n)x(n-2)');
xlabel('n-->');ylabel('b(n)');
[y,n]=sigadd(x1,n1,x2,n2); %adding x1 and x2
subplot(3,1,3);stem(n,y);
title('x(3-n)+x(n)x(n-2)');
xlabel('n-->');ylabel('c(n)');
end
function[y,n]=sigfold(x,n)
y=fliplr(x);n=-fliplr(n);
end
function[y,n]=sigshift(x,m,n0)
y=x;n=m+n0;
end
function[y,n]=sigadd(x1,n1,x2,n2)
n=min(min(n1),min(n2)):max(max(n1),max(n2));
y1=zeros(1,length(n));y2=y1;
y1(find((n>=min(n1))&(n<=max(n1))==1))=x1;
y2(find((n>=min(n2))&(n<=max(n2))==1))=x2;
y=y1+y2;
end
function[y,n]=sigmult(x1,n1,x2,n2)
n=min(min(n1),min(n2)):max(max(n1),max(n2));
y1=zeros(1,length(n));y2=y1;
y1(find((n>=min(n1))&(n<=max(n1))==1))=x1;
y2(find((n>=min(n2))&(n<=max(n2))==1))=x2;
y=y1.*y2;
end
Result:
EX NO:
DATE: LINEAR CONVOLUTION
Aim
To perform Linear Convolution the given Two signals in Matlab.
Theory
In continuous time, the convolution of two signals involves integrating the product of
the two signals where one of the signals is ‘flipped and shifted’ – it doesn’t matter which
signal is flipped and shifted. In discrete time, the convolution of two signals involves
summing the product of the two signals, while the rest are same. Convolution is an operation
between the input signal to a system and it’s impulse response, resulting in the output signal.
If the input signal is x(n) and the impulse response of the system is h(n), then the
output signal y(n) is given by
y(n)=x(n)*h(n)
Procedure
1. The two sequences x(n) and h(n) are given.
2. Fold h(n) about n=0 to get h(-n).
3. Increase m from 0 to length(x(n))+length(h(n))-2.
4. Find the product of x(n) and h(m-n) in each case.
5. And find sum of the elements in each case.
6. Repeat the step 3 until there is no overlap.
7. The output y(n) is the results of step 4.
Inputs and Code
function[z,n]=LinearConvolution;
n1=0:4;
x=[1,2,3,4,5];
subplot(3,1,1);
stem(n1,x);
title('Input x(n)');
xlabel('n-->');ylabel('x(n)');
n2=0:4;
h=[1,1,1,1,1];
subplot(3,1,2);
stem(n2,h);
title('Impulse h(n)');
xlabel('n-->');ylabel('h(n)');
[z1,m1]=sigfold(h,n2); %fold h(n)
i1=min(min(n1),min(n2));
i2=((max(n1)-min(n1))+(max(n2)-min(n2))+1);
z=zeros(1,i2-i1);
for i=i1:i2 %repeat
[z2,m2]=sigshift(z1,m1,i); %shift folded h(n) everytime
[y,n]=sigmult(x,n1,z2,m2); %multiply shifted h(n) with x(n)
z(i+1)=y; %store the sum of all elements in
each sequence
end
i=i1+1:i2+1;
subplot(3,1,3);
stem(i,z);
title('y(n)=x(n)*h(n)');
xlabel('n-->');ylabel('y(n)');
axis([i1+1 i2 0 20]);
end
function[y,n]=sigshift(x,m,n0)
n=m+n0;
y=x;
end
function[y,n]=sigfold(x,n)
y=fliplr(x);
n=-fliplr(n);
end
function[y,n]=sigmult(x1,n1,x2,n2)
n=min(min(n1),min(n2)):max(max(n1),max(n2));
y1=zeros(1,length(n));
y2=y1;
y1(find((n>=min(n1))&(n<=max(n1))==1))=x1;
y2(find((n>=min(n2))&(n<=max(n2))==1))=x2;
y=y1.*y2;
y=sum(y);
end
Output
1 3 6 10 15 14 12 9 5
Result
EX NO:
DATE: CIRCULAR CONVOLUTION
Aim
To perform circular convolution of two signals using MATLAB.
Theory
Consider two finite sequences x(n) and h(n) both of length N, the resultant signal y(n)
nothing but circular convolved signal of the two signals.
In linear convolution, the computation of sequence values y(n) involves multiplying
one sequence by a version of the other and then summing the values of x(m) and h(n-m) over
all m. In circular convolution, the sequence h(n) is circularly time reversed and circularly
shifted with respect to the first. Both the input sequences are of length N and the output
sequence is also of the length N.
Procedure
1. Enter the two sequences x(n) and h(n).
2. Add length(x(n))-length(h(n)) zeros at the end of the smaller sequence to
make lengths equal.
3. Fold h(n).
4. Rotate h(n) by changing from row to column, use circshift, then again
changing to row.
5. Multiply x(n) and present h(n) and find the sum of all values in the sequence.
6. Goto step 4.
7. Results in step 5 gives the output.
Inputs and Code
function[y,n]=circularConvolution;
x=[1,2,3,4,5];
h=[1,2,3];
n1=1:length(x);
n2=1:length(h);
subplot(3,1,1);
stem(n1,x);
title('Input x(n)');
xlabel('n-->');ylabel('x(n)');
subplot(3,1,2);
stem(n2,h);
title('Impulse h(n)');
xlabel('n-->');ylabel('h(n)');
n=max(max(n1),max(n2));
x=[x,zeros(1,n-max(n1))]; %length adjustment
h=[h,zeros(1,n-max(n2))]; %length adjustment
n1=1:n;
n2=1:n;
h=sigfold(h,n2); %fold h
h=h';h=circshift(h,1);h=h'; %circular shift of h
for i=1:n
y(i)=sigmult(x,n1,h,n2); %multiply shifted h with x
h=h';h=circshift(h,1);h=h'; %circular shift of h
end
subplot(3,1,3);
stem(1:n,y);
title('y(n)=circconv(x(n),h(n))');
xlabel('n-->');ylabel('y(n)');
end
function[y,n]=sigfold(x,n)
y=fliplr(x);
end
function[y]=sigmult(x1,n1,x2,n2)
n=min(min(n1),min(n2)):max(max(n1),max(n2));
y1=zeros(1,length(n));
y2=y1;
y1(find((n>=min(n1))&(n<=max(n1))==1))=x1;
y2(find((n>=min(n2))&(n<=max(n2))==1))=x2;
y=y1.*y2;y=sum(y); %give sum of elements in a
sequence
end
Output:
23 19 10 16 22
Result
EX NO:
DATE: OVERLAP SAVE METHOD
Aim
To perform linear convolution of given two signals by overlap save method using
MATLAB.
Theory
In this method, the data sequence is divided into N point section x1(n),.... Each
section contains the last (m-1) data points of the previous section followed by L new data
points to form a data sequence of length N=L+m-1. If we take N-pt circular convolution of
x1(n) and h(n), because of aliasing, the remaining (N-M+1) points however will agree with
the linear convolution. Hence we discard the first m-1 points of the circular convolved
signals.
Procedure
1. The two sequences x(n) and h(n) are given.
2. N1=length of x(n) and N2=length of h(n).
3. Add required number of zeros before and after x(n)so as to get a perfect overlapped
sequence.
4. Separate the input sequence into a number of smaller sequences of length N2 by
overlapping with last N2-1 values of the previous section.
5. Find circular convolution of each of the smaller sequence with h(n).
6. Write down the output sequence y(n) by neglecting off the first n values in each
sequence(where n is number of overlaps).
Inputs and Code
function[z,n]=overlapsave;
x=[1,-2,3,4,4];h=[1,2,-2];
n1=length(x);
n2=length(h);q1=n1;q2=n2;
subplot(3,1,1);stem(x);
title('Input x(n)');
xlabel('n-->');ylabel('x(n)');
subplot(3,1,2);stem(h);
title('Impulse h(n)');
xlabel('n-->');ylabel('h(n)');
n3=n1+n2-1;
n4=n2-1;
x=[zeros(1,n4),x];
h=[h,zeros(1,n4)];
n1=length(x);
n2=length(h);
h=sigfold(h,n2); %fold h
h=h';h=circshift(h,1);h=h'; %circular shift of h
w=1;
z=zeros(1,n3);
n5=mod(n1,(n2-n4));
n6=(n2-n4)-1;
n8=1:n2;
if n5==0
x=[x,zeros(1,n6)];%adding required number of zeros to meet
overlap
else
x=[x,zeros(1,(2*n6)-(n5-1)*1)];%adding required number of
zeros
end
n1=length(x);
q=h;
n7=(((n1+1)/(n2-n4))-1); %total number of
multiplications
for i=1:n7
h=q;
for j=1:n2
y(j)=x(j+(i-1)*(n2-n4)); %selecting the portion of x
with overlap
end
for k=1:n4
h=h';
h=circshift(h,1);h=h'; %circular shift h no of overlap
times
end
for e=1:(n2-n4)
z(w)=sigmult(y,n8,h,n8); %multiply h and y
h=h';h=circshift(h,1);h=h'; %circular shift h
w=w+1;
end
end
subplot(3,1,3);stem(z);
title('y(n)=x(n)*h(n)');
xlabel('n-->');ylabel('y(n)');
axis([1 q1+q2-1 -20 20]);
end
function[y,n]=sigfold(x,n)
y=fliplr(x);
end
function[y]=sigmult(x1,n1,x2,n2)
n=min(min(n1),min(n2)):max(max(n1),max(n2));
y1=zeros(1,length(n));y2=y1;
y1(find((n>=min(n1))&(n<=max(n1))==1))=x1;
y2(find((n>=min(n2))&(n<=max(n2))==1))=x2;
y=y1.*y2;
y=sum(y);
end
Output: 1 0 -3 14 6 0 -8
Result
EX NO:
DATE: DISCRETE FOURIER TRANSFORM
Aim
To obtain the discrete Fourier transform of the given sequence using MATLAB.
Theory
In mathematics, the discrete Fourier transform (DFT) converts a finite sequence of
equally-spaced samples of a function into an equivalent-length sequence of equally-spaced
samples of the discrete-time Fourier transform(DTFT), which is a complex-valued function
of frequency. The interval at which the DTFT is sampled is the reciprocal of the duration of
the input sequence. An inverse DFT is a Fourier series, using the DTFT samples as
coefficients of complex sinusoids at the corresponding DTFT frequencies. It has the same
sample-values as the original input sequence.
The DFT is therefore said to be a frequency domain representation of the original
input sequence. If the original sequence spans all the non-zero values of a function, its DTFT
is continuous (and periodic), and the DFT provides discrete samples of one cycle. If the
original sequence is one cycle of a periodic function, the DFT provides all the non-zero
values of one DTFT [Link] DFT is the most important discrete transform, used to
perform Fourier analysis in many practical applications.
MATLAB Code
function[y]=dft;
x=[1,0,0,0,0,0,0,0];
figure(1)
stem(x);
title('input');
xlabel('n--->');
ylabel('x(n)');
n=length(x);
n1=1:n;
y=zeros(1,n);
for i=1:n
for j=1:n
y(i)=y(i)+x(j).*complex(cos((2*pi*(j-1)*(i-1))/n),-
sin((2*pi*(j-1)*(i-1))/n));
end
end
figure(2)
subplot(1,2,1);
stem(abs(y));
title('DFT Magnitude Plot');
xlabel('n--->');
ylabel('y(n)');
subplot(1,2,2);
stem(angle(y));
title('DFT Phase Plot');
xlabel('n--->');
ylabel('y(n)');
end
Input
Output
Result
EX NO:
DATE: INVERSE DISCRETE FOURIER
TRANSFORM
Aim
To obtain the inverse discrete Fourier transform of the given sequence using
MATLAB.
Theory
The Fourier transform takes a signal in the so called time domain (where each sample
in the signal is associated with a time) and maps it, without loss of information, into the
frequency domain. The frequency domain representation is exactly the same signal, in a
different form. The inverse Fourier transform maps the signal back from the frequency
domain into the time domain.
A time domain signal will usually consist of a set of real values, where each value has
an associated time (e.g., the signal consists of a time series). The Fourier transform maps the
time series into a frequency domain series, where each value is a complex number that is
associated with a given frequency. The inverse Fourier transform takes the frequency series
of complex values and maps them back into the original time series. Assuming that the
original time series consisted of real values, the result of the IDFT will be complex numbers
where the imaginary part is zero.
MATLAB Code
function[y]=idft;
x=[20,-5.828-2.414i,0,-0.1716-0.4142i,0,-0.1716+0.4142i,0,-
5.828+2.4142i];
figure(1)
subplot(1,2,1);
stem(abs(x));
title('input Magnitude Plot');
xlabel('n--->');
ylabel('x(n)');
subplot(1,2,2);
stem(angle(x));
title('input Phase Plot');
xlabel('n--->');
ylabel('x(n)');
n=length(x);
n1=1:n;
y=zeros(1,n);
for i=1:n
for j=1:n
y(i)=(y(i)+x(j).*complex(cos((2*pi*(j-1)*(i-
1))/n),sin((2*pi*(j-1)*(i-1))/n)));
end
end
y=y/n;
figure(2)
stem(abs(y));
title('IDFT Plot');
xlabel('n--->');
ylabel('y(n)');
end
Input
Output
Result
EX NO:
DATE: FAST FOURIER TRANSFORM
Aim
To determine the discrete Fourier transform of the given sequence using Fast Fourier
Transform Algorithms in MATLAB.
Theory
Fast Fourier Transform was proposed by Cooley and Tukey in 1965. It is based on
decomposition and breaking of the transform into smaller Transforms and combining them to
get the total transform.
DFT can be implemented in computers by numerical algorithms or even
dedicated hardware. These implementations usually employ efficient fast Fourier
transform (FFT) algorithms;[3] so much so that the terms "FFT" and "DFT" are often used
interchangeably. Prior to its current usage, the "FFT" initialism may have also been used for
the ambiguous term "finite Fourier transform".
DIF:
DIT:
Decimation in time
Input
Output
MATLAB Code
DECIMATION IN TIME
function[q]=fftdit;
x=[1,2,3,4,4,3,2,1];
figure(1)
stem(x);
title('input');
xlabel('n--->');ylabel('x(n)');
n=length(x);
n1=1:n;
f=x(2);
x(2)=x(5);
x(5)=f;
f=x(7);
x(7)=x(4);
x(4)=f;
for i=1:n/8
y(i)=(x(i)+x(n/8+i).*complex(cos((2*pi*(i-1)*(n/8))/n),-
sin((2*pi*(i-1)*(n/8))/n)));
y(i+n/8)=(x(i)-x(n/8+i).*complex(cos((2*pi*(i-1)*(n/8))/n),-
sin((2*pi*(i-1)*(n/8))/n)));
y(i+2*n/8)=(x(i+2*n/8)+x(n/8+i+2*n/8).*complex(cos((2*pi*(i-
1)*(n/8))/n),-sin((2*pi*(i-1)*(n/8))/n)));
y(i+2*n/8+n/8)=(x(i+2*n/8)-
x(n/8+i+2*n/8).*complex(cos((2*pi*(i-1)*(n/8))/n),-
sin((2*pi*(i-1)*(n/8))/n)));
y(i+4*n/8)=(x(i+4*n/8)+x(n/8+i+4*n/8).*complex(cos((2*pi*(i-
1)*(n/8))/n),-sin((2*pi*(i-1)*(n/8))/n)));
y(i+4*n/8+n/8)=(x(i+4*n/8)-
x(n/8+i+4*n/8).*complex(cos((2*pi*(i-1)*(n/8))/n),-
sin((2*pi*(i-1)*(n/8))/n)));
y(i+6*n/8)=(x(i+6*n/8)+x(n/8+i+6*n/8).*complex(cos((2*pi*(i-
1)*(n/8))/n),-sin((2*pi*(i-1)*(n/8))/n)));
y(i+6*n/8+n/8)=(x(i+6*n/8)-
x(n/8+i+6*n/8).*complex(cos((2*pi*(i- 1)*(n/8))/n),-
sin((2*pi*(i-1)*(n/8))/n)));
end
for i=1:n/4
z(i)=(y(i)+y(n/4+i).*complex(cos((2*pi*(i-1)*(n/4))/n),-
sin((2*pi*(i-1)*(n/4))/n)));
z(i+n/4)=(y(i)-y(n/4+i).*complex(cos((2*pi*(i-1)*(n/4))/n),-
sin((2*pi*(i-1)*(n/4))/n)));
z(i+2*n/4)=(y(i+2*n/4)+y(n/4+i+2*n/4).*complex(cos((2*pi*(i-
1)*(n/4))/n),-sin((2*pi*(i-1)*(n/4))/n)));
z(i+2*n/4+n/4)=(y(i+2*n/4)-
y(n/4+i+2*n/4).*complex(cos((2*pi*(i-1)*(n/4))/n),-
sin((2*pi*(i-1)*(n/4))/n)));
end
for i=1:(n/2)
q(i)=(z(i)+z(n/2+i).*complex(cos((2*pi*(i-1))/n),-
sin((2*pi*(i-1))/n)));
q(i+n/2)=(z(i)-z(n/2+i).*complex(cos((2*pi*(i-1))/n),-
sin((2*pi*(i-1))/n)));
end
figure(2)
subplot(1,2,1);
stem(abs(q));
title('FFT DIT Magnitude Plot');
xlabel('n--->');ylabel('y(n)');
subplot(1,2,2);
stem(angle(q));
title('FFT DIT Phase Plot');
xlabel('n--->');
ylabel('y(n)');
end
Decimation in frequency
Input
Output
DECIMATION IN FREQUENCY
function[q]=fftdif;
x=[1,2,3,4,4,3,2,1];
figure(1)
stem(x);
title('input');
xlabel('n--->');
ylabel('x(n)');
n=length(x);
n1=1:n;
for i=1:(n/2)
y(i)=x(i)+x(n/2+i);
y(i+n/2)=(x(i)-x(n/2+i)).*complex(cos((2*pi*(i-1))/n),-
sin((2*pi*(i-1))/n));
end
for i=1:n/4
z(i)=y(i)+y(n/4+i);
z(i+n/4)=(y(i)-y(n/4+i)).*complex(cos((2*pi*(i-1)*(n/4))/n),-
sin((2*pi*(i-1)*(n/4))/n));
z(i+2*n/4)=y(i+2*n/4)+y(n/4+i+2*n/4);
z(i+2*n/4+n/4)=(y(i+2*n/4)-
y(n/4+i+2*n/4)).*complex(cos((2*pi*(i-1)*(n/4))/n),-
sin((2*pi*(i-1)*(n/4))/n));
end
for i=1:n/8
q(i)=z(i)+z(n/8+i);
q(i+n/8)=(z(i)-z(n/8+i)).*complex(cos((2*pi*(i-1)*(n/8))/n),-
sin((2*pi*(i-1)*(n/8))/n));
q(i+2*n/8)=z(i+2*n/8)+z(n/8+i+2*n/8);
q(i+2*n/8+n/8)=(z(i+2*n/8)-
z(n/8+i+2*n/8)).*complex(cos((2*pi*(i-1)*(n/8))/n),-
sin((2*pi*(i-1)*(n/8))/n));
q(i+4*n/8)=z(i+4*n/8)+z(n/8+i+4*n/8);
q(i+4*n/8+n/8)=(z(i+4*n/8)-
z(n/8+i+4*n/8)).*complex(cos((2*pi*(i-1)*(n/8))/n),-
sin((2*pi*(i-1)*(n/8))/n));
q(i+6*n/8)=z(i+6*n/8)+z(n/8+i+6*n/8);
q(i+6*n/8+n/8)=(z(i+6*n/8)-
z(n/8+i+6*n/8)).*complex(cos((2*pi*(i-1)*(n/8))/n),-
sin((2*pi*(i-1)*(n/8))/n));
end
f=q(2);
q(2)=q(5);
q(5)=f;
f=q(7);
q(7)=q(4);
q(4)=f;
figure(2)
subplot(1,2,1);
stem(abs(q));
title('FFT DIF Magnitude Plot');
xlabel('n--->');ylabel('y(n)');
subplot(1,2,2);
stem(angle(q));
title('FFT DIF Phase Plot');
xlabel('n--->');ylabel('y(n)');
end
Result
EX NO:
DATE: DIGITAL IIR FILTER DESIGN
Butterworth IIR LPF and HPF using Bi-linear Transformation
Aim
To design a digital Butterworth IIR LPF and HPF using bi-linear transformation.
Theory
In a digital filter design we have two kinds IIR and FIR. In IIR the length of h[n] is
infinite. IIR filter has fewer side lobes in the stop band when compared with FIR filter. IIR
filter is designed using Butterworth and Chebyshev filter. AnalogButterworth filter is
maximally flat filter and all pole filters. Analog IIR filter can be transformed to digital filter
using BLT or IIT. In BLT conformal mapping is done that maps the jΩ axis into the unit
circle in Z plane only once, thus avoiding aliasing of frequency components. Here both poles
and zeros are transformed.
MATLAB Code
clc;
close all;
clear all;
dp=input('Enter Passband attn:');
ds=input('Enter Stopband attn:');
wp=input('Enter Passband freq:');
ws=input('Enter Stopband freq:');
T=input('Enter T:');
wp1=((2/T)*tan(wp/2));
ws1=((2/T)*tan(ws/2));
dp1=((1/(dp*dp))-1);
ds1=((1/(ds*ds))-1);
N=((log10(sqrt(ds1/dp1)))/(log10(ws1/wp1)));
N=ceil(N);
wc=(wp1/((dp1)^(1/(2*N))));
fs=1/T;
[b,a]=butter(N,wc/(pi*fs),’low’);
freqz(b,a);
title(‘Butterworth IIR LPF using BLT’);
[b,a]=butter(N,wc/(pi*fs),’high’);
figure;
freqz(b,a);
title(‘Butterworth IIR HPF using BLT’);
Output
Butterworth IIR LPF and HPF using Impulse Invariance Transform
Aim
To design a digital Butterworth IIR LPF and HPF using IIT.
Theory
We can design a digital filter from an analog filter using two transformation BLT and
IIT. In IIT , the impulse response ha(t) and ha (nT) are equal but we cannot say that other
responses are same. In IIT we convert the transfer function Ha (s) to time domain ha(t) then
we sample it with the sampling period T to get ha(nT) which is invariant from h[n] we take z
transform to get H(z). This is applicable only for poles as zeros are not transformed in this
method.
ɷ=ΩT
MATLB Code
clc;
close all;
clear all;
dp=input('Enter Passband attn:');
ds=input('Enter Stopband attn:');
wp=input('Enter Passband freq:');
ws=input('Enter Stopband freq:');
T=input('Enter T:');
wp1=wp/T;
ws1=ws/T;
dp1=((1/(dp*dp))-1);
ds1=((1/(ds*ds))-1);
N=((log10(sqrt(ds1/dp1)))/(log10(ws1/wp1)));
N=ceil(N);
wc=(wp1/((dp1)^(1/(2*N))));
fs=1/T;
[b,a]=butter(N,wc/(pi*fs),’low’);
freqz(b,a);
title(‘Butterworth IIR LPF using IIT’);
[b,a]=butter(N,wc/(pi*fs),’high’);
figure;
freqz(b,a);
title(‘Butterworth IIR HPF using IIT’);
Output
Chebyshev IIR LPF and HPF using BLT
Aim
To design a digital Chebyshev IIR LPF and HPF using BLT.
Theory
IIR filter can be designed using Butterworth and Chebyshev filters. In Chebyshev
filters there are two types Type-I and Type-II. In Type-I there are ripples in the passband and
monotonic behaviour in the stopband while in the Type-II there are ripples in the stopband
and monotonic behaviour in the passband. Chebyshev filter is an optimum filter when
compared with Butterworth filter. We can design a digital IIR filter from an analog
Chebyshev filter using BLT.
MATLAB Code
clc;
close all;
clear all;
dp=input('Enter Passband attn:');
ds=input('Enter Stopband attn:');
wp=input('Enter Passband freq:');
ws=input('Enter Stopband freq:');
T=input('Enter T:');
wp1=((2/T)*tan(wp/2));
ws1=((2/T)*tan(ws/2));
dp1=((1/(dp*dp))-1);
ds1=((1/(ds*ds))-1);
N=((acosh(sqrt(ds1/dp1)))/(acosh(ws1/wp1)));
N=ceil(N);
fs=1/T;
dp2=20*log10(dp);
[b,a]=chebyl(N,-dp2,wp1/(pi*fs),’low’);
freqz(b,a);
title(‘Chebyshev IIR LPF using BLT’);
[b,a]=chebyl(N,-dp2,wp1/(pi*fs),’high’);
figure;
freqz(b,a);
title(‘Chebyshev IIR HPF using BLT’);
Output
Chebyshev IIR LPF and HPF using IIT
Aim
To design a digital Chebyshev IIR LPF and HPF using BLT.
Theory
One of the methods converting an analog Chebyshev IIR to a digital filter is by IIT.
First we find analog transfer function Ha(s) then we convert it into h(t)by inverse laplace
transform. Now h(t) is sampled to get h(nT) from which can easily find the transfer function
of a digital filter H(z). This is applicable only for poles and zeros are not transformed in
Impulse Invariance Transform method.
ɷ=ΩT
MATLAB Code
clc;
close all;
clear all;
dp=input('Enter Passband attn:');
ds=input('Enter Stopband attn:');
wp=input('Enter Passband freq:');
ws=input('Enter Stopband freq:');
T=input('Enter T:');
wp1=wp/T;
ws1=ws/T;
dp1=((1/(dp*dp))-1);
ds1=((1/(ds*ds))-1);
N=((acosh(sqrt(ds1/dp1)))/(acosh(ws1/wp1)));
N=ceil(N);
fs=1/T;
dp2=20*log10(dp);
[b,a]=chebyl(N,-dp2,wp1/(pi*fs),’low’);
freqz(b,a);
title(‘Chebyshev IIR LPF using IIT’);
[b,a]=chebyl(N,-dp2,wp1/(pi*fs),’high’);
figure;
freqz(b,a);
title(‘Chebyshev IIR HPF using IIT’);
Output
Practices
Design a Analog Low Pass Filter and convert it to HPF, BPF and BSF
Observe the response for higher order filters
Result
EX NO:
DATE: DIGITAL FIR FILTER DESIGN
Aim
To design a digital lowpass, highpass, bandpass and bandstop FIR filter using
MATLAB.
Theory
A finite impulse response filter is a filter whose impulse response is of finite duration,
because it settles to zero in finite time. This is in contrast to IIR filter which may have
internal feedback and may continue to response indefinitely. An FIR filter has number of
useful properties.
Requires no feedback.
Are inherently stable.
Can easily be designed to linear phase.
The main disadvantage of FIR filter is that considerably more computation power in a
general purpose processor is required.
There are two design methods of FIR filter windowing and frequency sampling
method. In windowing there are many windows like rectangular, triangular, Blackman,
Bartlett, Hamming, Hanning etc,.
MATLAB Code
clc;
close all;
clear all;
M=input('Enter the no. of co-efficient:');
fp=input('Enter Passband edge freq:');
fs=input('Enter sampling freq:');
N=M-1;
fn=fp/(fs/2);
b=fir1(N,fn,'low');
freqz(b);
title('LPF');
b=fir1(N,fn,'high');
figure;
Output
freqz(b);
title('HPF');
f1=input('Enter the freq f1 of BPF:');
f2=input('Enter the freq f2 of BPF:');
b=fir1(N,[f1/pi f2/pi],window);
figure;
freqz(b);
title('BPF');
b=fir1(N,[f1/pi f2/pi],'stop', window);
figure;
freqz(b);
title('BSF');
Result
EX NO: POLE ZERO ANALYSIS OF DISCRETE TIME
DATE: SYSTEM
Aim
To obtain impulse response sequence and plot Pole Zero plot for the given difference
equation of a Discrete Time System.
Theory
Consider the discrete-time LTI system, characterized by its pulse response {hn}:
the output to an input sequence {fn} is given by the convolution sum:
where {hn} is the pulse response. Using the convolution property of the z-transform we have
at the output
Y (z)= F (z)H(z)
where F (z)= Z{fn}, and H(z)= Z{hn}.
In general, for LTI systems the transfer function will be a rational function of z, and may
be written in terms of z or z−1, for example
where the bi, i =0,...,m, ai, i =0,...,n are constant coefficients.
The stability of continuous time systems is governed by pole locations - for a system
to be BIBO stable all poles must lie in the l.h. s-plane. Here we do a preliminary investigation
of stability of discrete-time systems, based on z-plane pole locations of H(z). Consider the
pulse response hn of the causal system with
with a single real pole at z = a and with a difference equation yn = ayn−1 + fn.
The nature of the pulse response will depend on the pole location:
0 <a<1: In this case hn = an will be a decreasing function of n and limn→∞ hn = 0 and
the system is stable.
a =1: The difference equation is yn = yn−1 + fn (the system is a summer and the
impulse response is hn = 1, (non-decaying). The system is marginally stable.
a>1: In this case hn = an will be a increasing function of n and limn→∞ h = ∞ and
the system is unstable.
−1 <a<0: In this case hn = an will be a oscillating but decreasing function of n and
limn→∞ hn = 0 and the system is stable.
a = −1: The difference equation is yn = −yn−1 + fn and the impulse response is hn =(−1)n
that is a pure oscillator. The system is marginally stable.
a<−1: In this case hn = an will be a oscillating but increasing function of n and
limn→∞ |hn| = ∞ and the system is unstable.
H = tf([2 5 1],[1 3 5]);
[p,z] = pzmap(H)
zplane(z,p)
p =
-1.5000 + 1.6583i
-1.5000 - 1.6583i
z =
-2.2808
-0.2192
>> a=[1 3 5]
>> b=[2 5 1];
>> z=roots(b)
z =
-2.2808
-0.2192
>> p=roots(a)
p =
-1.5000 + 1.6583i
-1.5000 - 1.6583i
>> zplane(z,p)
Result
EX NO:
DATE: MINI PROJECT
Students were assigned with technical topic for their Mini-Project
a) Project Status Report - Weekly Report (Duration: Monday to next Friday)
b) Project Report: The following is the format to prepare project report,
(i) Objective of the Project
(ii) Literature Survey
(iii) Block diagram and the associated theory
(iv) Algorithm for the topic
(v) Programme Code: Coding platform and Code
(vi) Display of Output
(vii) Discussion on outcome of the Mini-project
(viii) References
c) Viva Voce for the Mini-project