SlideShare uma empresa Scribd logo
1 de 173
FLOWCHART:
1 UR11EC098
START
ENTER THE SIGNAL
PARAMETERS (AMPLITUDE,
TIME AND FREQUENCY)
Generate the waveform by using the appropriate
library function
PLOT THE WAVEFORMS
STOP
AIM:
Write a program in MATLAB to generate the following waveforms
(Discrete – Time signal and Continuous – Time
signal)
1. Unit
Impulse
sequence,
2. Unit step
sequence,
3. Unit Ramp
sequence,
4. Sinusoidal
sequence,
5. Exponential
sequence,
6. Random
sequence,
1. Pulse signal,
2. Unit step
signal
3. Ramp signal
4. Sinusoidal
signal,
5. Exponential
signal,
6. R
a
n
d
o
m
s
i
g
n
a
l
APPARATUS REQUIRED:
2 UR11EC098
Ex. No :1
Date:09-12-13
Ex. No :1
Date:09-12-13 WAVEFORM GENERATIONWAVEFORM GENERATION
Pentium 4 Processor, MATLAB software
THEORY:
Real signals can be quite complicated. The study
of signals therefore starts with the analysis of basic
and fundamental signals. For linear systems, a
complicated signal and its behaviour can be
studied by superposition of basic signals. Common
basic signals are:
Discrete – Time signals:
• Unit impulse sequence. x n n
n
( ) ( )
,
= =
=


δ
1 0
0
for
, otherwise
• Unit step sequence. x n u n
n
( ) ( )
,
= =
≥


1 0
0
for
, otherwise
• Unit ramp sequence. x n r n
n n
( ) ( )
,
= =
≥


for
, otherwise
0
0
• Sinusoidal sequence. x n A n( ) sin( )= +ϖ φ .
• Exponential sequence. x(n) = A an
, where A and
a are constant.
Continuous – time signals:
• Unit impulse signal.
• Unit step signal.
• Unit ramp signal.
• Sinusoidal signal. .
• Exponential signal. , where A
and a are constant.
3 UR11EC098
x t r t
t t
( ) ( )
,
= =
≥


for
, otherwise
0
0
x t A( ) sin
(
)= +(ϖt
Τ
φ
x t
a
t
( ) = A e at
x t t
t
( ) ( )
,
= =
=


δ
1 0
0
for
, otherwise
x u t
t
(t ) ( )
,
= =
≥


1 0
0
for
, otherwise
LIBRARY FUNCTIONS:
clc:
CLC Clear command window.
CLC clears the command window and
homes the cursor.
clear all:
CLEAR Clear variables and functions from
memory. CLEAR removes all
variables from the workspace.CLEAR
VARIABLES does the same thing.
close all:
CLOSE Close figure.CLOSE, by itself,
closes the current figure window.
CLOSE ALL closes all the open figure
windows.
exp:
EXP Exponential.
EXP(X) is the exponential of the elements
of X, e to the X.
input:
INPUT Prompt for user input.
R = INPUT('How many apples') gives the
user the prompt in the text string and then
waits for input from the keyboard. The input
can be any MATLAB expression, which is
evaluated,using the variables in the current
workspace, and the result returned in R. If
the user presses the return key without
entering anything, INPUT returns an empty
matrix.
linspace:
LINSPACE Linearly spaced vector.
4 UR11EC098
LINSPACE(X1, X2) generates a row vector
of 100 linearly equally spaced points
between X1 and X2.
rand:
The rand function generates arrays of
random numbers whose elements are
uniformly distributed in the interval (0,1).
ones:
ONES(N) is an N-by-N matrix of ones.
ONES(M,N) or ONES([M,N]) is an M-by-N
matrix of ones.
zeros:
ZEROS(N) is an N-by-N matrix of Zeros.
ZEROS(M,N) or ZEROS([M,N]) is an M-
by-N matrix of zeros
plot:
PLOT Linear plot.
PLOT(X,Y) plots vector Y versus vector X.
If X or Y is a matrix, then the vector is
plotted versus the rows or columns of the
matrix, whichever line up.
subplot:
SUBPLOT Create axes in tiled positions.
H = SUBPLOT(m,n,p), or SUBPLOT(mnp),
breaks the Figure window into an m-by-n
matrix of small axes, selects the p-th axes
for the current plot, and returns the axis
handle. The axes are counted along the top
row of the Figure window, then the second
row, etc.
5 UR11EC098
stem:
STEM Discrete sequence or "stem" plot.
STEM(Y) plots the data sequence Y as
stems from the x axis terminated with circles
for the data value.
STEM(X,Y) plots the data sequence Y at the
values specified in X.
title:
TITLE Graph title.
TITLE('text') adds text at the top of the
current axis.
xlabel:
XLABEL X-axis label.
XLABEL('text') adds text beside the X-axis
on the current axis.
ylabel:
YLABEL Y-axis label.
YLABEL('text') adds text beside the Y-axis
on the current axis.
ALGORITHM/PROCEDURE:
1. Start the program
2. Get the inputs for signal generation
3. Use the appropriate library function
4. Display the waveform
Source code :
%WAVE FORM GENERATION
%CT SIGNAL
%UNIT IMPULSE
clc;
clear all;
6 UR11EC098
close all;
t1=-3:1:3;
x1=[0,0,0,1,0,0,0];
subplot(2,3,1);
plot(t1,x1);
xlabel('time');
ylabel('Amplitude');
title('Unit impulse signal');
%UNIT STEP SIGNAL
t2=-5:1:25;
x2=[zeros(1,5),ones(1,26)];
subplot(2,3,2);
plot(t2,x2);
xlabel('time');
ylabel('Amplitude');
title('Unit step signal');
%EXPONENTIAL SIGNAL
a=input('Enter the value of a:');
t3=-10:1:20;
x3=exp(-1*a*t3);
subplot(2,3,3);
plot(t3,x3);
xlabel('time');
ylabel('Amplitude');
title('Exponential signal');
%UNIT RAMP SIGNAL
t4=-10:1:20;
x4=t4;
subplot(2,3,4);
plot(t4,x4);
xlabel('time');
ylabel('Amplitude');
title('Unit ramp signal');
%SINUSOIDAL SIGNAL
A=input('Enter the amplitude:');
f=input('Enter the frequency:');
t5=-10:1:20;
x5=A*sin(2*pi*f*t5);
subplot(2,3,5);
7 UR11EC098
plot(t5,x5)
xlabel('time');
ylabel('Amplitude');
title('Sinusoidal signal');
%RANDOM SIGNAL
t6=-10:1:20;
x6=rand(1,31);
subplot(2,3,6);
plot(t6,x6);
xlabel('time');
ylabel('Amplitude');
title('Random signal');
%WAVE FORM GENERATION
%DT SIGNAL
%UNIT IMPULSE
clc;
clear all;
close all;
n1=-3:1:3;
x1=[0,0,0,1,0,0,0];
subplot(2,3,1);
stem(n1,x1);
xlabel('time');
ylabel('Amplitude');
title('Unit impulse signal');
%UNIT STEP SIGNAL
n2=-5:1:25;
x2=[zeros(1,5),ones(1,26)];
subplot(2,3,2);
stem(n2,x2);
xlabel('time');
ylabel('Amplitude');
title('Unit step signal');
%EXPONENTIAL SIGNAL
a=input('Enter the value of a:');
n3=-10:1:20;
x3=power(a,n3);
subplot(2,3,3);
8 UR11EC098
stem(n3,x3);
xlabel('time');
ylabel('Amplitude');
title('Exponential signal');
%UNIT RAMP SIGNAL
n4=-10:1:20;
x4=n4;
subplot(2,3,4);
stem(n4,x4);
xlabel('time');
ylabel('Amplitude');
title('Unit ramp signal');
%SINUSOIDAL SIGNAL
A=input('Enter the amplitude:');
f=input('Enter the frequency:');
n5=-10:1:20;
x5=A*sin(2*pi*f*n5);
subplot(2,3,5);
stem(n5,x5);
xlabel('time');
ylabel('Amplitude');
title('Sinusoidal signal');
%RANDOM SIGNAL
n6=-10:1:20;
x6=rand(1,31);
subplot(2,3,6);
stem(n6,x6);
xlabel('time');
ylabel('Amplitude');
title('Random signal');
CONTINUOUS TIME:
9 UR11EC098
DISCRETE TIME :
OUTPUT WAVEFORM(CONTINUOUS
TIME):
10 UR11EC098
OUTPUT WAVEFORM (DISCRETE TIME):
11 UR11EC098
RESULT:
12 UR11EC098
The program to generate various
waveforms is written, executed and the output is
verified.
FLOWCHART:
13 UR11EC098
START
READ THE INPUT
SEQUENCE
PLOT THE WAVEFORMS
STOP
READ THE CONSANT FOR
(SCALAR) AMPLITUDE
AND TIME
MANIPULATION
READ THE (VECTOR)
SEQUENCE FOR SIGNAL
ADDTION AND
MULTIPLICATION
PERFORM OPERTAION ON THE D.T. SIGNAL
AIM:
Write a program in MATLAB to study the
basic operations on the Discrete – time signals.
(Operation on dependent variable (amplitude
manipulation) and Operation on independent
variable (time manipulation)).
APPARATUS REQUIRED:
Pentium 4 Processor, MATLAB software
THEORY:
Let x(n) be a sequence with finite length.
1. Amplitude manipulation
• Amplitude scaling:y[n] =ax[n], where a is a
constant.
If a > 1, then y[n] is
amplified sequence
If a < 1, then y[n] is
attenuated sequence
If a = - 1, then y[n] is
amplitude reversal
sequence
14 UR11EC098
Ex. No :2
Date :21-12-13
Ex. No :2
Date :21-12-13 BASIC OPERATIONS ON D.T SIGNALSBASIC OPERATIONS ON D.T SIGNALS
• Offset the signal: y[n] =a+x[n], where a is
a constant
• Two signals x1[n] and x2[n] can also be
added and multiplied: By adding the values
y1[n]= x1[n] + x2[n] at each corresponding
sample and by multiplying the values
y2[n]= x1[n] X x2[n] at each corresponding
sample.
2. Time manipulation
• Time scaling: y[n]=x[an],
where a is a constant.
• Time shifting: y[n]=x[n -
τ], where τ is a constant.
• Time reflection (folding):y[n]=x[-n]
Arithmetic Operations
* Matrix multiplication
.* Array multiplication (element-wise)
LIBRARY FUNCTIONS:
date Current date as date string.
S = date returns a string containing the date
in dd-mmm-yyyy format
tic & toc Start a stopwatch timer.
The sequence of commands
15 UR11EC098
TIC, operation, TOC
prints the number of seconds required for
the operation.
Fprintf
Write formatted data to file. The special
formats n,r,t,b,f can be used to produce
linefeed, carriage return, tab, backspace, and
formfeed characters respectively.
Use  to produce a backslash character and
%% to produce the percent character.
ALGORITHM/PROCEDURE:
1. Start the program
2. Get the input for signal manipulation
3. Use the appropriate library function
4. Display the waveform
Source code :
clc;
clear all;
close all;
%operations on the amplitude of signal
x=input('Enter input sequence:');
a=input('Enter amplification factor:');
b=input('Enter attenuation factor:');
c=input('Enter amplitude reversal factor:');
y1=a*x;
y2=b*x;
16 UR11EC098
y3=c*x;
n=length(x);
subplot(2,2,1);
stem(0:n-1,x);
xlabel('time');
ylabel('amplitude');
title('Input signal');
subplot(2,2,2);
stem(0:n-1,y1);
xlabel('time');
ylabel('Amplitude');
title('Amplified signal');
subplot(2,2,3);
stem(0:n-1,y2);
xlabel('time');
ylabel('Amplitude');
title('Attenuated signal');
subplot(2,2,4);
stem(0:n-1,y3);
xlabel('time');
ylabel('Amplitude');
title('Amplitude reversal signal');
%scalar addition
d=input('Input the scalar to be added:');
y4=d+x;
figure(2);
stem(0:n-1,y4);
xlabel('time');
ylabel('Amplitude');
title('Scalar addition signal');
clc;
clear all;
close all;
%Operations on the independent variable
%Time shifting of the independent variable
x=input('Enter the input sequence:');
n0=input('Enter the +ve shift:');
17 UR11EC098
n1=input('Enter the -ve shift:');
l=length(x);
subplot(2,2,1);
stem(0:l-1,x);
xlabel('time');
ylabel('Amplitude');
title('Input signal');
i=n0:l+n0-1;
j=n1:l+n1-1;
subplot(2,2,2);
stem(i,x);
xlabel('time');
ylabel('Amplitude');
title('Positive shifted signal');
subplot(2,2,3);
stem(j,x);
xlabel('time');
ylabel('Amnplitude');
title('Negative shifted signal');
%Time reversal
subplot(2,2,4);
stem(-1*(0:l-1),x);
xlabel('time');
ylabel('Amplitude');
title('Time reversal signal');
clc;
clear all;
close all;
%Arithmetic operations on signals
%Addition and multiplication of two signals
x1=input('Enter the sequence of first signal:');
x2=input('Enter the sequence of second signal:');
l1=length(x1);
l2=length(x2);
subplot(2,2,1);
18 UR11EC098
stem(0:l1-1,x1);
xlabel('time');
ylabel('Amplitude');
title('Input sequence 1');
subplot(2,2,2);
stem(0:l2-1,x2);
xlabel('time');
ylabel('Amplitude');
title('Input sequence 2');
if l1>l2
l3=l1-l2;
x2=[x2,zeros(1,l3)];
y1=x1+x2;
subplot(2,2,3);
stem(0:l1-1,y1);
xlabel('time');
ylabel('Amplitude');
title('Addition of two signals');
y2=x1.*x2;
subplot(2,2,4);
stem(0:l1-1,y2);
xlabel('time');
ylabel('Amplitude');
title('Multiplication of two signals');
end
if l2>l1
l3=l2-l1;
x1=[x1,zeros(1,l3)];
y1=x1+x2;
subplot(2,2,3);
stem(0:l2-1,y1);
xlabel('time');
ylabel('Amplitude');
title('Addition of two signals');
y2=x1.*x2;
subplot(2,2,4);
stem(0:l2-1,y2);
xlabel('time');
ylabel('Amplitude');
19 UR11EC098
title('Multiplication of two signals');
else
y1=x1+x2;
subplot(2,2,3);
stem(0:l1-1,y1);
xlabel('time');
ylabel('Amplitude');
title('Addition of two signals');
y2=x1.*x2;
subplot(2,2,4);
stem(0:l1-1,y2);
xlabel('time');
ylabel('Amplitude');
title('Multiplication of two signals');
end
operations on the amplitude of signal :
Time shifting of the independent variable :
20 UR11EC098
Addition and multiplication of two signals :
OUTPUT (operations on the amplitude of signal
):
21 UR11EC098
OUTPUT(Time shifting of the independent
variable) :
22 UR11EC098
OUTPUT(Addition and multiplication of two
signals) :
RESULT:
23 UR11EC098
The program to perform various operations
on discrete time signal is written, executed and the
output is verified
FLOWCHART:
24 UR11EC098
START
READ THE INPUT
SEQUENCE
PLOT THE WAVEFORMS
STOP
READ THE CONSANT FOR
(SCALAR) AMPLITUDE
AND TIME
MANIPULATION
READ THE (VECTOR)
SEQUENCE FOR SIGNAL
ADDTION AND
MULTIPLICATION
PERFORM OPERTAION ON THE D.T. SIGNAL using
the appropriate library function
AIM:
To check for linearity, Causality and
stability of various systems given bellow:
Linearity: System1 n.X(n), System2 An.X2
(n)+B
System3: Log (X),sin(x),5X(n) …etc
Causality: System1 U(-n) System2 X(n-
4)+U(n+5)
Stability: System1 Z / (Z2
+ 0.5 Z+1)
APPARATUS REQUIRED:
Pentium 4 Processor, MATLAB software
THEORY:
LINEARITY:
The response of the system to a weighted
sum of signals is equal to the corresponding
weighted sum of the responses (outputs) of the
system to each of the individual input signals.
)]([)]([)]()([ 22112211 nxTanxTanxanxaT +=+
METHODS OF PROOF:
Individual inputs are applied and the
weighted sum of the outputs is taken. Then the
25 UR11EC098
Ex. No : 3
Date: 06-1-14
Ex. No : 3
Date: 06-1-14
PROPERTIES OF DISCRETE TIME SYSTEMPROPERTIES OF DISCRETE TIME SYSTEM
weighted sum of signals input is applied to the
system and the two outputs are checked to see if
they are equal.
CAUSALITY:
A system is said to be causal, if the output of
the system at any time n(y(n)) depends only on the
present and past inputs and past outputs [x(n),x(n-
1)…….y(n-1),…..]
But does not depend on future inputs [x
(n+1),x(n+2),…..]
y(n) = F[ x(n),x(n-1),x(n-2)….] F[ ] –
Arbitrary function.
METHODS OF PROOF:
1. If the difference equation is given, the
arguments of the output y (n) are compared
with the arguments (time instant) of the
input signals. In the case of only present and
past inputs, the system is causal. If future
inputs are present then the system is non-
causal.
2. If the impulse response is given, then it is
checked whether all the values of h (n) for
negative values of n are zero. (i.e.) if h(n)=0,
for <0. If this is satisfied, then the system is
causal.
26 UR11EC098
STABILITY:
An arbitrary relaxed system is said to be
bounded input – bounded output (BIBO) stable, if
and only if every bounded input produces a
bounded output.
METHODS OF PROOF:
1. If the impulse response is given, then the
summation of responses for n ranging from
-α to +α is taken and if the sum is finite, the
system is said to be BIBO stable.
2. It the transfer function of the system is
given, the poles of the transfer function is
plotted. If all the poles lie within the unit
circle, the system is stable.
A single order pole on the boundary
of unit circle makes the systems marginally
stable. If there are multiple order poles on
the boundary of unit circle, the system is
unstable.If any pole is lying outside the unit
circle, the system is unstable.
LIBRARY FUNCTION:
.^ Array power.
Z = X.^Y denotes element-by-element
powers. X and Y must have the same
27 UR11EC098
dimensions unless one is a scalar. A scalar
can operate into anything.
C = POWER(A,B) is called for the syntax
'A .^ B' when A or B is an object.
residuez Z-transform partial-fraction
expansion.
[R,P,K] = residuez(B,A) finds the
residues, poles and direct terms of the
partial-fraction expansion of B(z)/A(z),
zplane Z-plane zero-pole plot.
zplane(Z,P) plots the zeros Z and poles P
(in column vectors) with the unit circle for
reference. Each zero is represented with a
'o' and each pole with a 'x' on the plot.
tf Creation of transfer functions or
conversion to transfer function.
SYS = tf(NUM,DEN,TS) creates a discrete-
time transfer function with sample time TS
(set TS=1 to get it in z). Z = tf('z',TS)
specifies H(z) = z with sample time TS.
syms Short-cut for constructing symbolic
objects.
28 UR11EC098
subs Symbolic substitution. subs(S,NEW)
replaces the free symbolic variable in S with
NEW.
ALGORITHM/PROCEDURE:
1. Click on the MATLAB icon on the desktop
(or go to start – all programs and click
on MATLAB) to get into the Command
Window
2. Type ‘edit’ in the MATLAB prompt ‘>>’
that appears in the Command window.
3. Write the program in the ‘Edit’ window and
save it in ‘M-file’
4. Run the program
5. Enter the input in the command window
6. The result is displayed in the Command
window and the graphical output is
displayed in the Figure Window
Source code :1
clc;
clear all;
close all;
%Properties of DT Systems(Linearity)
%y(n)=[x(n)]^2+B;
x1=input('Enter first input sequence:');
29 UR11EC098
n=length(x1);
x2=input('Enter second input sequence:');
a=input('Enter scaling constant(a):');
b=input('Enter scaling constant(b):');
B=input('Enter scaling constant(B):');
y1=power(x1,2)+B;
y2=power(x2,2)+B;
rhs=a*y1+b*y2;
x3=a*x1+b*x2;
lhs=power(x3,2)+B;
subplot(2,2,1);
stem(0:n-1,x1);
xlabel('Time');
ylabel('Amplitude');
title('First input sequence');
subplot(2,2,2);
stem(0:n-1,x2);
xlabel('Time');
ylabel('Amplitude');
title('Second input sequence');
subplot(2,2,3);
stem(0:n-1,lhs);
xlabel('Time');
ylabel('Amplitude');
title('LHS');
subplot(2,2,4);
stem(0:n-1,rhs);
xlabel('Time');
ylabel('Amplitude');
title('RHS');
if(lhs==rhs)
display('system is linear');
else
display('system is non-linear');
end;
30 UR11EC098
Source code :2
clc;
clear all;
close all;
%Properties of DT Systems(Linearity)
%y(n)=x(n);
x1=input('Enter first input sequence:');
x2=input('Enter second input sequence:');
a=input('Enter scaling constant(a):');
b=input('Enter scaling constant(b):');
subplot(2,2,1);
stem(x1);
xlabel('time');
ylabel('Amplitude');
title('First signal');
subplot(2,2,2);
stem(x2);
xlabel('time');
ylabel('Amplitude');
title('Second signal');
y1=x1;
y2=x2;
rhs=a*y1+b*y2;
x3=a*x1+b*x2;
lhs=x3;
if(lhs==rhs)
display('system is linear');
else
display('system is non-linear');
end;
subplot(2,2,3);
stem(lhs);
xlabel('time');
ylabel('Amplitude');
31 UR11EC098
title('L.H.S');
subplot(2,2,4);
stem(rhs);
xlabel('time');
ylabel('Amplitude');
title('R.H.S');
Source code :3
clc;
clear all;
close all;
%Properties of DT Systems(Time Invariance)
%y(n)=x(n);
x1=input('Enter input sequence x1:');
n0=input('Enter shift:');
x2=[zeros(1,n0),x1];
y1=x1;
y2=x2;
y3=[zeros(1,n0),y1];
if(y2==y3)
display('system is time invariant');
else
display('system is time variant');
end;
subplot(2,2,1);
stem(x1);
xlabel('time');
ylabel('Amplitude');
title('Input signal');
subplot(2,2,2);
stem(x2);
xlabel('time');
ylabel('Amplitude');
title('Signal after shift');
subplot(2,2,3);
stem(y2);
32 UR11EC098
xlabel('time');
ylabel('Amplitude');
title('L.H.S');
subplot(2,2,4);
stem(y3);
xlabel('time');
ylabel('Amplitude');
title('R.H.S');
Source code :4
clc;
clear all;
close all;
%Properties of DT Systems(Time Invariance)
%y(n)=n*[x(n)];
x1=input('Enter input sequence x1:');
n1=length(x1);
for n=1:n1
y1(n1)=n.*x1(n);
end;
n0=input('Enter shift:');
x2=[zeros(1,n0),x1];
for n2=1:n1+n0
y2(n2)=n2.*x2(n2);
end;
y3=[zeros(1,n0),y1];
if(y2==y3)
display('system is time invariant');
else
display('system is time variant');
end;
subplot(2,2,1);
stem(x1);
xlabel('time');
ylabel('Amplitude');
33 UR11EC098
title('Input signal');
subplot(2,2,2);
stem(x2);
xlabel('time');
ylabel('Amplitude');
title('Signal after shift');
subplot(2,2,3);
stem(y2);
xlabel('time');
ylabel('Amplitude');
title('L.H.S');
subplot(2,2,4);
stem(y3);
xlabel('time');
ylabel('Amplitude');
title('R.H.S');
Source code :5
clc;
clear all;
close all;
%Properties of DT Systems(Causality)
%y(n)=x(-n);
x1=input('Enter input sequence x1:');
n1=input('Enter lower limit n1:');
n2=input('Enter lower limit n2:');
flag=0;
for n=n1:n2
arg=-n;
if arg>n;
flag=1;
end;
end;
if(flag==1)
display('system is causal');
else
34 UR11EC098
display('system is non-causal');
end;
Source code :6
disp('stability');
nr=input('input the numerator coefficients:');
dr=input('input the denominator coefficients:');
z=tf(nr,dr,1);
[r,p,k]=residuez(nr,dr);
figure
zplane(nr,dr);
if abs(p)<1
disp('the system is stable');
else
disp('the system is unstable');
end;
Non-Linear System :1
Output :
35 UR11EC098
Linear System :2
Output :
36 UR11EC098
Time invariant system :3
Output :
37 UR11EC098
Time variant system : 4
Output :
38 UR11EC098
Non-Causal system :5
Unstable system :6
39 UR11EC098
Output :
40 UR11EC098
RESULT:
The properties of Discrete – Time system is
verified using MATLAB
FLOWCHART:
41 UR11EC098
42 UR11EC098
START
ENTER THE SIGNAL
PARAMETERS (AMPLITUDE,
TIME AND FREQUENCY)
FIND THE SPectrum of
all the signals
PLOT THE WAVEFORMS
STOP
PERFORM THE SAMPLING RATE CONVERSION
ON THE INPUT BY using upsample,
DOWNSAMPLE and resample
PERFORM interpolation and decimation ON THE
INPUT
AIM:
Write a MATLAB Script to perform
sampling rate conversion for any given arbitrary
sequence (D.T) or signal (C.T) by interpolation,
decimation, upsampling, downsampling and
resampling (i.e. fractional value)
.
APPARATUS REQUIRED:
PC, MATLAB software
THEORY:
SAMPLING PROCESS:
It is a process by which a continuous time
signal is converted into discrete time signal. X[n]
is the discrete time signal obtained by taking
samples of the analog signal x(t) every T seconds,
where T is the sampling period.
X[n] = x (t) x p (t)
Where p(t) is impulse train; T – period
of the train
SAMPLING THEOREM:
It states that the band limited signal x(t)
having no frequency components above Fmax Hz is
specified by the samples that are taken at a
uniform rate greater than 2 Fmax Hz (Nyquist rate),
43 UR11EC098
Ex. No : 4
Date: 13-1-14
Ex. No : 4
Date: 13-1-14 SAMPLING RATE CONVERSIONSAMPLING RATE CONVERSION
or the frequency equal to twice the highest
frequency of x(t).
Fs ≥ 2 Fmax
SAMPLING RATE CONVERSION:
Sampling rate conversion is employed to
generate a new sequence with a sampling rate
higher or lower than that of a given sequence. If
x[n] is a sequence with a sampling rate of F Hz
and it is used to generate another sequence y[n]
with desired sampling rate F’ Hz, then the
sampling rate alteration is given by,
F’/F = R
If R > 1, the process is called interpolation
and results in a sequence with higher sampling
rate. If R< 1, the process is called decimation and
results in a sequence with lower sampling rate.
DOWNSAMPLE AND DECIMATION:
Down sampling operation by an integer
factor M (M>1) on a sequence x[n] consists of
keeping every Mth
sample of x[n] and removing M-
1 in between samples, generating an output
sequence y[n] according to the relation
y [n] = x[nM]
y [n] – sampling rate is 1/M that of x[n]
If we reduce the sampling rate, the resulting signal
will be an aliased version of x[n]. To avoid
44 UR11EC098
aliasing, the bandwidth of x[n] must be reduced to
Fmax =Fx/2 π or ωmax = π /M. The input sequence is
passed through LPF or an antialiasing filter before
down sampling.
x [n] -
y[n]
UPSAMPLE AND INTERPOLATION:
Upsampling by an integer factor L (L > 1)
on a sequence x[n] will insert (L–1) equidistant
samples between an output sequence y[n]
according to the relation
x[n/L], n = 0, ±1, ±2 ….
y[n] = 0, otherwise
The sampling rate of y[n] is L times that of x[n].
The unwanted images in the spectra of sampled
signal must be removed by a LPF called anti-
imaging filter. The input sequence is passed
through an anti-imaging filter after up sampling.
x[n]
y[n]
SAMPLING RATE CONVERSION BY A
RATIONAL FACTOR I/O:
45 UR11EC098
ANTIALIASING
FILTER H (Z)
↓M
↑L
ANTI IMAGING
FILTER H (Z)
We achieve this conversion, by first
performing interpolation by the factor I and then
decimating the output of interpolator by the factor
D, interpolation has to be performed before
decimation to obtain the new rational sampling
rate.
x[n]
y[n]
LIBRARY FUNCTIONS:
• resample: Changes sampling rate by
any rational factor.
y = resample (x,p,q) resamples the sequence in
vector x at p/q times the original sampling rate,
using a polyphase filter implementation. p and q
must be positive integers. The length of y is equal
to ceil (length(x)*p/q).
• interp: Increases sampling rate by
an integer factor (interpolation)
y = interp (x,r) increases the sampling rate of x by
a factor of r. The interpolated vector y is r times
longer than the original input x. ‘interp’ performs
low pass interpolation by inserting zeros into the
original sequence and then applying a special low
pass filter.
46 UR11EC098
UPSAMPLER ↑
ANTI
IMAGING
FILTER
ANTI
ALIASING
FILTER
DOWN
SAMPLER ↓
• upsample: Increases the sampling
rate of the input signal
y = upsample(x,n) increases the sampling rate of x
by inserting n-1 zeros between samples. The
upsampled y has length(x)*n samples
• decimate: Decreases the sampling
rate for a sequence (decimation).
y = decimate (x, r) reduces the sample rate of x by
a factor r. The decimated vector y is r times shorter
in length than the input vector x. By default,
decimate employs an eighth-order low pass
Chebyshev Type I filter. It filters the input
sequence in both the forward and reverse
directions to remove all phase distortion,
effectively doubling the filter order.
• downsample: Decreases the sampling
rate of the input signal
y = downsample(x,n) decreases the sampling rate
of x by keeping every nth
sample starting with the
first sample. The downsampled y has length(x)/n
samples
ALGORITHM/PROCEDURE:
1. Generate a sinusoidal waveform
47 UR11EC098
2. Using the appropriate library function for
interpolation ,decimation ,upsampling ,
downsampling and resampling, perform
sampling rate conversion for the sinusoidal
waveform
3. Find the spectrum of all the signals and
compare them in frequency domain.
4. Display the resultant waveforms
Source code :
clc;
clear all;
close all;
%continuous sinusoidal signal
a=input('Enter the amplitude:');
f=input('Enter the Timeperiod:');
t=-10:1:20;
x=a*sin(2*pi*f*t);
subplot(2,3,1);
plot(t,x);
xlabel('time');
ylabel('Amplitude');
title('Sinusoidal signal');
%decimating the signal
d=input('Enter the value by which the signal is to
be decimated:');
y1=decimate(x,d);
subplot(2,3,2);
stem(y1);
xlabel('time');
48 UR11EC098
ylabel('Amplitude');
title('Decimated signal');
%interpolating the signal
i=input('Enter the value by which the signal is to
be interpolated:');
y2=interp(x,i);
subplot(2,3,3);
stem(y2);
xlabel('time');
ylabel('Amplitude');
title('Interpolated signal');
%resampling the signal
y3=resample(x,3,2);
subplot(2,3,4);
stem(y3);
xlabel('time');
ylabel('Amplitude');
title('Resampled signal');
%downsampling the signal
y4=downsample(x,2);
subplot(2,3,5);
stem(y4);
xlabel('time');
ylabel('Amplitude');
title('Downsampled signal');
%upsampling the signal
y5=upsample(x,3);
subplot(2,3,6);
stem(y5);
xlabel('time');
ylabel('Amplitude');
title('Upsampled signal');
49 UR11EC098
Output :
50 UR11EC098
51 UR11EC098
RESULT:
The program written using library functions
and the sampling rate conversion process is
studied.
52 UR11EC098
FLOWCHART:
53 UR11EC098
START
ENTER THE INPUT
SEQUENCE x[n] & SYSTEM
RESPONSE h[n]
PERFORM LINEAR AND CIRCULAR
CONVOLUTION IN TIME DOMAIN
PLOT THE WAVEFORMS AND ERROR
STOP
AIM:
Write a MATLAB Script to perform discrete
convolution (Linear and Circular) for the given
two sequences and also prove by manual
calculation.
APPARATUS REQUIRED:
PC, MATLAB software
THEORY:
LINEAR CONVOLUTION:
The response y[n] of a LTI system for any
arbitrary input x[n] is given by convolution of
impulse response h[n] of the system and the
arbitrary input x[n].
y[n] = x[n]*h[n] =
∑
∞
−∞=
−
k
knhkx ][][
or
∑
∞
−∞=
−
k
knxkh ][][
If the input x[n] has N1 samples and impulse
response h[n] has N2 samples then the output
sequence y[n] will be a finite duration sequence
consisting of (N1 + N2 - 1) samples. The
54 UR11EC098
Ex. No : 5
Date : 20-1-14
Ex. No : 5
Date : 20-1-14 DISCRETE CONVOLUTIONDISCRETE CONVOLUTION
convolution results in a non periodic sequence
called Aperiodic convolution.
STEPS IN LINEAR CONVOLUTION:
The process of computing convolution between
x[k] and h[k] involves four steps.
1. Folding: Fold h[k] about k=0 to obtain
h[-k]
2. Shifting: Shift h[-k] by ‘n0’to right if ‘n0’
is positive and shift h[-k] by ‘n0’ to the
left if ‘n0’ is negative. Obtain h[n0-k]
3. Multiplication : Multiply x[k] by h[n0-k]
to obtain the product sequence
yn0 [k] = x[k] h [n0 –k]
4. Summation: Find the sum of all the
values of the product sequence to obtain
values of output at n = n0
Repeat steps 2 to 4 for all possible time
shifts ‘n0’ in the range - ∞ <n< ∞
CIRCULAR CONVOLUTION
The convolution of two periodic sequences
with period N is called circular convolution of two
signals x1[n] and x2[n] denoted by
y[n] = x1[n] * x2[n] = ∑
−
=
1
0
1x
N
k
[(n-k) mod N]
x2 (k) or ∑
−
=
1
0
1 )(x
N
k
k x2 [(n-k) mod N]
55 UR11EC098
where x1[(n-k) mod N] is the reflected and
circularly translated version of x1[n].
x1[n] * x2[n] = IDFTN { DFTN (x1[n] ) .
DFTN (x2[n])}
It can be performed only if both the
sequences consist of equal number of samples. If
the sequences are different in length then convert
the smaller size sequence to that of larger size by
appending zeros
METHODS FOR CIRCULAR CONVOLUTION:
Matrix Multiplication Method and Concentric
Circle Method
LIBRARY FUNCTION:
• conv: Convolution and polynomial
multiplication.
C = conv (A, B) convolves vectors A and B.
The resulting vector C’s length is given by
length(A)+length(B)-1. If Aand B are
vectors of polynomial coefficients,
convolving them is equivalent to
multiplying the two polynomials in
frequency domain.
• length: Length of vector.
56 UR11EC098
length(X) returns the length of vector X. It
is equivalent to size(X) for non empty arrays and 0
for empty ones.
• fft: Discrete Fourier transform.
fft(x) is the Discrete Fourier transform
(DFT) of vector x. For matrices, the ‘fft’
operation is applied to each column. For N-
D arrays, the ‘fft’ operation operates on the
first non-single dimension. fft(x,N) is the N-
point FFT, padded with zeros if x has less
than N points and truncated if it has more.
• ifft: Inverse Discrete Fourier
transform.
ifft(X) is the Inverse Discrete Fourier
transform of X.
ifft(X,N) is the N-point Inverse Discrete
Fourier transform of X.
ALGORITHM/PROCEDURE:
LINEAR CONVOLUTION:
1. Enter the sequences (Input x[n] and the
Impulse response h[n])
2. Perform the linear convolution between x[k]
and h[k] and obtain y[n].
3. Find the FFT of x[n] & h[n].Obtain X and H
57 UR11EC098
4. Multiply X and H to obtain Y
5. Find the IFFT of Y to obtain y’[n]
6. Compute error in time domain e=y[n]-y’[n]
7. Plot the Results
CIRCULAR CONVOLUTION
1. Enter the sequences (input x[n] and the
impulse response h[n])
2. Make the length of the sequences equal by
padding zeros to the smaller length
sequence.
3. Perform the circular convolution between
x[k] and h[k]and obtain y[n].
4. Find the FFT of x[n] & h[n].Obtain X and H
5. Multiply X and H to obtain Y
6. Find the IFFT of Y to obtain y’[n]
7. Compute error in time domain e=y[n]-y’[n]
8. Plot the Results
SOURCE CODE : 1
clc;
clear all;
close all;
%Program to perform Linear Convolution
x1=input('Enter the first sequence to be
convoluted:');
subplot(3,1,1);
stem(x1);
xlabel('Time');
ylabel('Amplitude');
58 UR11EC098
title('First sequence');
x2=input('Enter the second sequence to be
convoluted:');
subplot(3,1,2);
stem(x2);
xlabel('Time');
ylabel('Amplitude');
title('Second sequence');
f=conv(x1,x2);
disp('The Linear convoluted sequence is');
disp(f);
subplot(3,1,3);
stem(f);
xlabel('Time');
ylabel('Amplitude');
title('Linear Convoluted sequence');
Command window :
OUTPUT :
59 UR11EC098
SOURCE CODE :2
clc;
clear all;
close all;
%Program to perform Circular Convolution
x1=input('Enter the first sequence to be
convoluted:');
subplot(3,1,1);
l1=length(x1);
stem(x1);
xlabel('Time');
ylabel('Amplitude');
title('First sequence');
x2=input('Enter the second sequence to be
convoluted:');
subplot(3,1,2);
l2=length(x2);
stem(x2);
60 UR11EC098
xlabel('Time');
ylabel('Amplitude');
title('Second sequence');
if l1>l2
l3=l1-l2;
x2=[x2,zeros(1,l3)];
elseif l2>l1
l3=l2-l1;
x1=[x1,zeros(1,l3)];
end
f=cconv(x1,x2);
disp('The Circular convoluted sequence is');
disp(f);
subplot(3,1,3);
stem(f);
xlabel('Time');
ylabel('Amplitude');
title('Circular Convoluted sequence');
Command window :
OUTPUT :
61 UR11EC098
SOURCE CODE :3
clc;
clear all;
close all;
%Program to perform Linear Convolution using
Circular Convolution
x1=input('Enter the first sequence to be
convoluted:');
subplot(3,1,1);
l1=length(x1);
stem(x1);
xlabel('Time');
ylabel('Amplitude');
title('First sequence');
62 UR11EC098
x2=input('Enter the second sequence to be
convoluted:');
subplot(3,1,2);
l2=length(x2);
stem(x2);
xlabel('Time');
ylabel('Amplitude');
title('Second sequence');
if l1>l2
l3=l1-l2;
x2=[x2,zeros(1,l3)];
elseif l2>l1
l3=l2-l1;
x1=[x1,zeros(1,l3)];
end
n=l1+l2-1;
f=cconv(x1,x2,n);
disp('The convoluted sequence is');
disp(f);
subplot(3,1,3);
stem(f);
xlabel('Time');
ylabel('Amplitude');
title('Convoluted sequence');
Command window :
63 UR11EC098
OUTPUT:
SOURCE CODE :4
64 UR11EC098
clc;
clear all;
close all;
%Program to perform Linear Convolution
x=input('Enter the first input sequence:');
l1=length(x);
subplot(3,2,1);
stem(x);
xlabel('Time index n---->');
ylabel('Amplitude');
title('input sequence');
h=input('Enter the system response sequence:');
l2=length(h);
subplot(3,2,2);
stem(h);
xlabel('Time index n---->');
ylabel('Amplitude');
title('system response sequence');
if l1>l2
l3=l1-l2;
h=[h,zeros(1,l3)];
elseif l2>l1
l3=l2-l1;
x=[x,zeros(1,l3)];
end
y=conv(x,h);
disp('The time domain convoluted sequence is:');
disp(y);
subplot(3,2,3);
stem(y);
xlabel('Time index n---->');
ylabel('Amplitude');
title('convoluted output sequence');
65 UR11EC098
X=fft(x,length(y));
H=fft(h,length(y));
Y=X.*H;
disp('The frequency domain multiplied sequence
is:');
disp(Y);
subplot(3,2,4);
stem(Y);
xlabel('Time index n---->');
ylabel('Amplitude');
title('frequency domain multiplied response');
y1=ifft(Y,length(Y));
disp('The inverse fourier transformed sequence
is:');
disp(y1);
subplot(3,2,5);
stem(y1);
xlabel('Time index n---->');
ylabel('Amplitude');
title('output after inverse fourier transform');
e=y-y1;
disp('The Error sequence:')
disp(abs(e));
subplot(3,2,6);
stem(abs(e));
xlabel('Time index n---->');
ylabel('Amplitude');
title('error sequence');
66 UR11EC098
Command window :
OUTPUT :
67 UR11EC098
SOURCE CODE :5
clc;
clear all;
close all;
%PROGRAM FOR CIRCULAR
CONVOLUTION USING DISCRETE
CONVOLUTION EXPRESSION
x=input('Enter the first sequence:');
n1=length(x);
h=input('Enter the second sequence:');
n2=length(h);
n=0:1:n1-1;
subplot(3,1,1);
stem(n,x);
xlabel('Time');
ylabel('Amplitude');
title('First sequence Response x(n)');
n=0:1:n2-1;
subplot(3,1,2);
stem(n,h);
68 UR11EC098
xlabel('Time');
ylabel('Amplitude');
title('Second sequence Response h(n)');
n=n1+n2-1;
if n1>n2
n3=n1-n2;
h=[h,zeros(1,n3)];
elseif n2>n1
n3=n2-n1;
x=[x,zeros(1,n3)];
end
x=[x,zeros(1,n-n1)];
h=[h,zeros(1,n-n2)];
for n=1:n
y(n)=0;
for i=1:n
j=n-i+1;
if(j<=0)
j=n+j;
end
y(n)=y(n)+x(i)*h(j);
end
end
disp('Circular Convolution of x&h is');
disp(y);
subplot(3,1,3);
stem(y);
xlabel('Time');
ylabel('Amplitude');
title('Circular Convoluted sequence Response');
Command window :
69 UR11EC098
OUTPUT :
70 UR11EC098
RESULT:
The linear and circular convolutions are
performed by using MATLAB script and the
program results are verified by manual calculation.
FLOWCHART:
71 UR11EC098
72 UR11EC098
START
ENTER THE INPUT
SEQUENCE
PERFORM THE DFT USING IN-builT FFT AND
USING DIRECT FORMULA ON THE GIVEN
INPUT SEQUENCE
PLOT THE WAVEFORMS AND
ERROR
STOP
AIM:
Write a MATLAB program to perform the
Discrete Fourier Transform for the given
sequences.
.
APPARATUS REQUIRED:
PC, MATLAB software
THEORY:
DISCRETE FOURIER TRANSFORM
Fourier analysis is extremely useful for data
analysis, as it breaks down a signal into constituent
sinusoids of different frequencies. For sampled
vector data Fourier analysis is performed using the
Discrete Fourier Transform (DFT).
The Discrete Fourier transform computes
the values of the Z-transform for evenly spaced
points around the circle for a given sequence.
If the sequence to be represented is of finite
duration i.e. it has only a finite number of non-zero
values, the transform used is Discrete Fourier
transform.
73 UR11EC098
Ex. No : 6
Date : 27-1-14
Ex. No : 6
Date : 27-1-14 DISCRETE FOURIER TRANSFORMDISCRETE FOURIER TRANSFORM
It finds its application in Digital Signal
processing including Linear filtering, Correlation
analysis and Spectrum analysis.
Consider a complex series x [n] with N samples of
the form Where x is a
complex number Further,
assume that the series outside the range 0, N-1 is
extended N-periodic, that is, xk = xk+N for all k. The
FT of this series is denoted as X (k) and has N
samples. The forward transform is defined as
∑
−
=
−
−==
1
0
2
1...0,)(
1
X(k)
N
n
Nknj
Nkfornx
N e
π
The inverse transform is defined as
Although the functions here are described as
complex series, setting the imaginary part to 0 can
represent real valued series. In general, the
transform into the frequency domain will be a
complex valued function, that is, with magnitude
and phase.
74 UR11EC098
LIBRARY FUNCTIONS:
• exp: Exponential Function.
exp (X) is the exponential of the elements of
X, e to the power X. For complex Z=X+i*Y,
exp (Z) = exp(X)*(COS(Y) +i*SIN(Y)).
• disp: Display array.
disp (X) is called for the object X when the
semicolon is not used to terminate a
statement.
• max: Maximum elements of an array
C = max (A, B) returns an array of the same
size as A and B with the largest elements
taken from A or B.
• fft: Discrete Fourier transform.
fft(x) is the discrete Fourier transform (DFT)
of vector x. For the matrices, the FFT
operation is applied to each column. For N-
Dimensional arrays, the FFT operation
operates on the first non-singleton
dimension.
ALGORITHM/PROCEDURE:
1. Click on the MATLAB icon on the desktop
(or go to Start - All Programs and click on
MATLAB) to get into the Command
Window
75 UR11EC098
2. Type ‘edit’ in the MATLAB prompt ‘>>’
that appears in the Command window.
3. Write the program in the ‘Edit’ window and
save it as ‘m-file’
4. Run the program
5. Enter the input in the command window
6. The result is displayed in the Command
window and the graphical output is
displayed in the Figure Window
Source Code :
clc;
clear all;
close all;
%Get the sequence from user
disp('The sequence from the user:');
xn=input('Enter the input sequence x(n):');
% To find the length of the sequence
N=length(xn);
%To initilise an array of same size as that of input
sequence
Xk=zeros(1,N);
iXk=zeros(1,N);
%code block to find the DFT of the sequence
for k=0:N-1
for n=0:N-1
Xk(k+1)=Xk(k+1)+(xn(n+1)*exp((-
i)*2*pi*k*n/N));
end
end
76 UR11EC098
%code block to plot the input sequence
t=0:N-1;
subplot(3,2,1);
stem(t,xn);
ylabel ('Amplitude');
xlabel ('Time Index');
title ('Input Sequence');
%code block to plot the X(k)
disp('The discrete fourier transform of x(n):');
disp(Xk);
t=0:N-1;
subplot(3,2,2);
stem(t,Xk);
ylabel ('Amplitude');
xlabel ('Time Index');
title ('X(k)');
% To find the magnitudes of individual DFT
points
magnitude=abs(Xk);
%code block to plot the magnitude response
disp('The magnitude response of X(k):');
disp(magnitude);
t=0:N-1;
subplot(3,2,3);
stem(t,magnitude);
ylabel ('Amplitude');
xlabel ('K');
title ('Magnitude Response');
%To find the phases of individual DFT points
phase=angle(Xk);
%code block to plot the phase response
disp('The phase response of X(k):');
disp(phase);
77 UR11EC098
t=0:N-1;
subplot(3,2,4);
stem(t,phase);
ylabel ('Phase');
xlabel ('K');
title ('Phase Response');
% Code block to find the IDFT of the sequence
for n=0:N-1
for k=0:N-1
iXk(n+1)=iXk(n+1)+
(Xk(k+1)*exp(i*2*pi*k*n/N));
end
end
iXk=iXk./N;
%code block to plot the output sequence
t=0:N-1;
subplot(3,2,5);
stem(t,xn);
ylabel ('Amplitude');
xlabel ('Time Index');
title ('IDFT sequence');
%code block to plot the FFT of input sequence
using inbuilt function
x2=fft(xn);
subplot(3,2,6);
stem(t,x2);
ylabel ('Amplitude');
xlabel ('Time Index');
title ('FFT of input sequence');
Command Window :
78 UR11EC098
OUTPUT :
79 UR11EC098
RESULT:
The program for DFT calculation was
performed with library functions and without
library functions. The results were verified by
manual calculation.
80 UR11EC098
FLOWCHART:
81 UR11EC098
START
ENTER THE INPUT
SEQUENCE IN TIME
DOMAIN OR FREQUENCY
DOMAIN
PERFORM DIT/DIF-FFT FOR TIME SAMPLES
or PERFORM IDIT/IDIT-FFT FOR FREQuency
SAMPLES
PLOT THE WAVEFORMS
STOP
AIM:
Write a MATLAB Script to compute
Discrete Fourier Transform and Inverse Discrete
Fourier Transform of the given sequence using
FFT algorithms (DIT-FFT & DIF-FFT)
.
APPARATUS REQUIRED:
PC, MATLAB software
THEORY:
DFT is a powerful tool for performing
frequency analysis of discrete time signal and it is
described as a frequency domain representation of
a DT sequence.
The DFT of a finite duration sequence x[n]
is given by
X (k) = ∑
−
=
−
1
0
2
N
n
πnk/Nj
x(n)e k=0,
1….N-1
which may conveniently be written in the
form
X (k) = ∑
−
=
1
0
)(
N
n
nk
Nwnx k=0,
1….N-1
82 UR11EC098
Ex. No :7
Date :3-2-14
Ex. No :7
Date :3-2-14
FAST FOURIER TRANSFORM ALGORITHMSFAST FOURIER TRANSFORM ALGORITHMS
where WN=e-j2π/N
which is known as
Twiddle or Phase factor.
COMPUTATION OF DFT:
To compute DFT, it requires N2
multiplication and (N-1) N complex addition.
Direct computation of DFT is basically inefficient
precisely because it does not exploit the symmetry
and periodicity properties of phase factor WN.
FAST FOURIER TRANSFORM (FFT):
FFT is a method of having
computationally efficient algorithms for the
execution of DFT, under the approach of Divide
and Conquer. The number of computations can be
reduced in N point DFT for complex
multiplications to N/2log2N and for complex
addition to N/2log2N.
Types of FFT are,
(i) Decimation In Time (DIT)
(ii)Decimation In Frequency (DIF)
IDFT USING FFT ALGORITHMS:
The inverse DFT of an N point
sequence X (k), where k=0,1,2…N-1 is defined
as ,
x [n] = ∑
−
=
−
1
0
)(X
1 N
n
nk
NWk
N
83 UR11EC098
where, wN=e-j2π/N
.
Taking conjugate and multiplying by N, we get,
N x*[n] =
nk
N
N
k
Wk)(X
1
0
*
∑
−
=
The right hand side of the equation is the DFT
of the sequence X*(k). Now x[n] can be found
by taking the complex conjugate of the DFT
and dividing by N to give,
x [n]=
*
1
0
*
])(X[
1 nk
N
N
k
Wk
N
∑
−
=
RADIX-2 DECIMATION IN TIME FFT:
The idea is to successively split the N-
point time domain sequence into smaller sub
sequence. Initially the N-point sequence is split
into xe[n] and xo[n], which have the even and
odd indexed samples of x[n] respectively. The
N/2 point DFT’s of these two sequences are
evaluated and combined to give N-point DFT.
Similarly N/2 point sequences are represented
as a combination of two N/4 point DFT’s. This
process is continued, until we are left with 2
point DFT.
RADIX-2 DECIMATION IN FREQUENCY
FFT:
The output sequence X(k) is divided
into smaller sequence.. Initially x[n] is divided
84 UR11EC098
into two sequences x1[n], x2[n] consisting of the
first and second N/2 samples of x[n]
respectively. Then we find the N/2 point
sequences f[n] and g[n] as
f[n]= x1[n]+x2[n],
g[n]=( x1[n]-x2[n] )wN
k
The N/2 point DFT of the 2 sequences gives even
and odd numbered output samples. The above
procedure can be used to express each N/2 point
DFT as a combination of two N/4 point DFTs.
This process is continued until we are left with 2
point DFT.
LIBRARY FUNCTION:
• fft: Discrete Fourier transform.
fft(x) is the discrete Fourier transform (DFT) of
vector x. For matrices, the FFT operation is
applied to each column. For N-Dimensional
arrays, the FFT operation operates on the first
non-singleton dimension.
• ditfft: Decimation in time
(DIT)fft
ditfft(x) is the discrete Fourier transform (DFT)
of vector x in time domain decimation
85 UR11EC098
• diffft: Decimation in frequency
(DIF)fft
diffft(x) is the discrete Fourier transform (DFT)
of vector x in Frequency domain decimation
ALGORITHM/PROCEDURE:
1. Input the given sequence x[n]
2. Compute the Discrete Fourier Transform
using FFT library function (ditfft or diffft)
and obtain X[k]
3. Compute the Inverse Discrete Fourier
Transform using FFT library function (ditfft
or diffft) and obtain X[n] by following steps
a. Take conjugate of X [k] and obtain
X[k]*
b. Compute the Discrete Fourier
Transform using FFT library function
(ditfft or diffft) for X[k]* and obtain
N.x[n]*
c. Once again take conjugate for
N.x[n]* and divide by N to obtain
x[n]
4. Display the results.
SOURCE CODE:(DITFFT)
clc;
clear all;
close all;
86 UR11EC098
N=input('Enter the number of elements:');
for i=1:N
re(i)= input('Enter the real part of the element:');
im(i)= input('Enter the imaginary part of the
element:');
end
%% Call Dit_fft function
[re1,im1]= ditfft(re,im,N);
disp(re1);
disp(im1);
figure(1);
subplot(2,2,1);
stem(re1);
xlabel('Time period');
ylabel('Amplitude');
title('Real part of the output');
subplot(2,2,2);
stem(im1);
xlabel('Time period');
ylabel('Amplitude');
title('Imaginary part of the output');
%%dit_ifft
N=input('Enter the number of elements:');
for i=1:N
re(i)= input('Enter the real part of the element:');
im(i)= input('Enter the imaginary part of the
element:');
end
for i=1:N
re(i)=re(i);
im(i)=-im(i);
end
%% call dit_ifft function
[re1,im1]=ditifft(re,im,N);
87 UR11EC098
for i=1:N
re1(i)=re1(i)/N;
im1(i)=-im1(i)/N;
end
disp(re1);
disp(im1);
%figure(2)
subplot(2,2,3);
stem(re1);
xlabel('Time period');
ylabel('Amplitude');
title('Real part of the output');
subplot(2,2,4);
stem(im1);
xlabel('Time period');
ylabel('Amplitude');
title('Imaginary part of the output');
Function Table:(DITFFT)
function [ re, im ] = ditfft( re, im, N)
%UNTITLED5 Summary of this function goes
here
% Detailed explanation goes here
N1=N-1;
N2=N/2;
j=N2+1;
M=log2(N);
% Bit reversal sorting
for i=2:N-2
if i<j
tr=re(j);
ti=im(j);
re(j)=re(i);
im(j)=im(i);
re(i)=tr;
88 UR11EC098
im(i)=ti;
end
k=N2;
while k<=j
j=j-k;
k=k/2;
end
j=j+k;
j=round(j);
end
for l=1:M
le=2.^l;
le2=le/2;
ur=1;
ui=0;
sr=cos(pi/le2);
si=sin(pi/le2);
for j=2:(le2+1)
jm=j-1;
for i=jm:le:N
ip=i+le2;
tr=re(ip)*ur-im(ip)*ui;
ti=re(ip)*ui-im(ip)*ur;
re(ip)=re(i)-tr;
im(ip)=im(i)-ti;
re(i)=re(i)+tr;
im(i)=im(i)+ti;
end
tr=ur;
ur=tr*sr-ui*si;
ui=tr*si+ui*sr;
end
end
Function Table:(DITIFFT)
function [ re,im] = ditifft(re,im,N)
%UNTITLED2 Summary of this function goes
here
89 UR11EC098
% Detailed explanation goes here
N1=N-1;
N2=N/2;
j=N2+1;
M=log2(N);
%Bit reversal sorting
for i=2:N-2
if i<j
tr=re(j);
ti=im(j);
re(j)=re(i);
im(j)=im(i);
re(i)=tr;
im(i)=ti;
end
k=N2;
while k<=j
j=j-k;
k=k/2;
end
j=j+k;
j=round(j);
end
for l=1:M
le=2.^l;
le2=le/2;
ur=1;
ui=0;
sr=cos(pi/le2);
si=-sin(pi/le2);
for j=2:(le2+1)
jm=j-1;
for i=jm:le:N
ip=i+le2;
tr=re(ip)*ur-im(ip)*ui;
ti=re(ip)*ui+im(ip)*ur;
re(ip)=re(i)-tr;
90 UR11EC098
im(ip)=im(i)-ti;
re(i)=re(i)+tr;
im(i)=im(i)+ti;
end
tr=ur;
ur=tr*sr-ui*si;
ui=tr*si+ui*sr;
end
end
end
Command Window:
Output:
91 UR11EC098
Source code :(DIFFFT)
%% DIF_FFT
clc;
clear all;
close all;
%%
N=input('Enter the number of points in DIF
DFT:');
for i=1:N
re(i)=input('Enter the real part of the element:');
im(i)=input('Enter the imaginary part of the
element:');
end
%%
% Call DIf_FFT Function
[re1, im1]=diffft(re,im,N);
display(re1);
display(im1);
figure(1);
subplot(2,2,1);
92 UR11EC098
stem(re1);
xlabel('Time');
ylabel('Amplitude');
title('Real part of the output');
subplot(2,2,2);
stem(im1);
xlabel('Time');
ylabel('Amplitude');
title('Imaginary part of the output');
%% DIF IFFT
N=input('Enter the number of points in DIF
IFFT:');
for i=1:N
re(i)=input('Enter the real part of the element:');
im(i)=input('Enter the imaginary part of the
element:');
end
for i=1:N
re(i)=re(i);
im(i)=-im(i);
end
%% Call dif_ifft function
[re1, im1]=ditifft(re,im,N);
for i=1:N
re1(i)=re1(i)/N;
im1(i)=-im1(i)/N;
end
display(re1)
display(im1);
% figure(2);
subplot(2,2,3);
stem(re1);
xlabel('Time');
ylabel('Amplitude');
title('Real part of the output');
subplot(2,2,4);
93 UR11EC098
stem(im1);
xlabel('Time');
ylabel('Amplitude');
title('Imaginary part of the output');
Function Table:(DIFFFT)
function [re, im ] = diffft(re, im, N)
%UNTITLED5 Summary of this function goes
here
% Detailed explanation goes here
N1=N-1;
N2=N/2;
M=log2(N);
%%
%
for l=M:-1:1;
le=2.^l;
le2=le/2;
ur=1;
ui=0;
sr=cos(pi/le2);
si=-sin(pi/le2);
for j=2:(le2+1)
jm=j-1;
for i=jm:le:N
ip=i+le2;
tr=re(ip);
ti=im(ip);
re(ip)=re(i)-re(ip);
im(ip)=im(i)-im(ip);
re(i)=re(i)+tr;
im(i)=im(i)+ti;
tr=re(ip);
re(ip)=re(ip)*ur-im(ip)*ui;
im(ip)=im(ip)*ur+tr*ui;
end
tr=ur;
94 UR11EC098
ur=tr*sr-ui*si;
ui=tr*si+ui*sr;
end
end
j=N2+1;
for i=2:N-2
if i<j
tr=re(j);
ti=im(j);
re(j)=re(i);
im(j)=im(i);
re(i)=tr;
im(i)=ti;
end
k=N2;
while k<=j
j=j-k;
k=k/2;
end
j=j+k;
end
Function Table:(DIFIFFT)
function [ re, im ] = dififft( re, im, N)
%UNTITLED5 Summary of this function goes
here
% Detailed explanation goes here
N1=N-1;
N2=N/2;
M=log2(N);
%%
%
for l=M:-1:1;
le=2.^l;
le2=le/2;
ur=1;
95 UR11EC098
ui=0;
sr=cos(pi/le2);
si=-sin(pi/le2);
for j=2:(le2+1)
jm=j-1;
for i=jm:le:N
ip=i+le2;
tr=re(ip);
ti=im(ip);
re(ip)=re(i)-re(ip);
im(ip)=re(i)-re(ip);
re(i)=re(i)+tr;
im(i)=im(i)+ti
tr=re(ip);
re(ip)=re(ip)*ur-im(ip)*ui;
im(ip)=im(ip)*ur+tr*ui;
end
tr=ur;
ur=tr*sr-ui*si;
ui=tr*si+ui*sr;
end
end
j=N2+1;
for i=2:N-2
if i<j
tr=re(j);
ti=im(j);
re(j)=re(i);
im(j)=im(i);
re(i)=tr;
im(i)=ti;
end
k=N2;
while k<=j
j=j-k;
k=k/2;
end
j=j+k;
end
96 UR11EC098
Command Window:
Enter the number of points in DIF DFT:4
Enter the real part of the element:1
Enter the imaginary part of the element:0
Enter the real part of the element:1
Enter the imaginary part of the element:0
Enter the real part of the element:1
Enter the imaginary part of the element:0
Enter the real part of the element:1
E
n
t
e
r
t
h
e
i
m
a
g
i
n
97 UR11EC098
a
r
y
p
a
rt
o
f
t
h
e
e
l
e
m
e
n
t:
0
r
98 UR11EC098
e
1
=
4 0 0 0
im1 =
0 0 0 0
Enter the number of points in DIF IFFT:4
Enter the real part of the element:4
Enter the imaginary part of the element:0
Enter the real part of the element:0
Enter the imaginary part of the element:0
Enter the real part of the element:0
Enter the imaginary part of the element:0
Enter the real part of the element:0
Enter the imaginary part of the element:0
re
1
=
1 1 1 1
im1 =
0 0 0 0
Output:
99 UR11EC098
100 UR11EC098
RESULT:
The DFT and IDFT of the given sequence
are computed using FFT algorithm both DITFFT
and DIFFFT.
FLOWCHART:
101 UR11EC098
102 UR11EC098
START
ENTER THE FILTER
SPECIFICATIONS (ORDER OF
THE FILTER, CUT-OFF
FREQUENCY)
dESIGN THE FILTER
PLOT THE WAVEFORMS
STOP
AIM:
Write a MATLAB Script to design a low
pass FIR filter using Window Method for the given
specifications
.
APPARATUS REQUIRED:
PC, MATLAB software
THEORY:
A digital filter is a discrete time LTI system.
It is classified based on the length of the impulse
response as
IIR filters:
Where h [n] has infinite number of samples
and is recursive type.
FIR filters:
They are non-recursive type and h [n] has
finite number of samples.
The transfer function is of the form:
∑
−
=
−
=
1
0
)(
N
n
n
n zhzH
This implies that it has (N-1) zeros located
anywhere in the z-plane and (N-1) poles at Z = h.
THE FIR FILTER CAN BE DESIGNED BY:
103 UR11EC098
Ex. No :8
Date :10-2-14
Ex. No :8
Date :10-2-14 DESIGN OF FIR FILTERSDESIGN OF FIR FILTERS
 Fourier series method
 Frequency sampling method
 Window method
Most of the FIR design methods are
interactive procedures and hence require more
memory and execution time. Also implementation
of narrow transition band filter is costly. But there
are certain reasons to go for FIR.
TYPES OF WINDOWS:
1. Rectangular
2. Triangular
3. Hamming
4. Hanning
5. Blackman
6. Kaiser
LIBRARY FUNCTIONS:
fir1 FIR filter design using the Window
method.
B = fir1(N,Wn) designs an Nth order low
pass FIR digital filter and returns the filter
coefficients of vector B of length (N+1).
The cut-off frequency Wn must be between
0 < Wn < 1.0, with 1.0 corresponding to
half the sample rate. The filter B is real and
has linear phase. The normalized gain of the
filter at Wn is -6 dB.
B = fir1(N,Wn,'high') designs an Nth order
high pass filter. You can also use
B = fir1(N,Wn,'low') to design a low pass
filter.
104 UR11EC098
If Wn is a two-element vector, Wn = [W1
W2], fir1 returns an order N band pass filter
with pass band W1 < W < W2.You can also
specify B = fir1(N,Wn,'bandpass'). If Wn =
[W1 W2], B = fir1(N,Wn,'stop') will design
a band-stop filter.
If Wn is a multi-element vector, Wn = [W1
W2 W3 W4 W5 ... WN], fir1 returns a N-
order multi-band filter with
bands 0 < W < W1, W1 < W < W2, ..., WN
< W < 1.
B = fir1(N,Wn,'DC-1') makes the first band
a pass band.
B = fir1(N,Wn,'DC-0') makes the first band
a stop band.
B = fir1(N,Wn,WIN) designs an N-th order
FIR filter using the vector WIN of (N+1)
length to window the impulse response. If
empty or omitted, fir1 uses a Hamming
window of length N+1. For a complete list
of available windows, see the Help for the
WINDOW function. KAISER and
CHEBWIN can be specified with an
optional trailing argument. For example, B
= fir1(N,Wn,kaiser(N+1,4)) uses a Kaiser
window with beta=4. B =
fir1(N,Wn,'high',chebwin(N+1,R)) uses a
Chebyshev window with R decibels of
relative sidelobe attenuation.For filters with
a gain other than zero at Fs/2, e.g., high pass
and band stop filters, N must be even.
Otherwise, N will be incremented by one.
In this case, the window length should be
specified as N+2. By default, the filter is
scaled so the center of the first pass band
has magnitude exactly one after windowing.
Use a trailing 'noscale' argument to
prevent this scaling, e.g.
105 UR11EC098
B = fir1(N,Wn,'noscale'), B =
fir1(N,Wn,'high','noscale'),
B = fir1(N,Wn,wind,'noscale'). You can
also specify the scaling explicitly, e.g.
fir1(N,Wn,'scale'), etc.
We can specify windows from the Signal
Processing Toolbox, such as boxcar,
hamming, hanning, bartlett, blackman,
kaiser or chebwin
w = hamming(n) returns an n-point
symmetric Hamming window in the column
vector w. n should be a positive integer.
w = hanning(n) returns an n-point
symmetric Hann window in the column
vector w. n must be a positive integer.
w=triang(n) returns an n-point triangular
window in the column vector w. The
triangular window is very similar to a
Bartlett window. The Bartlett window
always ends with zeros at samples 1 and n,
while the triangular window is nonzero at
those points. For n odd, the center (n-2)
points of triang(n-2) are equivalent to
bartlett(n).
106 UR11EC098
w = rectwin(n) returns a rectangular
window of length n in the column vector w.
This function is provided for completeness.
A rectangular window is equivalent to no
window at all.
ALGORITHM/PROCEDURE:
1. Click on the MATLAB icon on the desktop
(or go to Start – All Programs and
click on MATLAB) to get into the
Command Window.
2. Type ‘edit’ in the MATLAB prompt ‘>>’
that appears in the Command window.
3. Write the program in the ‘Edit’ window and
save it in ‘M-file’.
4. Run the program.
5. Enter the input in the Command Window.
6. The result is displayed in the Command
window and the graphical output is
displayed in the Figure Window.
Source code :1
%windows technique of Rectangular window
using low pass filter
clc;
clear all;
close all;
N=input('Size of window:');
107 UR11EC098
wc=input('Cut off frequency:');
h=fir1(N-1,wc/pi,boxcar(N));
tf(h,1,1,'variable','z^-1');
freqz(h);
xlabel('Frequency');
ylabel('Magnitude');
title('FIR Filter');
Source code :2
%windows technique of Triangular(Bartlet
Window) using High pass filter
clc;
clear all;
close all;
N=input('Size of window:');
wc=input('Cut off frequency:');
h=fir1(N-1,wc/pi,'high',triang(N));
tf(h,1,1,'variable','z^-1');
freqz(h);
xlabel('Frequency');
ylabel('Magnitude');
title('FIR Filter');
Source code :3
%windows technique of Hamming using Band
pass filter
clc;
clear all;
close all;
N=input('Size of window:');
wc1=input('Lower Cut off frequency:');
wc2=input('Upper Cut off frequency:');
wc=[wc1 wc2];
h=fir1(N-1,wc/pi,'bandpass',hamming(N));
tf(h,1,1,'variable','z^-1');
freqz(h);
xlabel('Frequency');
ylabel('Magnitude');
108 UR11EC098
title('FIR Filter');
Source code :4
%windows technique of Hanning using Band stop
filter
clc;
clear all;
close all;
N=input('Size of window:');
wc1=input('Lower Cut off frequency:');
wc2=input('Upper Cut off frequency:');
wc=[wc1 wc2];
h=fir1(N-1,wc/pi,'stop',hanning(N));
tf(h,1,1,'variable','z^-1');
freqz(h);
xlabel('Frequency');
ylabel('Magnitude');
title('FIR Filter');
Source code :5
%windows technique of Blackman window using
low pass filter
clc;
clear all;
close all;
N=input('Size of window:');
wc=input('Cut off frequency:');
h=fir1(N-1,wc/pi,blackman(N));
tf(h,1,1,'variable','z^-1');
freqz(h);
xlabel('Frequency');
ylabel('Magnitude');
title('FIR Filter');
Command Window :1
109 UR11EC098
Output:1
Command Window :2
OUTPUT: 2
110 UR11EC098
Command Window :3
Output:3
111 UR11EC098
Command Window :4
Output:4
112 UR11EC098
Command Window :5
Output:
RESULT:
113 UR11EC098
The given low pass filter was designed using
Window method and manually verified filter co-
efficient of the filters.
FLOWCHART:
114 UR11EC098
START
ENTER THE FILTER
SPECIFICATIONS (PASS,
STOP BAND GAINS AND
EDGE FREQUENCIES)
DESIGN THE ANALOG BUTTERWORTH
and chebyshev FILTER
PLOT THE WAVEFORMS
STOP
AIM:
Write a MATLAB Script to design Analog
Butterworth filters for the given specifications.
APPARATUS REQUIRED:
PC, MATLAB software
THEORY:
BUTTERWORTH FILTER:
Low pass Analog Butterworth filters are all
pole filters characterised by magnitude frequency
response by
)( ωjH 2
=
N
c
2
1
1






Ω
Ω
+
where N is the order of the filter and cΩ is
the cut-off frequency.
As N→α , the low pass filter is said to be
normalized. All types of filters namely-Low pass,
High pass, Band pass and Band elimination filters
can be derived from the Normalized Low pass
filter.
STEPS IN DESIGNING ANALOG FILTER:
115 UR11EC098
Ex. No : 9
Date: 17-02-14
Ex. No : 9
Date: 17-02-14
9.DESIGN OF BUTTERWORTH FILTERS9.DESIGN OF BUTTERWORTH FILTERS
1. Transform the given specification to a
Normalized Low pass specification
2. Find the order of the filter N and cut-off
frequency Ωc
3. Find the transfer function H(s) of
normalized LPF.
4. Use the applicable analog-to-analog
transformation to get the transfer function of
the required filter.
LIBRARY FUNCTIONS:
• butter: Butterworth digital and
analog filter design.
[B, A] = butter (N,Wn) designs an Nth order
Low pass digital Butterworth filter and
returns the filter coefficient vectors B
(numerator) and A (denominator) in length
N+1. The coefficients are listed in
descending powers of z. The cut-off
frequency Wn must be in the range 0.0 <
Wn < 1.0, with 1.0 corresponding to half the
sample rate.
butter (N,Wn,'s'),butter
(N,Wn,'low','s'),butter
(N,Wn,'high','s'),butter (N,Wn,'pass','s')and
butter (N,Wn,'stop','s')design analog
Butterworth filters. In this case, Wn is in
[rad/s] and it can be greater than 1.0.
• buttord: Butterworth filter order
selection.
116 UR11EC098
[N, Wn] = buttord (Wp, Ws, Rp, Rs)
returns the order N of the lowest order
digital Butterworth filter that loses no more
than Rp dB in the pass band and has at
least Rs dB of attenuation in the stop band.
Wp and Ws are the pass band and stop band
edge frequencies, normalized from 0 to 1
(where 1 corresponds to pi radians/sample).
For example,
Lowpass: Wp = .1, Ws = .2
Highpass: Wp = .2, Ws = .1
Bandpass: Wp = [.2 .7], Ws = [.1 .8]
Bandstop: Wp = [.1 .8], Ws = [.2 .7]
buttord: also returns Wn, the Butterworth
natural frequency (or) the "3 dB frequency"
to be used with BUTTER to achieve the
specifications.
[N, Wn] = buttord (Wp, Ws, Rp, Rs, 's')
does the computation for an analog filter,
in which case Wp and Ws are in
radians/second. When Rp is chosen as 3
dB, the Wn in BUTTER is equal to Wp in
BUTTORD.
• angle : Phase angle.
Theta=angle (H) returns the phase angles, in
radians, of a matrix with complex elements.
• freqs : Laplace-transform (s-domain)
frequency response.
117 UR11EC098
H = freqs(B,A,W) returns the complex
frequency response vector H of the filter
B/A:
B(s) b (1)s nb-1
+ b(2)s nb-
2
+ ... + b(nb)
H(s) = ---- =
--------------------------------------------------
A(s) a(1)s na-1
+ a(2)s na-2
+ ... + a(na)
given the numerator and denominator
coefficients in vectors B and A. The
frequency response is evaluated at the points
specified in vector W (in rad/s). The
magnitude and phase can be graphed by
calling freqs(B,A,W) with no output
arguments.
• tf: Transfer function
SYS = tf(NUM,DEN) creates a continuous-
time transfer function SYS with
numerator(s) NUM and denominator(s)
DEN. The output SYS is a tf object.
ALGORITHM/PROCEDURE:
1. Click on the MATLAB icon on the desktop
(or go to Start – All programs and click on
118 UR11EC098
MATLAB) to get into the Command
Window.
2. Type ‘edit’ in the MATLAB prompt ‘>>’
that appears in the Command window.
3. Write the program in the ‘Edit’ window and
save it in ‘M-file’.
4. Run the program.
5. Enter the input in the command window.
6. The result is displayed in the Command
window and the graphical output is
displayed in the Figure Window.
Butterworth Filters
SOURCE CODE:1
clc;
clear all;
close all;
%% Butterworth low pass Filter
% Filter Specifications
k1=input('Enter the passband gain in db:');
k2=input('Enter the stopband gain in db:');
w1=input('Enter the passband edge frequency in
rad/Sec:');
w2=input('Enter the stopband edge frequency in
rad/Sec:');
%Find the order and Cutofrf frequency using the
given specification of
%filter
[n,Wc]=buttord(w1,w2,k1,k2,'s');
disp('The order is:');
disp(n);
disp('The cutoff frequency is:');
119 UR11EC098
disp(Wc);
% Low pass filtering
[b,a]=butter(n,Wc,'low','s');
%Plotting magnitude & phase response
f=linspace(1,512,1000);
h=freqs(b,a,f);
m=20*log(abs(h));
subplot(2,1,1);
semilogx(f,m);
xlabel('Frequency');
ylabel('Magnitude');
title('Magnitude response of Butterworth LPF');
% Phase response
p=angle(h);
subplot(2,1,2);
semilogx(f,p);
xlabel('Frequency');
ylabel('Phase');
title('Phase response of Butterworth LPF');
SOURCE CODE:2
clc;
clear all;
close all;
%% Butterworth high pass Filter
% Filter Specifications
k1=input('Enter the passband gain in db:');
k2=input('Enter the stopband gain in db:');
w1=input('Enter the passband edge frequency in
rad/Sec:');
w2=input('Enter the stopband edge frequency in
rad/Sec:');
120 UR11EC098
%Find the order and Cutofrf frequency using the
given specification of
%filter
[n,Wc]=buttord(w1,w2,k1,k2,'s');
disp('The order is:');
disp(n);
disp('The cutoff frequency is:');
disp(Wc);
% Low pass filtering
[b,a]=butter(n,Wc,'high','s');
%Plotting magnitude & phase response
f=linspace(1,512,1000);
h=freqs(b,a,f);
m=20*log(abs(h));
subplot(2,1,1);
semilogx(f,m);
xlabel('Frequency');
ylabel('Magnitude');
title('Magnitude response of Butterworth HPF');
% Phase response
p=angle(h);
subplot(2,1,2);
semilogx(f,p);
xlabel('Frequency');
ylabel('Phase');
title('Phase response of Butterworth HPF');
SOURCE CODE:3
clc;
clear all;
close all;
%% Bandpass Filter Specifications
Wp=input('Enter the pass band edge frequency : ');
Ws=input('Enter the stop band edge frequency : ');
121 UR11EC098
Rp=input('Enter the Pass band ripple: ');
Rs=input('Enter the stop band gain: ');
%To find order of the filter
[N]=buttord(Wp,Ws,Rp,Rs,'s')
%To find cut off frequency
Wc=[Wp Ws];
%Band pass Filtering
[b,a]=butter(N,Wc,'bandpass','s');
%plotting magnitude and phase response
figure(1);freqs(b,a);
SOURCE CODE:4
clc;
clear all;
close all;
%% Bandstop Filter Specifications
Wp=input('Enter the pass band edge frequency : ');
Ws=input('Enter the stop band edge frequency : ');
Rp=input('Enter the Pass band ripple: ');
Rs=input('Enter the stop band gain: ');
%To find order of the filter
[N]=buttord(Wp,Ws,Rp,Rs,'s')
%To find cut off frequency
Wc=[Wp Ws];
%Band stop Filtering
[b,a]=butter(N,Wc,'stop','s');
%plotting magnitude and phase response
figure(1);freqs(b,a);
Command Windows :
122 UR11EC098
Using Low pass filter
Using High pass filter
Using Band pass filter
Using Band stop filter
123 UR11EC098
OUTPUTS:
Using Low pass filter
Using High pass filter
124 UR11EC098
Using Band pass filter
125 UR11EC098
Using Band stop filter
126 UR11EC098
RESULT:
Analog Butterworth Filter is designed for
the given specifications, and manually verified the
order, cut off frequency and filter co-efficient of
the filter.
FLOWCHART:
127 UR11EC098
128 UR11EC098
START
ENTER THE FILTER
SPECIFICATIONS (PASS,
STOP BAND GAINS AND
EDGE FREQUENCIES)
DESIGN THE ANALOG BUTTERWORTH
and chebyshev FILTER
PLOT THE WAVEFORMS
STOP
AIM:
Write a MATLAB Script to design Analog
Chebyshev filter for the given specifications.
APPARATUS REQUIRED:
PC, MATLAB software
THEORY:
Chebyshev Filters :
There are two types of Chebyshev filters.
Type I are all-pole filters that exhibit equi-ripple
behaviour in pass band and monotonic
characteristics in stop band.
Type II are having both poles and zeros and
exhibit monotonic behavior in pass band and equi-
ripple behavior in stop band. The zero lies on the
imaginary axis.
The magnitude-squared function is given as
)/(1
1
)(
22
2
pC
jH
N ΩΩ+
=
ε
ω
ε is the ripple parameter in pass band
CN(x) is the Nth
order Chebyshev polynomial
defined as
129 UR11EC098
Ex. No : 10
Date: 17-02-14
Ex. No : 10
Date: 17-02-14
10.DESIGN OF CHEBYSHEV FILTERS10.DESIGN OF CHEBYSHEV FILTERS
CN(x) =




>
≤
−
−
1),cosh(
1,)cosh(
1
1
xxNCos
xxNCos
STEPS IN DESIGNING ANALOG FILTER:
1.Transform the given specification to a
Normalized Low pass specification
2. Find the order of the filter N and cut-off
frequency Ωc
3. Find the transfer function H(s) of
normalized LPF.
4. Use the applicable analog-to-analog
transformation to get the transfer function of
the required filter.
LIBRARY FUNCTIONS:
• cheb1ord: Chebyshev Type I filter
order selection.
[N, Wn] = cheb1ord (Wp, Ws, Rp, Rs)
returns the order N of the lowest order
digital Chebyshev Type I filter that loses no
more than Rp dB in the pass band and has
at least Rs dB of attenuation in the stop
band. Wp and Ws are the pass band and
stop band edge frequencies, normalized
130 UR11EC098
from 0 to 1 (where 1 corresponds to pi
radians/sample). For example,
Lowpass: Wp = .1, Ws = .2
Highpass: Wp = .2, Ws = .1
Bandpass: Wp = [.2 .7], Ws = [.1 .8]
Bandstop: Wp = [.1 .8], Ws = [.2 .7]
cheb1ord also returns Wn, the Chebyshev
natural frequency to use with cheby1 to
achieve the specifications.
[N, Wn] = cheb1ord (Wp, Ws, Rp, Rs, 's')
does the computation for an analog filter,
in which case Wp and Ws are in
radians/second.
• cheby1 Chebyshev Type I digital and
analog filter design.
[B,A] = cheby1 (N,R,Wn) designs an Nth
order Low pass digital Chebyshev filter
with R decibels of peak-to-peak ripple in the
pass band. cheby1 returns the filter
coefficient vectors B (numerator) and A
(denominator) of length N+1. The cut-off
frequency Wn must be in the range 0.0 <
Wn < 1.0, with 1.0 corresponding to half the
sample rate. Use R=0.5 as a starting point,
if you are unsure about choosing R.
cheby1 (N,R,Wn,'s'), cheby1
(N,R,Wn,'low','s'), cheby1
(N,R,Wn,'high','s'), cheby1
(N,R,Wn,'pass','s') and cheby1
131 UR11EC098
(N,R,Wn,'stop','s') design analog Chebyshev
Type I filters. In this case, Wn is in [rad/s]
and it can be greater than 1.0.
ALGORITHM/PROCEDURE:
1. Click on the MATLAB icon on the desktop
(or go to Start – All programs and click on
MATLAB) to get into the Command
Window.
2. Type ‘edit’ in the MATLAB prompt ‘>>’
that appears in the Command window.
3. Write the program in the ‘Edit’ window and
save it in ‘M-file’.
4. Run the program.
5. Enter the input in the command window.
6. The result is displayed in the Command
window and the graphical output is
displayed in the Figure Window.
CHEBYSHEV FILTERS
:
Source code:1
clc;
clear all;
close all;
%% Chebyshev low pass Filter
% Filter Specifications
k1=input('Enter the passband ripple in db:');
k2=input('Enter the stopband attenuation in db:');
132 UR11EC098
w1=input('Enter the passband edge frequency in
rad/Sec:');
w2=input('Enter the stopband edge frequency in
rad/Sec:');
%Find the order and Cutofrf frequency using the
given specification of
%filter
[n,Wc]=cheb1ord(w1,w2,k1,k2,'s');
disp('The order is:');
disp(n);
disp('The cutoff frequency is:');
disp(Wc);
% Low pass filtering
[b,a]=cheby1(n,k1,w1,'low','s');
figure(1);freqs(b,a);
Source code:2
clc;
clear all;
close all;
%% Chebyshev High pass Filter
% Filter Specifications
k1=input('Enter the passband ripple in db:');
k2=input('Enter the stopband attenuation in db:');
w1=input('Enter the passband edge frequency in
rad/Sec:');
w2=input('Enter the stopband edge frequency in
rad/Sec:');
%Find the order and Cutofrf frequency using the
given specification of
%filter
[n,Wc]=cheb1ord(w1,w2,k1,k2,'s');
disp('The order is:');
disp(n);
disp('The cutoff frequency is:');
133 UR11EC098
disp(Wc);
% High pass filtering
[b,a]=cheby1(n,k1,w1,'high','s');
figure(1);freqs(b,a);
Source code: 3
clc;
clear all;
close all;
%% Bandpass Filter Specifications
Wp=input('Enter the pass band edge frequency : ');
Ws=input('Enter the stop band edge frequency : ');
Rp=input('Enter the Pass band ripple: ');
Rs=input('Enter the stop band gain: ');
%To find order of the filter
[N]=cheb1ord(Wp,Ws,Rp,Rs,'s')
%To find cut off frequency
Wc=[Wp Ws];
%Band pass Filtering
[b,a]=cheby1(N,Rp,Wc,'bandpass','s');
%plotting magnitude and phase response
figure(1);freqs(b,a);
Source code: 4
clc;
clear all;
close all;
%% Bandstop Filter Specifications
Wp=input('Enter the pass band edge frequency : ');
Ws=input('Enter the stop band edge frequency : ');
Rp=input('Enter the Pass band ripple: ');
Rs=input('Enter the stop band gain: ');
134 UR11EC098
%To find order of the filter
[N]=cheb1ord(Wp,Ws,Rp,Rs,'s')
%To find cut off frequency
Wc=[Wp Ws];
%Bandstop Filtering
[b,a]=cheby1(N,Rp,Wc,'stop','s');
%plotting magnitude and phase response
figure(1);freqs(b,a);
Command Window :1(LPF)
Output:
135 UR11EC098
Command Window :2(HPF)
Output:
136 UR11EC098
Command Window :3(BPF)
Output:
137 UR11EC098
Command Window :4(BSF)
Output:
138 UR11EC098
RESULT:
Analog Chebyshev Filter is designed for the
given specifications, and manually verified the
139 UR11EC098
order, cut off frequency and filter co-efficient of
the filter.
FLOWCHART:
140 UR11EC098
START
ENTER THE FILTER
SPECIFICATIONS (PASS,
STOP BAND GAINS AND
EDGE FREQUENCIES)
DESIGN THE ANALOG BUTTERWORTH and
CHEBYSHEV LOW PASS FILTER
PLOT THE WAVEFORMS
STOP
CONVERT THE LOW PASS FILTERS in to
digital filterS by using the impulse invariant and
bilinear TRANSFORMATIONS
141 UR11EC098
AIM:
Write a MATLAB Script to design
Butterworth and Chebyshev low pass filters using
Bilinear Transformation
Impulse Invariant Transformation
.
APPARATUS REQUIRED:
PC, MATLAB software
THEORY:
A digital filter is a linear time invariant
discrete time system. The digital filters are
classified into two, based on their lengths of
impulse response
1. Finite Impulse response (FIR)
They are of non-recursive type and h
[n] has finite number of samples
2. Infinite Impulse response (IIR)
h[n] has finite number of samples.
They are of recursive type. Hence,
their transfer function is of the form
∑=
−
=
α
0
)()(
n
n
znhzH
142 UR11EC098
Ex. No : 11
Date: 03-03-14
Ex. No : 11
Date: 03-03-14 11.DESIGN OF IIR FILTERS11.DESIGN OF IIR FILTERS
∑
∑
−
=
−
−
=
−
+
=
1
1
1
0
1
)(
N
j
j
j
M
K
k
k
Za
Zb
ZH
The digital filters are designed from analog
filters. The two widely used methods for digitizing
the analog filters include
1. Bilinear transformation
2. Impulse Invariant transformation
The bilinear transformation maps the s-plane into
the z-plane by
H(Z) = 1
1
1
12
|)(
−
−
+
−
×=
Z
Z
T
SH s
This transformation maps the jΩ axis (from Ω = -∞
to +∞) repeatedly around the unit circle (exp ( jw),
from w=-π to π ) by






=Ω
2
tan
2 ω
T
BILINEAR TRANSFORMATION:
DESIGN STEPS:
1. From the given specifications, Find
pre-warped analog frequencies using






=Ω
2
tan
2 ω
T
2. Using the analog frequencies, find
H(s) of the analog filter
143 UR11EC098
3. Substitute 1
1
1
12
−
−
+
−
×=
Z
Z
T
S in the H(s)
of Step:2
IMPULSE INVARIANT
TRANSFORMATION:
DESIGN STEPS:
1. Find the analog frequency using  =
T/ω
2. Find the transfer function of analog filter
Ha(s)
3. Express the analog filter transfer function
as a sum of single pole filters
4. Compute H(Z) of digital filter using the
formula
∑
=
− −
−
=
N
k
ZTP
k
k
e
C
ZH
1
1
1
)(
LIBRARY FUNCTIONS:
• Impinvar: Impulse Invariant method for
analog-to-digital filter conversion [bz,az] =
impinvar(b,a,fs) creates a digital filter with
numerator and denominator coefficients bz
and az, respectively, whose impulse
response is equal to the impulse response of
the analog filter with coefficients b and a,
scaled by 1/fs. If you leave out the argument
144 UR11EC098
fs (or) specify fs as an empty vector [ ], it
takes the default value of 1 Hz.
• Bilinear: Bilinear transformation method
for analog-to-digital filter conversion. The
bilinear transformation is a mathematical
mapping of variables. In digital filtering, it
is a standard method of mapping the s or
analog plane into the z or digital plane. It
transforms analog filters, designed using
classical filter design
ALGORITHM/PROCEDURE:
1. Calculate the attenuation in dB for the given
design parameters
2. Design the analog counterpart
3. Using Impulse Invariant /Bilinear
transformation design the digital filter
145 UR11EC098
4. Display the transfer function. Plot the
magnitude response and phase response
SOURCE CODE:
/ Butterworth Lowpass Impulse
invariant method
clc;
clear all;
close all;
warning off;
% Design of IIR Filters
%% Filter Specifications
% Input Wp,Ws,Sp,Ss,T
% T=1,bothe ripple gains should be b/w .1 to .3
disp(' Butterworth Lowpass filter using Impulse
invariant method ');
T=input('Enter the Sampling Frequency in rad/sec:
');
Sp=input('Enter the Pass-band Ripple Gain: ');
Wp=input('Enter the Pass-band Edge Frequency in
rad/sec: ');
Ss=input('Enter the Stop-band Ripple Gain: ');
Ws=input('Enter the Stop-band Edge Frequency in
rad/sec: ');
% Calculation of ohmp,ohms,Ap,As
Ap=abs(20*log10(1-Sp));
As=abs(20*log10(Ss));
ohmp=Wp/T;
ohms=Ws/T;
% Butterworth Filter
146 UR11EC098
% Calculation of order and cutoff freq. for the
above filter specs.
[n,Wc]=buttord(ohmp,ohms,Ap,As,'s');
% Low Pass Filtering
[b,a]=butter(n,Wc,'low','s');
[bz,az] = impinvar(b,a,T);
tf(bz,az,T);
O=linspace(-pi,pi,50);
% O is the freq. axis
H=freqz(bz,az,O);
% Magnitude Response
Hm=20*log10(abs(H));
subplot(2,1,1);
semilogx(O,Hm);
xlabel('Frequency');
ylabel('Magnitude');
title('Magnitude Response of IIR Filter using
Impulse Invariant Method');
% Phase Response
Ha=angle(H);
subplot(2,1,2);
semilogx(O,Ha);
xlabel('Frequency');
ylabel('Phase');
title('Phase Response of IIR Filter using Impulse
Invariant Method');
/ Butterworth Lowpass Bilinear
Transformation Method
clc;
clear all;
close all;
warning off;
% Design of IIR Filters
147 UR11EC098
%% Filter Specifications
% Input Wp,Ws,Sp,Ss,T
% T=1,both the ripple gains should have band
width( .1 to .3)
disp(' Butterworth Lowpass filter using Bilnear
transformation method ');
T=input('Enter the Sampling Frequency in rad/sec:
');
Sp=input('Enter the Pass-band Ripple Gain: ');
Wp=input('Enter the Pass-band Edge Frequency in
rad/sec: ');
Ss=input('Enter the Stop-band Ripple Gain: ');
Ws=input('Enter the Stop-band Edge Frequency in
rad/sec: ');
% Calculation of ohmp,ohms,Ap,As
Ap=abs(20*log10(1-Sp));
As=abs(20*log10(Ss));
ohmp=Wp/T;
ohms=Ws/T;
% Butterworth Filter
% Calculation of order and cutoff freq. for the
above filter specs.
[n,Wc]=buttord(ohmp,ohms,Ap,As,'s');
% Low Pass Filtering
[b,a]=butter(n,Wc,'low','s');
[bz,az] = bilinear(b,a,1/T);
tf(bz,az,T);
O=linspace(-pi,pi,50);
% O is the freq. axis
H=freqz(bz,az,O);
% Magnitude Response
Hm=20*log10(abs(H));
subplot(2,1,1);
semilogx(O,Hm);
xlabel('Frequency');
148 UR11EC098
ylabel('Magnitude');
title('Magnitude Response of IIR Filter using
Bilinear Transformation Method');
% Phase Response
Ha=angle(H);
subplot(2,1,2);
semilogx(O,Ha);
xlabel('Frequency');
ylabel('Phase');
title('Phase Response of IIR Filter using Bilinear
Transformation Method');
/ Chebyshev Lowpass Impulse invariant
method
clc;
clear all;
close all;
warning off;
% Design of IIR Filters
%% Filter Specifications
% Input Wp,Ws,Sp,Ss,T
% T=1,bothe ripple gains should be b/w .1 to .3
disp(' Chebyshev Lowpass filter using Impulse
invariant method ');
T=input('Enter the Sampling Frequency in rad/sec:
');
Sp=input('Enter the Pass-band Ripple Gain: ');
Wp=input('Enter the Pass-band Edge Frequency in
rad/sec: ');
Ss=input('Enter the Stop-band Ripple Gain: ');
Ws=input('Enter the Stop-band Edge Frequency in
rad/sec: ');
% Calculation of ohmp,ohms,Ap,As
Ap=abs(20*log10(1-Sp));
149 UR11EC098
As=abs(20*log10(Ss));
ohmp=Wp/T;
ohms=Ws/T;
% Chebyshev Filter
% Calculation of order and cutoff freq. for the
above filter specs.
[n,Wc2]=cheb1ord(ohmp,ohms,Ap,As,'s')
% Low Pass Filtering
[b,a]=cheby1(n,Ap,Wc2,'low','s');
[bz,az] = impinvar(b,a,T);
tf(bz,az,T);
O=linspace(-pi,pi,50);
% O is the freq. axis
H=freqz(bz,az,O);
% Magnitude Response
Hm=20*log10(abs(H));
subplot(2,1,1);
semilogx(O,Hm);
xlabel('Frequency');
ylabel('Magnitude');
title('Magnitude Response of IIR Filter using
Impulse Invariant Method');
% Phase Response
Ha=angle(H);
subplot(2,1,2);
semilogx(O,Ha);
xlabel('Frequency');
ylabel('Phase');
title('Phase Response of IIR Filter using Impulse
Invariant Method');
/Chebyshev Lowpass Bilinear
Transformation Method
clc;
150 UR11EC098
clear all;
close all;
warning off;
% Design of IIR Filters
%% Filter Specifications
% Input Wp,Ws,Sp,Ss,T
% T=1,bothe ripple gains should be b/w .1 to .3
disp(' Chebyshev Lowpass filter using Bilnear
transformation method ');
T=input('Enter the Sampling Frequency in rad/sec:
');
Sp=input('Enter the Pass-band Ripple Gain: ');
Wp=input('Enter the Pass-band Edge Frequency in
rad/sec: ');
Ss=input('Enter the Stop-band Ripple Gain: ');
Ws=input('Enter the Stop-band Edge Frequency in
rad/sec: ');
% Calculation of ohmp,ohms,Ap,As
Ap=abs(20*log10(1-Sp));
As=abs(20*log10(Ss));
ohmp=Wp/T;
ohms=Ws/T;
% Chebyshev Filter
% Calculation of order and cutoff freq. for the
above filter specs.
[n,Wc2]=cheb1ord(ohmp,ohms,Ap,As,'s')
% Low Pass Filtering
[b,a]=cheby1(n,Ap,Wc2,'low','s');
[bz,az] = bilinear(b,a,1/T);
tf(bz,az,T);
O=linspace(-pi,pi,50);
% O is the freq. axis
H=freqz(bz,az,O);
% Magnitude Response
Hm=20*log10(abs(H));
151 UR11EC098
subplot(2,1,1);
semilogx(O,Hm);
xlabel('Frequency');
ylabel('Magnitude');
title('Magnitude Response of IIR Filter using
Bilinear Transformation Method');
% Phase Response
Ha=angle(H);
subplot(2,1,2);
semilogx(O,Ha);
xlabel('Frequency');
ylabel('Phase');
title('Phase Response of IIR Filter using Bilinear
Transformation Method');
/ Butterworth Lowpass Impulse
invariant method
Command window:
Output:
152 UR11EC098
/ Butterworth Lowpass Bilinear
Transformation Method
Command Window :
153 UR11EC098
Output:
/ Chebyshev Lowpass Impulse invariant
method
Command Window:
154 UR11EC098
Output:
/Chebyshev Lowpass Bilinear
Transformation Method
155 UR11EC098
Command Window:
Output:
156 UR11EC098
RESULT:
Butterworth and Chebyshev Lowpass filters
were designed using Bilinear and Impulse
Invariant transformations, and manually verified
157 UR11EC098
the order, cut off frequency and filter co-efficient
of the filters.
FLOWCHART:
158 UR11EC098
START
ENTER THE SYSTEM’S
NUMERATOR AND
DENOMINATOR
COEFFICIENTS
Generate the waveform of TIME DOMAIN
response by using the appropriate library function
PLOT THE WAVEFORMS
STOP
AIM:
Write a MATLAB Script to find the time
domain response (impulse response and step
response) for the given FIR and IIR systems
(filters).
.
APPARATUS REQUIRED:
PC, MATLAB software
THEORY:
IMPULSE RESPONSE:
δ[n]
y1[n]=T[δ[n]]=h[n]
If the input to the system is a unit impulse
(ie) x[n] = δ[n], then the output of the system,
known as the impulse response, is denoted by h [n]
where,
h[n]=T[δ[n]]
STEP RESPONSE:
159 UR11EC098
Ex. No :12(a)
Date:10-03-14
Ex. No :12(a)
Date:10-03-14
TIME DOMAIN RESPONSE OF LTI SYSTEMSTIME DOMAIN RESPONSE OF LTI SYSTEMS
T
T
u[n]
y2[n]=T[u[n]]=s[n]
If the input to the system is a unit step (ie)
x[n] = u[n], then the output of the system, known
as step response, is denoted by s[n] where,
s[n]=T[u[n]]
The relation between the impulse response
and step response is given by
s[n] = u[n]*h[n]
* is the Convolution operator
LIBRARY FUNCTIONS:
• filter: Filters data with an infinite
impulse response (IIR) or finite
impulse
response (FIR) filter .The filter function
filters a data sequence using a digital filter
which works for both real and complex
inputs. The filter is a direct form II
transposed implementation of the standard
difference equation.
y = filter (b, a, X) filters the data in
vector X with the filter described by
numerator coefficient vector b and
denominator coefficient vector a. If a(1) is
160 UR11EC098
not equal to 1, filter normalizes the filter
coefficients by a(1). If a(1) equals 0, filter
returns an error.
ALGORITHM/PROCEDURE:
1. Click on the MATLAB icon on the desktop
(or go to Start – All Programs and click on
MATLAB) to get into the Command
Window
2. Type ‘edit’ in the MATLAB prompt ‘>>’
that appears in the Command window.
3. Write the program in the ‘Edit’ window and
save it in ‘M-file’
4. Run the program
5. Enter the input in the command window
6. The result is displayed in the Command
window and the graphical output is
displayed in the Figure Window
SOURCE CODE:
PROGRAM 1
clc;
clear all;
close all;
%% Input the samples
% Time domain response of FIR filter
N=16; %Input samples
k=0:N-1;
x=(k==0);
161 UR11EC098
b0=1; b1= -1; b2=-2;
B=[b0,b1,b2]; %Numerator coeff.
A=1; %Denominator coeff.
%Filtering
y=filter(B, A ,x);
%Plot the graph
subplot(2,2,1), stem(k,x,'r');
xlabel('Time');
ylabel('Unit Impulse');
title('Impulse input');
subplot(2,2,2), stem(k,y,'r');
xlabel('Frequency');
ylabel('Magnitude');
title('Impulse Response FIR Filter');
% Time domain Response of IIR Filter
N1=10; %input samples
k1=0:N1-1;
x1=(k1==0);
B1=1;
a=0.8;
A1=[1,-a];
y1=filter(B1, A1 ,x1);
%plot the graph
subplot(2,2,3), stem(k1,x1,'r');
xlabel('Time');
ylabel('Unit Impulse');
title('Impulse input');
subplot(2,2,4), stem(k1,y1,'r');
xlabel('Frequency');
ylabel('Magnitude');
title('Impulse Response IIR Filter');
PROGRAM 2
clc;
clear all;
close all;
%% Input the samples
% Time domain Response of FIR filter
162 UR11EC098
N=16; %Input samples
k=0:N-1;
x(1:N)=1;
b0=1; b1= -1; b2=-2;
B=[b0,b1,b2]; %Numerator coeff.
A=1; %Denominator coeff.
%Filtering
y=filter(B, A ,x);
%plot the graph
subplot(2,2,1);
stem(k,x,'r');
xlabel('Time');
ylabel('Unit step signal');
title('Unit step input signal');
subplot(2,2,2);
stem(k,y,'r');
xlabel('Frequency');
ylabel('Magnitude');
title('Step Response FIR filter');
% Time domain response of IIR filter
N1=10; %Input samples
k1=0:N1-1;
x1(1:N1)=1;
B1=1;
a=0.8;
A1=[1,-a];
y1=filter(B1, A1 ,x1);
%plot the graph
subplot(2,2,3);
stem(k1,x1,'r');
xlabel('Time');
ylabel('Unit step input');
title('Unit step input signal');
subplot(2,2,4);
stem(k1,y1,'r');
xlabel('Frequency');
ylabel('Magnitude');
title('Step Response IIR Filter');
163 UR11EC098
Output for Unit impulse input:
Output for Unit step input:
164 UR11EC098
RESULT:
165 UR11EC098
The Time domain responses of the given
systems were found using MATLAB and manually
verified.
FLOWCHART:
166 UR11EC098
START
ENTER THE SYSTEM’S
NUMERATOR AND
DENOMINATOR
COEFFICIENTS
Generate the waveform of frequencY
PLOT THE WAVEFORMS
STOP
AIM:
Write a MATLAB Script to find the
frequency domain response (magnitude response
and phase response) for the given FIR and IIR
systems (filters).
.
APPARATUS REQUIRED:
PC, MATLAB software
THEORY:
IMPULSE RESPONSE:
x[n]
y[n]=T[x[n]]
If the input to the system is a unit impulse
(ie) x[n]=δ[n], then the output of the system is
known as impulse response denoted by h[n] where,
h[n]=T[δ[n]]
167 UR11EC098
Ex. No : 12(b)
Date:10-03-14
Ex. No : 12(b)
Date:10-03-14
FREQUENCY DOMAIN RESPONSE OF LTI SYSTEMSFREQUENCY DOMAIN RESPONSE OF LTI SYSTEMS
T
T
We know that any arbitrary sequence
x[n] can be represented as a weighted sum of
discrete impulses. Now the system response is
given by,
y[n]=T[x[n]]= T[
∑
∞
−∞=
−
k
knkx )()( δ ]
where x(k) denotes the kth
sample. The
response of DTLTI system to sequence x(k) δ[n-k]
will be x(k)h[n-k].i.e. T[x(k) δ[n-k]] = x(k) T[δ[n-
k]] = x(k) h[n-k].So response y[n] of DTLTI
system to x[n] is
y [n]= ∑
∞
−∞=
−
k
knhkx )()(
This is known as convolution sum and can
be represented as
y[n] = x[n]*h[n]
* is the Convolution operator
FREQUENCY RESPONSE:
y[n] can also be written as
∴y[n]= ∑
∞
−∞=
−
k
knxkh )()(
If x[n] is a complex exponential of the form x[n]
=ejωn
where n varies from -∞ to ∞
Then y[n] = )()(
khe
k
knj
∑
∞
−∞=
−ω
= )(. khee nj
k
kj ωω
∑
∞
−∞=
−
168 UR11EC098
=
jwn
k
kj
ekhe )(∑
∞
−∞=
− ω
y[n]=H(ejω
) ejωn
where H(ejω
)= )(khe
k
kj
∑
∞
−∞=
− ω
H(ejω
) is called the frequency response of DTLTI
system. It is a complex function
H(ejω
) =Hr(ejω
)+j Him(ejω
)
H(ejω
)= )( ωj
eH ejθ(ω)
)( ωj
eH is the magnitude response. )(ωθ is the
phase response.
LIBRARY FUNCTIONS:
• exp: Exponential.
exp (X) is the exponential of the elements of
X, e to the power X. For complex Z=X+i*Y,
exp (Z) = exp (X)*(COS(Y) +i*SIN(Y)).
• disp: Display array.
DISP (X) is called for the object X when the
semicolon is not used to terminate a
statement.
• Freqz: Compute the frequency
response of discrete-time filters,
[h,w] = freqz (hd) returns the frequency
response vector h and the corresponding
frequency vector w for the discrete-time
filter hd. When hd is a vector of discrete-
time filters, freqz returns the matrix h. Each
column of h corresponds to one filter in the
vector hd.
169 UR11EC098
• Angle: Phase angle
P = angle (Z) returns the phase angle, in
radians, for each element of complex array
Z.
• log10:
The log10 function operates element-by-
element on arrays. Its domain includes
complex numbers, which may lead to
unexpected results if used unintentionally
ALGORITHM/PROCEDURE:
1. Click on the MATLAB icon on the desktop
(or go to Start – All programs and click on
MATLAB) to get into the Command
Window
2. Type ‘edit’ in the MATLAB prompt ‘>>’
that appears in the Command window.
3. Write the program in the ‘Edit’ window and
save it in ‘M-file’.
4. Run the program.
5. Enter the input in the command window.
6. The result is displayed in the Command
window and the graphical output is
displayed in the Figure Window.
SOURCE CODE:
clc;
170 UR11EC098
clear all;
close all;
%Frequency Response
num=input('Enter num:');
denum=input('Enter denum:');
n=linspace(0,pi,1000);
h=freqz(num,denum,n);
mag=20*log(abs(h));
subplot(2,2,1),semilogx(n,mag);
xlabel('Frequency
index'),ylabel('Magnitude'),title('Magnitude
Response');
pha=angle(h);
subplot(2,2,2),semilogx(n,pha);
xlabel('Frequency
index'),ylabel('Phase'),title('Phase Response');
z=tf(num,denum,1)
COMMAND WINDOW:
OUTPUT :
171 UR11EC098
RESULT:
The frequency response (magnitude and
phase response) of the given system was found
using MATLAB.
172 UR11EC098
173 UR11EC098

Mais conteúdo relacionado

Mais procurados

digital signal-processing-lab-manual
digital signal-processing-lab-manualdigital signal-processing-lab-manual
digital signal-processing-lab-manualAhmed Alshomi
 
Pulse Modulation ppt
Pulse Modulation pptPulse Modulation ppt
Pulse Modulation pptsanjeev2419
 
Signal classification of signal
Signal classification of signalSignal classification of signal
Signal classification of signal001Abhishek1
 
Digital modulation techniques...
Digital modulation techniques...Digital modulation techniques...
Digital modulation techniques...Nidhi Baranwal
 
L 1 5 sampling quantizing encoding pcm
L 1 5 sampling quantizing encoding pcmL 1 5 sampling quantizing encoding pcm
L 1 5 sampling quantizing encoding pcmDEEPIKA KAMBOJ
 
1. elementary signals
1. elementary signals 1. elementary signals
1. elementary signals MdFazleRabbi18
 
Windowing techniques of fir filter design
Windowing techniques of fir filter designWindowing techniques of fir filter design
Windowing techniques of fir filter designRohan Nagpal
 
DSP_FOEHU - Lec 11 - IIR Filter Design
DSP_FOEHU - Lec 11 - IIR Filter DesignDSP_FOEHU - Lec 11 - IIR Filter Design
DSP_FOEHU - Lec 11 - IIR Filter DesignAmr E. Mohamed
 
Demodulation of AM wave
Demodulation of AM waveDemodulation of AM wave
Demodulation of AM waveLokesh Parihar
 
DSP_FOEHU - MATLAB 01 - Discrete Time Signals and Systems
DSP_FOEHU - MATLAB 01 - Discrete Time Signals and SystemsDSP_FOEHU - MATLAB 01 - Discrete Time Signals and Systems
DSP_FOEHU - MATLAB 01 - Discrete Time Signals and SystemsAmr E. Mohamed
 
Circular Convolution
Circular ConvolutionCircular Convolution
Circular ConvolutionSarang Joshi
 
DIGITAL SIGNAL PROCESSING
DIGITAL SIGNAL PROCESSINGDIGITAL SIGNAL PROCESSING
DIGITAL SIGNAL PROCESSINGSnehal Hedau
 
Introduction to Digital Signal Processing
Introduction to Digital Signal ProcessingIntroduction to Digital Signal Processing
Introduction to Digital Signal Processingop205
 
DSP_2018_FOEHU - Lec 04 - The z-Transform
DSP_2018_FOEHU - Lec 04 - The z-TransformDSP_2018_FOEHU - Lec 04 - The z-Transform
DSP_2018_FOEHU - Lec 04 - The z-TransformAmr E. Mohamed
 
Chapter2 - Linear Time-Invariant System
Chapter2 - Linear Time-Invariant SystemChapter2 - Linear Time-Invariant System
Chapter2 - Linear Time-Invariant SystemAttaporn Ninsuwan
 
DSP_2018_FOEHU - Lec 02 - Sampling of Continuous Time Signals
DSP_2018_FOEHU - Lec 02 - Sampling of Continuous Time SignalsDSP_2018_FOEHU - Lec 02 - Sampling of Continuous Time Signals
DSP_2018_FOEHU - Lec 02 - Sampling of Continuous Time SignalsAmr E. Mohamed
 

Mais procurados (20)

digital signal-processing-lab-manual
digital signal-processing-lab-manualdigital signal-processing-lab-manual
digital signal-processing-lab-manual
 
Pulse Modulation ppt
Pulse Modulation pptPulse Modulation ppt
Pulse Modulation ppt
 
DPCM
DPCMDPCM
DPCM
 
Signal classification of signal
Signal classification of signalSignal classification of signal
Signal classification of signal
 
Digital modulation techniques...
Digital modulation techniques...Digital modulation techniques...
Digital modulation techniques...
 
L 1 5 sampling quantizing encoding pcm
L 1 5 sampling quantizing encoding pcmL 1 5 sampling quantizing encoding pcm
L 1 5 sampling quantizing encoding pcm
 
1. elementary signals
1. elementary signals 1. elementary signals
1. elementary signals
 
Introduction to dsp
Introduction to dspIntroduction to dsp
Introduction to dsp
 
Windowing techniques of fir filter design
Windowing techniques of fir filter designWindowing techniques of fir filter design
Windowing techniques of fir filter design
 
DSP_FOEHU - Lec 11 - IIR Filter Design
DSP_FOEHU - Lec 11 - IIR Filter DesignDSP_FOEHU - Lec 11 - IIR Filter Design
DSP_FOEHU - Lec 11 - IIR Filter Design
 
Demodulation of AM wave
Demodulation of AM waveDemodulation of AM wave
Demodulation of AM wave
 
DSP_FOEHU - MATLAB 01 - Discrete Time Signals and Systems
DSP_FOEHU - MATLAB 01 - Discrete Time Signals and SystemsDSP_FOEHU - MATLAB 01 - Discrete Time Signals and Systems
DSP_FOEHU - MATLAB 01 - Discrete Time Signals and Systems
 
Circular Convolution
Circular ConvolutionCircular Convolution
Circular Convolution
 
DIGITAL SIGNAL PROCESSING
DIGITAL SIGNAL PROCESSINGDIGITAL SIGNAL PROCESSING
DIGITAL SIGNAL PROCESSING
 
Properties of dft
Properties of dftProperties of dft
Properties of dft
 
Signals & systems
Signals & systems Signals & systems
Signals & systems
 
Introduction to Digital Signal Processing
Introduction to Digital Signal ProcessingIntroduction to Digital Signal Processing
Introduction to Digital Signal Processing
 
DSP_2018_FOEHU - Lec 04 - The z-Transform
DSP_2018_FOEHU - Lec 04 - The z-TransformDSP_2018_FOEHU - Lec 04 - The z-Transform
DSP_2018_FOEHU - Lec 04 - The z-Transform
 
Chapter2 - Linear Time-Invariant System
Chapter2 - Linear Time-Invariant SystemChapter2 - Linear Time-Invariant System
Chapter2 - Linear Time-Invariant System
 
DSP_2018_FOEHU - Lec 02 - Sampling of Continuous Time Signals
DSP_2018_FOEHU - Lec 02 - Sampling of Continuous Time SignalsDSP_2018_FOEHU - Lec 02 - Sampling of Continuous Time Signals
DSP_2018_FOEHU - Lec 02 - Sampling of Continuous Time Signals
 

Semelhante a Digital Signal Processing Lab Manual ECE students

Basic simulation lab manual1
Basic simulation lab manual1Basic simulation lab manual1
Basic simulation lab manual1Janardhana Raju M
 
BS LAB Manual (1).pdf
BS LAB Manual  (1).pdfBS LAB Manual  (1).pdf
BS LAB Manual (1).pdfssuser476810
 
Digital Signal Processing Lab Manual
Digital Signal Processing Lab Manual Digital Signal Processing Lab Manual
Digital Signal Processing Lab Manual Amairullah Khan Lodhi
 
Signals And Systems Lab Manual, R18 Batch
Signals And Systems Lab Manual, R18 BatchSignals And Systems Lab Manual, R18 Batch
Signals And Systems Lab Manual, R18 BatchAmairullah Khan Lodhi
 
Digital Signal Processing and Control System under MATLAB Environment
Digital Signal Processing and Control System under MATLAB EnvironmentDigital Signal Processing and Control System under MATLAB Environment
Digital Signal Processing and Control System under MATLAB EnvironmentParamjeet Singh Jamwal
 
DSP_DiscSignals_LinearS_150417.pptx
DSP_DiscSignals_LinearS_150417.pptxDSP_DiscSignals_LinearS_150417.pptx
DSP_DiscSignals_LinearS_150417.pptxHamedNassar5
 
Matlab 2
Matlab 2Matlab 2
Matlab 2asguna
 
Computer aided design of communication systems / Simulation Communication Sys...
Computer aided design of communication systems / Simulation Communication Sys...Computer aided design of communication systems / Simulation Communication Sys...
Computer aided design of communication systems / Simulation Communication Sys...Makan Mohammadi
 
DSP Lab Manual (10ECL57) - VTU Syllabus (KSSEM)
DSP Lab Manual (10ECL57) - VTU Syllabus (KSSEM)DSP Lab Manual (10ECL57) - VTU Syllabus (KSSEM)
DSP Lab Manual (10ECL57) - VTU Syllabus (KSSEM)Ravikiran A
 
Digital Signal Processing
Digital Signal ProcessingDigital Signal Processing
Digital Signal ProcessingPRABHAHARAN429
 
Ec8352 signals and systems 2 marks with answers
Ec8352 signals and systems   2 marks with answersEc8352 signals and systems   2 marks with answers
Ec8352 signals and systems 2 marks with answersGayathri Krishnamoorthy
 
Ia iz matematike na engleskom jeziku
Ia iz matematike na engleskom jezikuIa iz matematike na engleskom jeziku
Ia iz matematike na engleskom jezikumaturskirad
 

Semelhante a Digital Signal Processing Lab Manual ECE students (20)

Dsp file
Dsp fileDsp file
Dsp file
 
Basic simulation lab manual1
Basic simulation lab manual1Basic simulation lab manual1
Basic simulation lab manual1
 
BS LAB Manual (1).pdf
BS LAB Manual  (1).pdfBS LAB Manual  (1).pdf
BS LAB Manual (1).pdf
 
Digital Signal Processing Lab Manual
Digital Signal Processing Lab Manual Digital Signal Processing Lab Manual
Digital Signal Processing Lab Manual
 
signal and system
signal and system signal and system
signal and system
 
Dsp Lab Record
Dsp Lab RecordDsp Lab Record
Dsp Lab Record
 
Signals And Systems Lab Manual, R18 Batch
Signals And Systems Lab Manual, R18 BatchSignals And Systems Lab Manual, R18 Batch
Signals And Systems Lab Manual, R18 Batch
 
Digital Signal Processing and Control System under MATLAB Environment
Digital Signal Processing and Control System under MATLAB EnvironmentDigital Signal Processing and Control System under MATLAB Environment
Digital Signal Processing and Control System under MATLAB Environment
 
DSP_DiscSignals_LinearS_150417.pptx
DSP_DiscSignals_LinearS_150417.pptxDSP_DiscSignals_LinearS_150417.pptx
DSP_DiscSignals_LinearS_150417.pptx
 
Matlab 2
Matlab 2Matlab 2
Matlab 2
 
Dsp manual
Dsp manualDsp manual
Dsp manual
 
Computer aided design of communication systems / Simulation Communication Sys...
Computer aided design of communication systems / Simulation Communication Sys...Computer aided design of communication systems / Simulation Communication Sys...
Computer aided design of communication systems / Simulation Communication Sys...
 
DSP Mat Lab
DSP Mat LabDSP Mat Lab
DSP Mat Lab
 
DSP Lab Manual (10ECL57) - VTU Syllabus (KSSEM)
DSP Lab Manual (10ECL57) - VTU Syllabus (KSSEM)DSP Lab Manual (10ECL57) - VTU Syllabus (KSSEM)
DSP Lab Manual (10ECL57) - VTU Syllabus (KSSEM)
 
IARE_DSP_PPT.pptx
IARE_DSP_PPT.pptxIARE_DSP_PPT.pptx
IARE_DSP_PPT.pptx
 
Digital Signal Processing
Digital Signal ProcessingDigital Signal Processing
Digital Signal Processing
 
Ec8352 signals and systems 2 marks with answers
Ec8352 signals and systems   2 marks with answersEc8352 signals and systems   2 marks with answers
Ec8352 signals and systems 2 marks with answers
 
Dsp manual print
Dsp manual printDsp manual print
Dsp manual print
 
Ia iz matematike na engleskom jeziku
Ia iz matematike na engleskom jezikuIa iz matematike na engleskom jeziku
Ia iz matematike na engleskom jeziku
 
505 260-266
505 260-266505 260-266
505 260-266
 

Último

Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 

Último (20)

Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 

Digital Signal Processing Lab Manual ECE students

  • 1. FLOWCHART: 1 UR11EC098 START ENTER THE SIGNAL PARAMETERS (AMPLITUDE, TIME AND FREQUENCY) Generate the waveform by using the appropriate library function PLOT THE WAVEFORMS STOP
  • 2. AIM: Write a program in MATLAB to generate the following waveforms (Discrete – Time signal and Continuous – Time signal) 1. Unit Impulse sequence, 2. Unit step sequence, 3. Unit Ramp sequence, 4. Sinusoidal sequence, 5. Exponential sequence, 6. Random sequence, 1. Pulse signal, 2. Unit step signal 3. Ramp signal 4. Sinusoidal signal, 5. Exponential signal, 6. R a n d o m s i g n a l APPARATUS REQUIRED: 2 UR11EC098 Ex. No :1 Date:09-12-13 Ex. No :1 Date:09-12-13 WAVEFORM GENERATIONWAVEFORM GENERATION
  • 3. Pentium 4 Processor, MATLAB software THEORY: Real signals can be quite complicated. The study of signals therefore starts with the analysis of basic and fundamental signals. For linear systems, a complicated signal and its behaviour can be studied by superposition of basic signals. Common basic signals are: Discrete – Time signals: • Unit impulse sequence. x n n n ( ) ( ) , = = =   δ 1 0 0 for , otherwise • Unit step sequence. x n u n n ( ) ( ) , = = ≥   1 0 0 for , otherwise • Unit ramp sequence. x n r n n n ( ) ( ) , = = ≥   for , otherwise 0 0 • Sinusoidal sequence. x n A n( ) sin( )= +ϖ φ . • Exponential sequence. x(n) = A an , where A and a are constant. Continuous – time signals: • Unit impulse signal. • Unit step signal. • Unit ramp signal. • Sinusoidal signal. . • Exponential signal. , where A and a are constant. 3 UR11EC098 x t r t t t ( ) ( ) , = = ≥   for , otherwise 0 0 x t A( ) sin ( )= +(ϖt Τ φ x t a t ( ) = A e at x t t t ( ) ( ) , = = =   δ 1 0 0 for , otherwise x u t t (t ) ( ) , = = ≥   1 0 0 for , otherwise
  • 4. LIBRARY FUNCTIONS: clc: CLC Clear command window. CLC clears the command window and homes the cursor. clear all: CLEAR Clear variables and functions from memory. CLEAR removes all variables from the workspace.CLEAR VARIABLES does the same thing. close all: CLOSE Close figure.CLOSE, by itself, closes the current figure window. CLOSE ALL closes all the open figure windows. exp: EXP Exponential. EXP(X) is the exponential of the elements of X, e to the X. input: INPUT Prompt for user input. R = INPUT('How many apples') gives the user the prompt in the text string and then waits for input from the keyboard. The input can be any MATLAB expression, which is evaluated,using the variables in the current workspace, and the result returned in R. If the user presses the return key without entering anything, INPUT returns an empty matrix. linspace: LINSPACE Linearly spaced vector. 4 UR11EC098
  • 5. LINSPACE(X1, X2) generates a row vector of 100 linearly equally spaced points between X1 and X2. rand: The rand function generates arrays of random numbers whose elements are uniformly distributed in the interval (0,1). ones: ONES(N) is an N-by-N matrix of ones. ONES(M,N) or ONES([M,N]) is an M-by-N matrix of ones. zeros: ZEROS(N) is an N-by-N matrix of Zeros. ZEROS(M,N) or ZEROS([M,N]) is an M- by-N matrix of zeros plot: PLOT Linear plot. PLOT(X,Y) plots vector Y versus vector X. If X or Y is a matrix, then the vector is plotted versus the rows or columns of the matrix, whichever line up. subplot: SUBPLOT Create axes in tiled positions. H = SUBPLOT(m,n,p), or SUBPLOT(mnp), breaks the Figure window into an m-by-n matrix of small axes, selects the p-th axes for the current plot, and returns the axis handle. The axes are counted along the top row of the Figure window, then the second row, etc. 5 UR11EC098
  • 6. stem: STEM Discrete sequence or "stem" plot. STEM(Y) plots the data sequence Y as stems from the x axis terminated with circles for the data value. STEM(X,Y) plots the data sequence Y at the values specified in X. title: TITLE Graph title. TITLE('text') adds text at the top of the current axis. xlabel: XLABEL X-axis label. XLABEL('text') adds text beside the X-axis on the current axis. ylabel: YLABEL Y-axis label. YLABEL('text') adds text beside the Y-axis on the current axis. ALGORITHM/PROCEDURE: 1. Start the program 2. Get the inputs for signal generation 3. Use the appropriate library function 4. Display the waveform Source code : %WAVE FORM GENERATION %CT SIGNAL %UNIT IMPULSE clc; clear all; 6 UR11EC098
  • 7. close all; t1=-3:1:3; x1=[0,0,0,1,0,0,0]; subplot(2,3,1); plot(t1,x1); xlabel('time'); ylabel('Amplitude'); title('Unit impulse signal'); %UNIT STEP SIGNAL t2=-5:1:25; x2=[zeros(1,5),ones(1,26)]; subplot(2,3,2); plot(t2,x2); xlabel('time'); ylabel('Amplitude'); title('Unit step signal'); %EXPONENTIAL SIGNAL a=input('Enter the value of a:'); t3=-10:1:20; x3=exp(-1*a*t3); subplot(2,3,3); plot(t3,x3); xlabel('time'); ylabel('Amplitude'); title('Exponential signal'); %UNIT RAMP SIGNAL t4=-10:1:20; x4=t4; subplot(2,3,4); plot(t4,x4); xlabel('time'); ylabel('Amplitude'); title('Unit ramp signal'); %SINUSOIDAL SIGNAL A=input('Enter the amplitude:'); f=input('Enter the frequency:'); t5=-10:1:20; x5=A*sin(2*pi*f*t5); subplot(2,3,5); 7 UR11EC098
  • 8. plot(t5,x5) xlabel('time'); ylabel('Amplitude'); title('Sinusoidal signal'); %RANDOM SIGNAL t6=-10:1:20; x6=rand(1,31); subplot(2,3,6); plot(t6,x6); xlabel('time'); ylabel('Amplitude'); title('Random signal'); %WAVE FORM GENERATION %DT SIGNAL %UNIT IMPULSE clc; clear all; close all; n1=-3:1:3; x1=[0,0,0,1,0,0,0]; subplot(2,3,1); stem(n1,x1); xlabel('time'); ylabel('Amplitude'); title('Unit impulse signal'); %UNIT STEP SIGNAL n2=-5:1:25; x2=[zeros(1,5),ones(1,26)]; subplot(2,3,2); stem(n2,x2); xlabel('time'); ylabel('Amplitude'); title('Unit step signal'); %EXPONENTIAL SIGNAL a=input('Enter the value of a:'); n3=-10:1:20; x3=power(a,n3); subplot(2,3,3); 8 UR11EC098
  • 9. stem(n3,x3); xlabel('time'); ylabel('Amplitude'); title('Exponential signal'); %UNIT RAMP SIGNAL n4=-10:1:20; x4=n4; subplot(2,3,4); stem(n4,x4); xlabel('time'); ylabel('Amplitude'); title('Unit ramp signal'); %SINUSOIDAL SIGNAL A=input('Enter the amplitude:'); f=input('Enter the frequency:'); n5=-10:1:20; x5=A*sin(2*pi*f*n5); subplot(2,3,5); stem(n5,x5); xlabel('time'); ylabel('Amplitude'); title('Sinusoidal signal'); %RANDOM SIGNAL n6=-10:1:20; x6=rand(1,31); subplot(2,3,6); stem(n6,x6); xlabel('time'); ylabel('Amplitude'); title('Random signal'); CONTINUOUS TIME: 9 UR11EC098
  • 10. DISCRETE TIME : OUTPUT WAVEFORM(CONTINUOUS TIME): 10 UR11EC098
  • 11. OUTPUT WAVEFORM (DISCRETE TIME): 11 UR11EC098
  • 13. The program to generate various waveforms is written, executed and the output is verified. FLOWCHART: 13 UR11EC098 START READ THE INPUT SEQUENCE PLOT THE WAVEFORMS STOP READ THE CONSANT FOR (SCALAR) AMPLITUDE AND TIME MANIPULATION READ THE (VECTOR) SEQUENCE FOR SIGNAL ADDTION AND MULTIPLICATION PERFORM OPERTAION ON THE D.T. SIGNAL
  • 14. AIM: Write a program in MATLAB to study the basic operations on the Discrete – time signals. (Operation on dependent variable (amplitude manipulation) and Operation on independent variable (time manipulation)). APPARATUS REQUIRED: Pentium 4 Processor, MATLAB software THEORY: Let x(n) be a sequence with finite length. 1. Amplitude manipulation • Amplitude scaling:y[n] =ax[n], where a is a constant. If a > 1, then y[n] is amplified sequence If a < 1, then y[n] is attenuated sequence If a = - 1, then y[n] is amplitude reversal sequence 14 UR11EC098 Ex. No :2 Date :21-12-13 Ex. No :2 Date :21-12-13 BASIC OPERATIONS ON D.T SIGNALSBASIC OPERATIONS ON D.T SIGNALS
  • 15. • Offset the signal: y[n] =a+x[n], where a is a constant • Two signals x1[n] and x2[n] can also be added and multiplied: By adding the values y1[n]= x1[n] + x2[n] at each corresponding sample and by multiplying the values y2[n]= x1[n] X x2[n] at each corresponding sample. 2. Time manipulation • Time scaling: y[n]=x[an], where a is a constant. • Time shifting: y[n]=x[n - τ], where τ is a constant. • Time reflection (folding):y[n]=x[-n] Arithmetic Operations * Matrix multiplication .* Array multiplication (element-wise) LIBRARY FUNCTIONS: date Current date as date string. S = date returns a string containing the date in dd-mmm-yyyy format tic & toc Start a stopwatch timer. The sequence of commands 15 UR11EC098
  • 16. TIC, operation, TOC prints the number of seconds required for the operation. Fprintf Write formatted data to file. The special formats n,r,t,b,f can be used to produce linefeed, carriage return, tab, backspace, and formfeed characters respectively. Use to produce a backslash character and %% to produce the percent character. ALGORITHM/PROCEDURE: 1. Start the program 2. Get the input for signal manipulation 3. Use the appropriate library function 4. Display the waveform Source code : clc; clear all; close all; %operations on the amplitude of signal x=input('Enter input sequence:'); a=input('Enter amplification factor:'); b=input('Enter attenuation factor:'); c=input('Enter amplitude reversal factor:'); y1=a*x; y2=b*x; 16 UR11EC098
  • 17. y3=c*x; n=length(x); subplot(2,2,1); stem(0:n-1,x); xlabel('time'); ylabel('amplitude'); title('Input signal'); subplot(2,2,2); stem(0:n-1,y1); xlabel('time'); ylabel('Amplitude'); title('Amplified signal'); subplot(2,2,3); stem(0:n-1,y2); xlabel('time'); ylabel('Amplitude'); title('Attenuated signal'); subplot(2,2,4); stem(0:n-1,y3); xlabel('time'); ylabel('Amplitude'); title('Amplitude reversal signal'); %scalar addition d=input('Input the scalar to be added:'); y4=d+x; figure(2); stem(0:n-1,y4); xlabel('time'); ylabel('Amplitude'); title('Scalar addition signal'); clc; clear all; close all; %Operations on the independent variable %Time shifting of the independent variable x=input('Enter the input sequence:'); n0=input('Enter the +ve shift:'); 17 UR11EC098
  • 18. n1=input('Enter the -ve shift:'); l=length(x); subplot(2,2,1); stem(0:l-1,x); xlabel('time'); ylabel('Amplitude'); title('Input signal'); i=n0:l+n0-1; j=n1:l+n1-1; subplot(2,2,2); stem(i,x); xlabel('time'); ylabel('Amplitude'); title('Positive shifted signal'); subplot(2,2,3); stem(j,x); xlabel('time'); ylabel('Amnplitude'); title('Negative shifted signal'); %Time reversal subplot(2,2,4); stem(-1*(0:l-1),x); xlabel('time'); ylabel('Amplitude'); title('Time reversal signal'); clc; clear all; close all; %Arithmetic operations on signals %Addition and multiplication of two signals x1=input('Enter the sequence of first signal:'); x2=input('Enter the sequence of second signal:'); l1=length(x1); l2=length(x2); subplot(2,2,1); 18 UR11EC098
  • 19. stem(0:l1-1,x1); xlabel('time'); ylabel('Amplitude'); title('Input sequence 1'); subplot(2,2,2); stem(0:l2-1,x2); xlabel('time'); ylabel('Amplitude'); title('Input sequence 2'); if l1>l2 l3=l1-l2; x2=[x2,zeros(1,l3)]; y1=x1+x2; subplot(2,2,3); stem(0:l1-1,y1); xlabel('time'); ylabel('Amplitude'); title('Addition of two signals'); y2=x1.*x2; subplot(2,2,4); stem(0:l1-1,y2); xlabel('time'); ylabel('Amplitude'); title('Multiplication of two signals'); end if l2>l1 l3=l2-l1; x1=[x1,zeros(1,l3)]; y1=x1+x2; subplot(2,2,3); stem(0:l2-1,y1); xlabel('time'); ylabel('Amplitude'); title('Addition of two signals'); y2=x1.*x2; subplot(2,2,4); stem(0:l2-1,y2); xlabel('time'); ylabel('Amplitude'); 19 UR11EC098
  • 20. title('Multiplication of two signals'); else y1=x1+x2; subplot(2,2,3); stem(0:l1-1,y1); xlabel('time'); ylabel('Amplitude'); title('Addition of two signals'); y2=x1.*x2; subplot(2,2,4); stem(0:l1-1,y2); xlabel('time'); ylabel('Amplitude'); title('Multiplication of two signals'); end operations on the amplitude of signal : Time shifting of the independent variable : 20 UR11EC098
  • 21. Addition and multiplication of two signals : OUTPUT (operations on the amplitude of signal ): 21 UR11EC098
  • 22. OUTPUT(Time shifting of the independent variable) : 22 UR11EC098
  • 23. OUTPUT(Addition and multiplication of two signals) : RESULT: 23 UR11EC098
  • 24. The program to perform various operations on discrete time signal is written, executed and the output is verified FLOWCHART: 24 UR11EC098 START READ THE INPUT SEQUENCE PLOT THE WAVEFORMS STOP READ THE CONSANT FOR (SCALAR) AMPLITUDE AND TIME MANIPULATION READ THE (VECTOR) SEQUENCE FOR SIGNAL ADDTION AND MULTIPLICATION PERFORM OPERTAION ON THE D.T. SIGNAL using the appropriate library function
  • 25. AIM: To check for linearity, Causality and stability of various systems given bellow: Linearity: System1 n.X(n), System2 An.X2 (n)+B System3: Log (X),sin(x),5X(n) …etc Causality: System1 U(-n) System2 X(n- 4)+U(n+5) Stability: System1 Z / (Z2 + 0.5 Z+1) APPARATUS REQUIRED: Pentium 4 Processor, MATLAB software THEORY: LINEARITY: The response of the system to a weighted sum of signals is equal to the corresponding weighted sum of the responses (outputs) of the system to each of the individual input signals. )]([)]([)]()([ 22112211 nxTanxTanxanxaT +=+ METHODS OF PROOF: Individual inputs are applied and the weighted sum of the outputs is taken. Then the 25 UR11EC098 Ex. No : 3 Date: 06-1-14 Ex. No : 3 Date: 06-1-14 PROPERTIES OF DISCRETE TIME SYSTEMPROPERTIES OF DISCRETE TIME SYSTEM
  • 26. weighted sum of signals input is applied to the system and the two outputs are checked to see if they are equal. CAUSALITY: A system is said to be causal, if the output of the system at any time n(y(n)) depends only on the present and past inputs and past outputs [x(n),x(n- 1)…….y(n-1),…..] But does not depend on future inputs [x (n+1),x(n+2),…..] y(n) = F[ x(n),x(n-1),x(n-2)….] F[ ] – Arbitrary function. METHODS OF PROOF: 1. If the difference equation is given, the arguments of the output y (n) are compared with the arguments (time instant) of the input signals. In the case of only present and past inputs, the system is causal. If future inputs are present then the system is non- causal. 2. If the impulse response is given, then it is checked whether all the values of h (n) for negative values of n are zero. (i.e.) if h(n)=0, for <0. If this is satisfied, then the system is causal. 26 UR11EC098
  • 27. STABILITY: An arbitrary relaxed system is said to be bounded input – bounded output (BIBO) stable, if and only if every bounded input produces a bounded output. METHODS OF PROOF: 1. If the impulse response is given, then the summation of responses for n ranging from -α to +α is taken and if the sum is finite, the system is said to be BIBO stable. 2. It the transfer function of the system is given, the poles of the transfer function is plotted. If all the poles lie within the unit circle, the system is stable. A single order pole on the boundary of unit circle makes the systems marginally stable. If there are multiple order poles on the boundary of unit circle, the system is unstable.If any pole is lying outside the unit circle, the system is unstable. LIBRARY FUNCTION: .^ Array power. Z = X.^Y denotes element-by-element powers. X and Y must have the same 27 UR11EC098
  • 28. dimensions unless one is a scalar. A scalar can operate into anything. C = POWER(A,B) is called for the syntax 'A .^ B' when A or B is an object. residuez Z-transform partial-fraction expansion. [R,P,K] = residuez(B,A) finds the residues, poles and direct terms of the partial-fraction expansion of B(z)/A(z), zplane Z-plane zero-pole plot. zplane(Z,P) plots the zeros Z and poles P (in column vectors) with the unit circle for reference. Each zero is represented with a 'o' and each pole with a 'x' on the plot. tf Creation of transfer functions or conversion to transfer function. SYS = tf(NUM,DEN,TS) creates a discrete- time transfer function with sample time TS (set TS=1 to get it in z). Z = tf('z',TS) specifies H(z) = z with sample time TS. syms Short-cut for constructing symbolic objects. 28 UR11EC098
  • 29. subs Symbolic substitution. subs(S,NEW) replaces the free symbolic variable in S with NEW. ALGORITHM/PROCEDURE: 1. Click on the MATLAB icon on the desktop (or go to start – all programs and click on MATLAB) to get into the Command Window 2. Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command window. 3. Write the program in the ‘Edit’ window and save it in ‘M-file’ 4. Run the program 5. Enter the input in the command window 6. The result is displayed in the Command window and the graphical output is displayed in the Figure Window Source code :1 clc; clear all; close all; %Properties of DT Systems(Linearity) %y(n)=[x(n)]^2+B; x1=input('Enter first input sequence:'); 29 UR11EC098
  • 30. n=length(x1); x2=input('Enter second input sequence:'); a=input('Enter scaling constant(a):'); b=input('Enter scaling constant(b):'); B=input('Enter scaling constant(B):'); y1=power(x1,2)+B; y2=power(x2,2)+B; rhs=a*y1+b*y2; x3=a*x1+b*x2; lhs=power(x3,2)+B; subplot(2,2,1); stem(0:n-1,x1); xlabel('Time'); ylabel('Amplitude'); title('First input sequence'); subplot(2,2,2); stem(0:n-1,x2); xlabel('Time'); ylabel('Amplitude'); title('Second input sequence'); subplot(2,2,3); stem(0:n-1,lhs); xlabel('Time'); ylabel('Amplitude'); title('LHS'); subplot(2,2,4); stem(0:n-1,rhs); xlabel('Time'); ylabel('Amplitude'); title('RHS'); if(lhs==rhs) display('system is linear'); else display('system is non-linear'); end; 30 UR11EC098
  • 31. Source code :2 clc; clear all; close all; %Properties of DT Systems(Linearity) %y(n)=x(n); x1=input('Enter first input sequence:'); x2=input('Enter second input sequence:'); a=input('Enter scaling constant(a):'); b=input('Enter scaling constant(b):'); subplot(2,2,1); stem(x1); xlabel('time'); ylabel('Amplitude'); title('First signal'); subplot(2,2,2); stem(x2); xlabel('time'); ylabel('Amplitude'); title('Second signal'); y1=x1; y2=x2; rhs=a*y1+b*y2; x3=a*x1+b*x2; lhs=x3; if(lhs==rhs) display('system is linear'); else display('system is non-linear'); end; subplot(2,2,3); stem(lhs); xlabel('time'); ylabel('Amplitude'); 31 UR11EC098
  • 32. title('L.H.S'); subplot(2,2,4); stem(rhs); xlabel('time'); ylabel('Amplitude'); title('R.H.S'); Source code :3 clc; clear all; close all; %Properties of DT Systems(Time Invariance) %y(n)=x(n); x1=input('Enter input sequence x1:'); n0=input('Enter shift:'); x2=[zeros(1,n0),x1]; y1=x1; y2=x2; y3=[zeros(1,n0),y1]; if(y2==y3) display('system is time invariant'); else display('system is time variant'); end; subplot(2,2,1); stem(x1); xlabel('time'); ylabel('Amplitude'); title('Input signal'); subplot(2,2,2); stem(x2); xlabel('time'); ylabel('Amplitude'); title('Signal after shift'); subplot(2,2,3); stem(y2); 32 UR11EC098
  • 33. xlabel('time'); ylabel('Amplitude'); title('L.H.S'); subplot(2,2,4); stem(y3); xlabel('time'); ylabel('Amplitude'); title('R.H.S'); Source code :4 clc; clear all; close all; %Properties of DT Systems(Time Invariance) %y(n)=n*[x(n)]; x1=input('Enter input sequence x1:'); n1=length(x1); for n=1:n1 y1(n1)=n.*x1(n); end; n0=input('Enter shift:'); x2=[zeros(1,n0),x1]; for n2=1:n1+n0 y2(n2)=n2.*x2(n2); end; y3=[zeros(1,n0),y1]; if(y2==y3) display('system is time invariant'); else display('system is time variant'); end; subplot(2,2,1); stem(x1); xlabel('time'); ylabel('Amplitude'); 33 UR11EC098
  • 34. title('Input signal'); subplot(2,2,2); stem(x2); xlabel('time'); ylabel('Amplitude'); title('Signal after shift'); subplot(2,2,3); stem(y2); xlabel('time'); ylabel('Amplitude'); title('L.H.S'); subplot(2,2,4); stem(y3); xlabel('time'); ylabel('Amplitude'); title('R.H.S'); Source code :5 clc; clear all; close all; %Properties of DT Systems(Causality) %y(n)=x(-n); x1=input('Enter input sequence x1:'); n1=input('Enter lower limit n1:'); n2=input('Enter lower limit n2:'); flag=0; for n=n1:n2 arg=-n; if arg>n; flag=1; end; end; if(flag==1) display('system is causal'); else 34 UR11EC098
  • 35. display('system is non-causal'); end; Source code :6 disp('stability'); nr=input('input the numerator coefficients:'); dr=input('input the denominator coefficients:'); z=tf(nr,dr,1); [r,p,k]=residuez(nr,dr); figure zplane(nr,dr); if abs(p)<1 disp('the system is stable'); else disp('the system is unstable'); end; Non-Linear System :1 Output : 35 UR11EC098
  • 36. Linear System :2 Output : 36 UR11EC098
  • 37. Time invariant system :3 Output : 37 UR11EC098
  • 38. Time variant system : 4 Output : 38 UR11EC098
  • 39. Non-Causal system :5 Unstable system :6 39 UR11EC098
  • 41. RESULT: The properties of Discrete – Time system is verified using MATLAB FLOWCHART: 41 UR11EC098
  • 42. 42 UR11EC098 START ENTER THE SIGNAL PARAMETERS (AMPLITUDE, TIME AND FREQUENCY) FIND THE SPectrum of all the signals PLOT THE WAVEFORMS STOP PERFORM THE SAMPLING RATE CONVERSION ON THE INPUT BY using upsample, DOWNSAMPLE and resample PERFORM interpolation and decimation ON THE INPUT
  • 43. AIM: Write a MATLAB Script to perform sampling rate conversion for any given arbitrary sequence (D.T) or signal (C.T) by interpolation, decimation, upsampling, downsampling and resampling (i.e. fractional value) . APPARATUS REQUIRED: PC, MATLAB software THEORY: SAMPLING PROCESS: It is a process by which a continuous time signal is converted into discrete time signal. X[n] is the discrete time signal obtained by taking samples of the analog signal x(t) every T seconds, where T is the sampling period. X[n] = x (t) x p (t) Where p(t) is impulse train; T – period of the train SAMPLING THEOREM: It states that the band limited signal x(t) having no frequency components above Fmax Hz is specified by the samples that are taken at a uniform rate greater than 2 Fmax Hz (Nyquist rate), 43 UR11EC098 Ex. No : 4 Date: 13-1-14 Ex. No : 4 Date: 13-1-14 SAMPLING RATE CONVERSIONSAMPLING RATE CONVERSION
  • 44. or the frequency equal to twice the highest frequency of x(t). Fs ≥ 2 Fmax SAMPLING RATE CONVERSION: Sampling rate conversion is employed to generate a new sequence with a sampling rate higher or lower than that of a given sequence. If x[n] is a sequence with a sampling rate of F Hz and it is used to generate another sequence y[n] with desired sampling rate F’ Hz, then the sampling rate alteration is given by, F’/F = R If R > 1, the process is called interpolation and results in a sequence with higher sampling rate. If R< 1, the process is called decimation and results in a sequence with lower sampling rate. DOWNSAMPLE AND DECIMATION: Down sampling operation by an integer factor M (M>1) on a sequence x[n] consists of keeping every Mth sample of x[n] and removing M- 1 in between samples, generating an output sequence y[n] according to the relation y [n] = x[nM] y [n] – sampling rate is 1/M that of x[n] If we reduce the sampling rate, the resulting signal will be an aliased version of x[n]. To avoid 44 UR11EC098
  • 45. aliasing, the bandwidth of x[n] must be reduced to Fmax =Fx/2 π or ωmax = π /M. The input sequence is passed through LPF or an antialiasing filter before down sampling. x [n] - y[n] UPSAMPLE AND INTERPOLATION: Upsampling by an integer factor L (L > 1) on a sequence x[n] will insert (L–1) equidistant samples between an output sequence y[n] according to the relation x[n/L], n = 0, ±1, ±2 …. y[n] = 0, otherwise The sampling rate of y[n] is L times that of x[n]. The unwanted images in the spectra of sampled signal must be removed by a LPF called anti- imaging filter. The input sequence is passed through an anti-imaging filter after up sampling. x[n] y[n] SAMPLING RATE CONVERSION BY A RATIONAL FACTOR I/O: 45 UR11EC098 ANTIALIASING FILTER H (Z) ↓M ↑L ANTI IMAGING FILTER H (Z)
  • 46. We achieve this conversion, by first performing interpolation by the factor I and then decimating the output of interpolator by the factor D, interpolation has to be performed before decimation to obtain the new rational sampling rate. x[n] y[n] LIBRARY FUNCTIONS: • resample: Changes sampling rate by any rational factor. y = resample (x,p,q) resamples the sequence in vector x at p/q times the original sampling rate, using a polyphase filter implementation. p and q must be positive integers. The length of y is equal to ceil (length(x)*p/q). • interp: Increases sampling rate by an integer factor (interpolation) y = interp (x,r) increases the sampling rate of x by a factor of r. The interpolated vector y is r times longer than the original input x. ‘interp’ performs low pass interpolation by inserting zeros into the original sequence and then applying a special low pass filter. 46 UR11EC098 UPSAMPLER ↑ ANTI IMAGING FILTER ANTI ALIASING FILTER DOWN SAMPLER ↓
  • 47. • upsample: Increases the sampling rate of the input signal y = upsample(x,n) increases the sampling rate of x by inserting n-1 zeros between samples. The upsampled y has length(x)*n samples • decimate: Decreases the sampling rate for a sequence (decimation). y = decimate (x, r) reduces the sample rate of x by a factor r. The decimated vector y is r times shorter in length than the input vector x. By default, decimate employs an eighth-order low pass Chebyshev Type I filter. It filters the input sequence in both the forward and reverse directions to remove all phase distortion, effectively doubling the filter order. • downsample: Decreases the sampling rate of the input signal y = downsample(x,n) decreases the sampling rate of x by keeping every nth sample starting with the first sample. The downsampled y has length(x)/n samples ALGORITHM/PROCEDURE: 1. Generate a sinusoidal waveform 47 UR11EC098
  • 48. 2. Using the appropriate library function for interpolation ,decimation ,upsampling , downsampling and resampling, perform sampling rate conversion for the sinusoidal waveform 3. Find the spectrum of all the signals and compare them in frequency domain. 4. Display the resultant waveforms Source code : clc; clear all; close all; %continuous sinusoidal signal a=input('Enter the amplitude:'); f=input('Enter the Timeperiod:'); t=-10:1:20; x=a*sin(2*pi*f*t); subplot(2,3,1); plot(t,x); xlabel('time'); ylabel('Amplitude'); title('Sinusoidal signal'); %decimating the signal d=input('Enter the value by which the signal is to be decimated:'); y1=decimate(x,d); subplot(2,3,2); stem(y1); xlabel('time'); 48 UR11EC098
  • 49. ylabel('Amplitude'); title('Decimated signal'); %interpolating the signal i=input('Enter the value by which the signal is to be interpolated:'); y2=interp(x,i); subplot(2,3,3); stem(y2); xlabel('time'); ylabel('Amplitude'); title('Interpolated signal'); %resampling the signal y3=resample(x,3,2); subplot(2,3,4); stem(y3); xlabel('time'); ylabel('Amplitude'); title('Resampled signal'); %downsampling the signal y4=downsample(x,2); subplot(2,3,5); stem(y4); xlabel('time'); ylabel('Amplitude'); title('Downsampled signal'); %upsampling the signal y5=upsample(x,3); subplot(2,3,6); stem(y5); xlabel('time'); ylabel('Amplitude'); title('Upsampled signal'); 49 UR11EC098
  • 52. RESULT: The program written using library functions and the sampling rate conversion process is studied. 52 UR11EC098
  • 53. FLOWCHART: 53 UR11EC098 START ENTER THE INPUT SEQUENCE x[n] & SYSTEM RESPONSE h[n] PERFORM LINEAR AND CIRCULAR CONVOLUTION IN TIME DOMAIN PLOT THE WAVEFORMS AND ERROR STOP
  • 54. AIM: Write a MATLAB Script to perform discrete convolution (Linear and Circular) for the given two sequences and also prove by manual calculation. APPARATUS REQUIRED: PC, MATLAB software THEORY: LINEAR CONVOLUTION: The response y[n] of a LTI system for any arbitrary input x[n] is given by convolution of impulse response h[n] of the system and the arbitrary input x[n]. y[n] = x[n]*h[n] = ∑ ∞ −∞= − k knhkx ][][ or ∑ ∞ −∞= − k knxkh ][][ If the input x[n] has N1 samples and impulse response h[n] has N2 samples then the output sequence y[n] will be a finite duration sequence consisting of (N1 + N2 - 1) samples. The 54 UR11EC098 Ex. No : 5 Date : 20-1-14 Ex. No : 5 Date : 20-1-14 DISCRETE CONVOLUTIONDISCRETE CONVOLUTION
  • 55. convolution results in a non periodic sequence called Aperiodic convolution. STEPS IN LINEAR CONVOLUTION: The process of computing convolution between x[k] and h[k] involves four steps. 1. Folding: Fold h[k] about k=0 to obtain h[-k] 2. Shifting: Shift h[-k] by ‘n0’to right if ‘n0’ is positive and shift h[-k] by ‘n0’ to the left if ‘n0’ is negative. Obtain h[n0-k] 3. Multiplication : Multiply x[k] by h[n0-k] to obtain the product sequence yn0 [k] = x[k] h [n0 –k] 4. Summation: Find the sum of all the values of the product sequence to obtain values of output at n = n0 Repeat steps 2 to 4 for all possible time shifts ‘n0’ in the range - ∞ <n< ∞ CIRCULAR CONVOLUTION The convolution of two periodic sequences with period N is called circular convolution of two signals x1[n] and x2[n] denoted by y[n] = x1[n] * x2[n] = ∑ − = 1 0 1x N k [(n-k) mod N] x2 (k) or ∑ − = 1 0 1 )(x N k k x2 [(n-k) mod N] 55 UR11EC098
  • 56. where x1[(n-k) mod N] is the reflected and circularly translated version of x1[n]. x1[n] * x2[n] = IDFTN { DFTN (x1[n] ) . DFTN (x2[n])} It can be performed only if both the sequences consist of equal number of samples. If the sequences are different in length then convert the smaller size sequence to that of larger size by appending zeros METHODS FOR CIRCULAR CONVOLUTION: Matrix Multiplication Method and Concentric Circle Method LIBRARY FUNCTION: • conv: Convolution and polynomial multiplication. C = conv (A, B) convolves vectors A and B. The resulting vector C’s length is given by length(A)+length(B)-1. If Aand B are vectors of polynomial coefficients, convolving them is equivalent to multiplying the two polynomials in frequency domain. • length: Length of vector. 56 UR11EC098
  • 57. length(X) returns the length of vector X. It is equivalent to size(X) for non empty arrays and 0 for empty ones. • fft: Discrete Fourier transform. fft(x) is the Discrete Fourier transform (DFT) of vector x. For matrices, the ‘fft’ operation is applied to each column. For N- D arrays, the ‘fft’ operation operates on the first non-single dimension. fft(x,N) is the N- point FFT, padded with zeros if x has less than N points and truncated if it has more. • ifft: Inverse Discrete Fourier transform. ifft(X) is the Inverse Discrete Fourier transform of X. ifft(X,N) is the N-point Inverse Discrete Fourier transform of X. ALGORITHM/PROCEDURE: LINEAR CONVOLUTION: 1. Enter the sequences (Input x[n] and the Impulse response h[n]) 2. Perform the linear convolution between x[k] and h[k] and obtain y[n]. 3. Find the FFT of x[n] & h[n].Obtain X and H 57 UR11EC098
  • 58. 4. Multiply X and H to obtain Y 5. Find the IFFT of Y to obtain y’[n] 6. Compute error in time domain e=y[n]-y’[n] 7. Plot the Results CIRCULAR CONVOLUTION 1. Enter the sequences (input x[n] and the impulse response h[n]) 2. Make the length of the sequences equal by padding zeros to the smaller length sequence. 3. Perform the circular convolution between x[k] and h[k]and obtain y[n]. 4. Find the FFT of x[n] & h[n].Obtain X and H 5. Multiply X and H to obtain Y 6. Find the IFFT of Y to obtain y’[n] 7. Compute error in time domain e=y[n]-y’[n] 8. Plot the Results SOURCE CODE : 1 clc; clear all; close all; %Program to perform Linear Convolution x1=input('Enter the first sequence to be convoluted:'); subplot(3,1,1); stem(x1); xlabel('Time'); ylabel('Amplitude'); 58 UR11EC098
  • 59. title('First sequence'); x2=input('Enter the second sequence to be convoluted:'); subplot(3,1,2); stem(x2); xlabel('Time'); ylabel('Amplitude'); title('Second sequence'); f=conv(x1,x2); disp('The Linear convoluted sequence is'); disp(f); subplot(3,1,3); stem(f); xlabel('Time'); ylabel('Amplitude'); title('Linear Convoluted sequence'); Command window : OUTPUT : 59 UR11EC098
  • 60. SOURCE CODE :2 clc; clear all; close all; %Program to perform Circular Convolution x1=input('Enter the first sequence to be convoluted:'); subplot(3,1,1); l1=length(x1); stem(x1); xlabel('Time'); ylabel('Amplitude'); title('First sequence'); x2=input('Enter the second sequence to be convoluted:'); subplot(3,1,2); l2=length(x2); stem(x2); 60 UR11EC098
  • 61. xlabel('Time'); ylabel('Amplitude'); title('Second sequence'); if l1>l2 l3=l1-l2; x2=[x2,zeros(1,l3)]; elseif l2>l1 l3=l2-l1; x1=[x1,zeros(1,l3)]; end f=cconv(x1,x2); disp('The Circular convoluted sequence is'); disp(f); subplot(3,1,3); stem(f); xlabel('Time'); ylabel('Amplitude'); title('Circular Convoluted sequence'); Command window : OUTPUT : 61 UR11EC098
  • 62. SOURCE CODE :3 clc; clear all; close all; %Program to perform Linear Convolution using Circular Convolution x1=input('Enter the first sequence to be convoluted:'); subplot(3,1,1); l1=length(x1); stem(x1); xlabel('Time'); ylabel('Amplitude'); title('First sequence'); 62 UR11EC098
  • 63. x2=input('Enter the second sequence to be convoluted:'); subplot(3,1,2); l2=length(x2); stem(x2); xlabel('Time'); ylabel('Amplitude'); title('Second sequence'); if l1>l2 l3=l1-l2; x2=[x2,zeros(1,l3)]; elseif l2>l1 l3=l2-l1; x1=[x1,zeros(1,l3)]; end n=l1+l2-1; f=cconv(x1,x2,n); disp('The convoluted sequence is'); disp(f); subplot(3,1,3); stem(f); xlabel('Time'); ylabel('Amplitude'); title('Convoluted sequence'); Command window : 63 UR11EC098
  • 65. clc; clear all; close all; %Program to perform Linear Convolution x=input('Enter the first input sequence:'); l1=length(x); subplot(3,2,1); stem(x); xlabel('Time index n---->'); ylabel('Amplitude'); title('input sequence'); h=input('Enter the system response sequence:'); l2=length(h); subplot(3,2,2); stem(h); xlabel('Time index n---->'); ylabel('Amplitude'); title('system response sequence'); if l1>l2 l3=l1-l2; h=[h,zeros(1,l3)]; elseif l2>l1 l3=l2-l1; x=[x,zeros(1,l3)]; end y=conv(x,h); disp('The time domain convoluted sequence is:'); disp(y); subplot(3,2,3); stem(y); xlabel('Time index n---->'); ylabel('Amplitude'); title('convoluted output sequence'); 65 UR11EC098
  • 66. X=fft(x,length(y)); H=fft(h,length(y)); Y=X.*H; disp('The frequency domain multiplied sequence is:'); disp(Y); subplot(3,2,4); stem(Y); xlabel('Time index n---->'); ylabel('Amplitude'); title('frequency domain multiplied response'); y1=ifft(Y,length(Y)); disp('The inverse fourier transformed sequence is:'); disp(y1); subplot(3,2,5); stem(y1); xlabel('Time index n---->'); ylabel('Amplitude'); title('output after inverse fourier transform'); e=y-y1; disp('The Error sequence:') disp(abs(e)); subplot(3,2,6); stem(abs(e)); xlabel('Time index n---->'); ylabel('Amplitude'); title('error sequence'); 66 UR11EC098
  • 67. Command window : OUTPUT : 67 UR11EC098
  • 68. SOURCE CODE :5 clc; clear all; close all; %PROGRAM FOR CIRCULAR CONVOLUTION USING DISCRETE CONVOLUTION EXPRESSION x=input('Enter the first sequence:'); n1=length(x); h=input('Enter the second sequence:'); n2=length(h); n=0:1:n1-1; subplot(3,1,1); stem(n,x); xlabel('Time'); ylabel('Amplitude'); title('First sequence Response x(n)'); n=0:1:n2-1; subplot(3,1,2); stem(n,h); 68 UR11EC098
  • 69. xlabel('Time'); ylabel('Amplitude'); title('Second sequence Response h(n)'); n=n1+n2-1; if n1>n2 n3=n1-n2; h=[h,zeros(1,n3)]; elseif n2>n1 n3=n2-n1; x=[x,zeros(1,n3)]; end x=[x,zeros(1,n-n1)]; h=[h,zeros(1,n-n2)]; for n=1:n y(n)=0; for i=1:n j=n-i+1; if(j<=0) j=n+j; end y(n)=y(n)+x(i)*h(j); end end disp('Circular Convolution of x&h is'); disp(y); subplot(3,1,3); stem(y); xlabel('Time'); ylabel('Amplitude'); title('Circular Convoluted sequence Response'); Command window : 69 UR11EC098
  • 71. RESULT: The linear and circular convolutions are performed by using MATLAB script and the program results are verified by manual calculation. FLOWCHART: 71 UR11EC098
  • 72. 72 UR11EC098 START ENTER THE INPUT SEQUENCE PERFORM THE DFT USING IN-builT FFT AND USING DIRECT FORMULA ON THE GIVEN INPUT SEQUENCE PLOT THE WAVEFORMS AND ERROR STOP
  • 73. AIM: Write a MATLAB program to perform the Discrete Fourier Transform for the given sequences. . APPARATUS REQUIRED: PC, MATLAB software THEORY: DISCRETE FOURIER TRANSFORM Fourier analysis is extremely useful for data analysis, as it breaks down a signal into constituent sinusoids of different frequencies. For sampled vector data Fourier analysis is performed using the Discrete Fourier Transform (DFT). The Discrete Fourier transform computes the values of the Z-transform for evenly spaced points around the circle for a given sequence. If the sequence to be represented is of finite duration i.e. it has only a finite number of non-zero values, the transform used is Discrete Fourier transform. 73 UR11EC098 Ex. No : 6 Date : 27-1-14 Ex. No : 6 Date : 27-1-14 DISCRETE FOURIER TRANSFORMDISCRETE FOURIER TRANSFORM
  • 74. It finds its application in Digital Signal processing including Linear filtering, Correlation analysis and Spectrum analysis. Consider a complex series x [n] with N samples of the form Where x is a complex number Further, assume that the series outside the range 0, N-1 is extended N-periodic, that is, xk = xk+N for all k. The FT of this series is denoted as X (k) and has N samples. The forward transform is defined as ∑ − = − −== 1 0 2 1...0,)( 1 X(k) N n Nknj Nkfornx N e π The inverse transform is defined as Although the functions here are described as complex series, setting the imaginary part to 0 can represent real valued series. In general, the transform into the frequency domain will be a complex valued function, that is, with magnitude and phase. 74 UR11EC098
  • 75. LIBRARY FUNCTIONS: • exp: Exponential Function. exp (X) is the exponential of the elements of X, e to the power X. For complex Z=X+i*Y, exp (Z) = exp(X)*(COS(Y) +i*SIN(Y)). • disp: Display array. disp (X) is called for the object X when the semicolon is not used to terminate a statement. • max: Maximum elements of an array C = max (A, B) returns an array of the same size as A and B with the largest elements taken from A or B. • fft: Discrete Fourier transform. fft(x) is the discrete Fourier transform (DFT) of vector x. For the matrices, the FFT operation is applied to each column. For N- Dimensional arrays, the FFT operation operates on the first non-singleton dimension. ALGORITHM/PROCEDURE: 1. Click on the MATLAB icon on the desktop (or go to Start - All Programs and click on MATLAB) to get into the Command Window 75 UR11EC098
  • 76. 2. Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command window. 3. Write the program in the ‘Edit’ window and save it as ‘m-file’ 4. Run the program 5. Enter the input in the command window 6. The result is displayed in the Command window and the graphical output is displayed in the Figure Window Source Code : clc; clear all; close all; %Get the sequence from user disp('The sequence from the user:'); xn=input('Enter the input sequence x(n):'); % To find the length of the sequence N=length(xn); %To initilise an array of same size as that of input sequence Xk=zeros(1,N); iXk=zeros(1,N); %code block to find the DFT of the sequence for k=0:N-1 for n=0:N-1 Xk(k+1)=Xk(k+1)+(xn(n+1)*exp((- i)*2*pi*k*n/N)); end end 76 UR11EC098
  • 77. %code block to plot the input sequence t=0:N-1; subplot(3,2,1); stem(t,xn); ylabel ('Amplitude'); xlabel ('Time Index'); title ('Input Sequence'); %code block to plot the X(k) disp('The discrete fourier transform of x(n):'); disp(Xk); t=0:N-1; subplot(3,2,2); stem(t,Xk); ylabel ('Amplitude'); xlabel ('Time Index'); title ('X(k)'); % To find the magnitudes of individual DFT points magnitude=abs(Xk); %code block to plot the magnitude response disp('The magnitude response of X(k):'); disp(magnitude); t=0:N-1; subplot(3,2,3); stem(t,magnitude); ylabel ('Amplitude'); xlabel ('K'); title ('Magnitude Response'); %To find the phases of individual DFT points phase=angle(Xk); %code block to plot the phase response disp('The phase response of X(k):'); disp(phase); 77 UR11EC098
  • 78. t=0:N-1; subplot(3,2,4); stem(t,phase); ylabel ('Phase'); xlabel ('K'); title ('Phase Response'); % Code block to find the IDFT of the sequence for n=0:N-1 for k=0:N-1 iXk(n+1)=iXk(n+1)+ (Xk(k+1)*exp(i*2*pi*k*n/N)); end end iXk=iXk./N; %code block to plot the output sequence t=0:N-1; subplot(3,2,5); stem(t,xn); ylabel ('Amplitude'); xlabel ('Time Index'); title ('IDFT sequence'); %code block to plot the FFT of input sequence using inbuilt function x2=fft(xn); subplot(3,2,6); stem(t,x2); ylabel ('Amplitude'); xlabel ('Time Index'); title ('FFT of input sequence'); Command Window : 78 UR11EC098
  • 80. RESULT: The program for DFT calculation was performed with library functions and without library functions. The results were verified by manual calculation. 80 UR11EC098
  • 81. FLOWCHART: 81 UR11EC098 START ENTER THE INPUT SEQUENCE IN TIME DOMAIN OR FREQUENCY DOMAIN PERFORM DIT/DIF-FFT FOR TIME SAMPLES or PERFORM IDIT/IDIT-FFT FOR FREQuency SAMPLES PLOT THE WAVEFORMS STOP
  • 82. AIM: Write a MATLAB Script to compute Discrete Fourier Transform and Inverse Discrete Fourier Transform of the given sequence using FFT algorithms (DIT-FFT & DIF-FFT) . APPARATUS REQUIRED: PC, MATLAB software THEORY: DFT is a powerful tool for performing frequency analysis of discrete time signal and it is described as a frequency domain representation of a DT sequence. The DFT of a finite duration sequence x[n] is given by X (k) = ∑ − = − 1 0 2 N n πnk/Nj x(n)e k=0, 1….N-1 which may conveniently be written in the form X (k) = ∑ − = 1 0 )( N n nk Nwnx k=0, 1….N-1 82 UR11EC098 Ex. No :7 Date :3-2-14 Ex. No :7 Date :3-2-14 FAST FOURIER TRANSFORM ALGORITHMSFAST FOURIER TRANSFORM ALGORITHMS
  • 83. where WN=e-j2π/N which is known as Twiddle or Phase factor. COMPUTATION OF DFT: To compute DFT, it requires N2 multiplication and (N-1) N complex addition. Direct computation of DFT is basically inefficient precisely because it does not exploit the symmetry and periodicity properties of phase factor WN. FAST FOURIER TRANSFORM (FFT): FFT is a method of having computationally efficient algorithms for the execution of DFT, under the approach of Divide and Conquer. The number of computations can be reduced in N point DFT for complex multiplications to N/2log2N and for complex addition to N/2log2N. Types of FFT are, (i) Decimation In Time (DIT) (ii)Decimation In Frequency (DIF) IDFT USING FFT ALGORITHMS: The inverse DFT of an N point sequence X (k), where k=0,1,2…N-1 is defined as , x [n] = ∑ − = − 1 0 )(X 1 N n nk NWk N 83 UR11EC098
  • 84. where, wN=e-j2π/N . Taking conjugate and multiplying by N, we get, N x*[n] = nk N N k Wk)(X 1 0 * ∑ − = The right hand side of the equation is the DFT of the sequence X*(k). Now x[n] can be found by taking the complex conjugate of the DFT and dividing by N to give, x [n]= * 1 0 * ])(X[ 1 nk N N k Wk N ∑ − = RADIX-2 DECIMATION IN TIME FFT: The idea is to successively split the N- point time domain sequence into smaller sub sequence. Initially the N-point sequence is split into xe[n] and xo[n], which have the even and odd indexed samples of x[n] respectively. The N/2 point DFT’s of these two sequences are evaluated and combined to give N-point DFT. Similarly N/2 point sequences are represented as a combination of two N/4 point DFT’s. This process is continued, until we are left with 2 point DFT. RADIX-2 DECIMATION IN FREQUENCY FFT: The output sequence X(k) is divided into smaller sequence.. Initially x[n] is divided 84 UR11EC098
  • 85. into two sequences x1[n], x2[n] consisting of the first and second N/2 samples of x[n] respectively. Then we find the N/2 point sequences f[n] and g[n] as f[n]= x1[n]+x2[n], g[n]=( x1[n]-x2[n] )wN k The N/2 point DFT of the 2 sequences gives even and odd numbered output samples. The above procedure can be used to express each N/2 point DFT as a combination of two N/4 point DFTs. This process is continued until we are left with 2 point DFT. LIBRARY FUNCTION: • fft: Discrete Fourier transform. fft(x) is the discrete Fourier transform (DFT) of vector x. For matrices, the FFT operation is applied to each column. For N-Dimensional arrays, the FFT operation operates on the first non-singleton dimension. • ditfft: Decimation in time (DIT)fft ditfft(x) is the discrete Fourier transform (DFT) of vector x in time domain decimation 85 UR11EC098
  • 86. • diffft: Decimation in frequency (DIF)fft diffft(x) is the discrete Fourier transform (DFT) of vector x in Frequency domain decimation ALGORITHM/PROCEDURE: 1. Input the given sequence x[n] 2. Compute the Discrete Fourier Transform using FFT library function (ditfft or diffft) and obtain X[k] 3. Compute the Inverse Discrete Fourier Transform using FFT library function (ditfft or diffft) and obtain X[n] by following steps a. Take conjugate of X [k] and obtain X[k]* b. Compute the Discrete Fourier Transform using FFT library function (ditfft or diffft) for X[k]* and obtain N.x[n]* c. Once again take conjugate for N.x[n]* and divide by N to obtain x[n] 4. Display the results. SOURCE CODE:(DITFFT) clc; clear all; close all; 86 UR11EC098
  • 87. N=input('Enter the number of elements:'); for i=1:N re(i)= input('Enter the real part of the element:'); im(i)= input('Enter the imaginary part of the element:'); end %% Call Dit_fft function [re1,im1]= ditfft(re,im,N); disp(re1); disp(im1); figure(1); subplot(2,2,1); stem(re1); xlabel('Time period'); ylabel('Amplitude'); title('Real part of the output'); subplot(2,2,2); stem(im1); xlabel('Time period'); ylabel('Amplitude'); title('Imaginary part of the output'); %%dit_ifft N=input('Enter the number of elements:'); for i=1:N re(i)= input('Enter the real part of the element:'); im(i)= input('Enter the imaginary part of the element:'); end for i=1:N re(i)=re(i); im(i)=-im(i); end %% call dit_ifft function [re1,im1]=ditifft(re,im,N); 87 UR11EC098
  • 88. for i=1:N re1(i)=re1(i)/N; im1(i)=-im1(i)/N; end disp(re1); disp(im1); %figure(2) subplot(2,2,3); stem(re1); xlabel('Time period'); ylabel('Amplitude'); title('Real part of the output'); subplot(2,2,4); stem(im1); xlabel('Time period'); ylabel('Amplitude'); title('Imaginary part of the output'); Function Table:(DITFFT) function [ re, im ] = ditfft( re, im, N) %UNTITLED5 Summary of this function goes here % Detailed explanation goes here N1=N-1; N2=N/2; j=N2+1; M=log2(N); % Bit reversal sorting for i=2:N-2 if i<j tr=re(j); ti=im(j); re(j)=re(i); im(j)=im(i); re(i)=tr; 88 UR11EC098
  • 89. im(i)=ti; end k=N2; while k<=j j=j-k; k=k/2; end j=j+k; j=round(j); end for l=1:M le=2.^l; le2=le/2; ur=1; ui=0; sr=cos(pi/le2); si=sin(pi/le2); for j=2:(le2+1) jm=j-1; for i=jm:le:N ip=i+le2; tr=re(ip)*ur-im(ip)*ui; ti=re(ip)*ui-im(ip)*ur; re(ip)=re(i)-tr; im(ip)=im(i)-ti; re(i)=re(i)+tr; im(i)=im(i)+ti; end tr=ur; ur=tr*sr-ui*si; ui=tr*si+ui*sr; end end Function Table:(DITIFFT) function [ re,im] = ditifft(re,im,N) %UNTITLED2 Summary of this function goes here 89 UR11EC098
  • 90. % Detailed explanation goes here N1=N-1; N2=N/2; j=N2+1; M=log2(N); %Bit reversal sorting for i=2:N-2 if i<j tr=re(j); ti=im(j); re(j)=re(i); im(j)=im(i); re(i)=tr; im(i)=ti; end k=N2; while k<=j j=j-k; k=k/2; end j=j+k; j=round(j); end for l=1:M le=2.^l; le2=le/2; ur=1; ui=0; sr=cos(pi/le2); si=-sin(pi/le2); for j=2:(le2+1) jm=j-1; for i=jm:le:N ip=i+le2; tr=re(ip)*ur-im(ip)*ui; ti=re(ip)*ui+im(ip)*ur; re(ip)=re(i)-tr; 90 UR11EC098
  • 92. Source code :(DIFFFT) %% DIF_FFT clc; clear all; close all; %% N=input('Enter the number of points in DIF DFT:'); for i=1:N re(i)=input('Enter the real part of the element:'); im(i)=input('Enter the imaginary part of the element:'); end %% % Call DIf_FFT Function [re1, im1]=diffft(re,im,N); display(re1); display(im1); figure(1); subplot(2,2,1); 92 UR11EC098
  • 93. stem(re1); xlabel('Time'); ylabel('Amplitude'); title('Real part of the output'); subplot(2,2,2); stem(im1); xlabel('Time'); ylabel('Amplitude'); title('Imaginary part of the output'); %% DIF IFFT N=input('Enter the number of points in DIF IFFT:'); for i=1:N re(i)=input('Enter the real part of the element:'); im(i)=input('Enter the imaginary part of the element:'); end for i=1:N re(i)=re(i); im(i)=-im(i); end %% Call dif_ifft function [re1, im1]=ditifft(re,im,N); for i=1:N re1(i)=re1(i)/N; im1(i)=-im1(i)/N; end display(re1) display(im1); % figure(2); subplot(2,2,3); stem(re1); xlabel('Time'); ylabel('Amplitude'); title('Real part of the output'); subplot(2,2,4); 93 UR11EC098
  • 94. stem(im1); xlabel('Time'); ylabel('Amplitude'); title('Imaginary part of the output'); Function Table:(DIFFFT) function [re, im ] = diffft(re, im, N) %UNTITLED5 Summary of this function goes here % Detailed explanation goes here N1=N-1; N2=N/2; M=log2(N); %% % for l=M:-1:1; le=2.^l; le2=le/2; ur=1; ui=0; sr=cos(pi/le2); si=-sin(pi/le2); for j=2:(le2+1) jm=j-1; for i=jm:le:N ip=i+le2; tr=re(ip); ti=im(ip); re(ip)=re(i)-re(ip); im(ip)=im(i)-im(ip); re(i)=re(i)+tr; im(i)=im(i)+ti; tr=re(ip); re(ip)=re(ip)*ur-im(ip)*ui; im(ip)=im(ip)*ur+tr*ui; end tr=ur; 94 UR11EC098
  • 95. ur=tr*sr-ui*si; ui=tr*si+ui*sr; end end j=N2+1; for i=2:N-2 if i<j tr=re(j); ti=im(j); re(j)=re(i); im(j)=im(i); re(i)=tr; im(i)=ti; end k=N2; while k<=j j=j-k; k=k/2; end j=j+k; end Function Table:(DIFIFFT) function [ re, im ] = dififft( re, im, N) %UNTITLED5 Summary of this function goes here % Detailed explanation goes here N1=N-1; N2=N/2; M=log2(N); %% % for l=M:-1:1; le=2.^l; le2=le/2; ur=1; 95 UR11EC098
  • 97. Command Window: Enter the number of points in DIF DFT:4 Enter the real part of the element:1 Enter the imaginary part of the element:0 Enter the real part of the element:1 Enter the imaginary part of the element:0 Enter the real part of the element:1 Enter the imaginary part of the element:0 Enter the real part of the element:1 E n t e r t h e i m a g i n 97 UR11EC098
  • 99. e 1 = 4 0 0 0 im1 = 0 0 0 0 Enter the number of points in DIF IFFT:4 Enter the real part of the element:4 Enter the imaginary part of the element:0 Enter the real part of the element:0 Enter the imaginary part of the element:0 Enter the real part of the element:0 Enter the imaginary part of the element:0 Enter the real part of the element:0 Enter the imaginary part of the element:0 re 1 = 1 1 1 1 im1 = 0 0 0 0 Output: 99 UR11EC098
  • 101. RESULT: The DFT and IDFT of the given sequence are computed using FFT algorithm both DITFFT and DIFFFT. FLOWCHART: 101 UR11EC098
  • 102. 102 UR11EC098 START ENTER THE FILTER SPECIFICATIONS (ORDER OF THE FILTER, CUT-OFF FREQUENCY) dESIGN THE FILTER PLOT THE WAVEFORMS STOP
  • 103. AIM: Write a MATLAB Script to design a low pass FIR filter using Window Method for the given specifications . APPARATUS REQUIRED: PC, MATLAB software THEORY: A digital filter is a discrete time LTI system. It is classified based on the length of the impulse response as IIR filters: Where h [n] has infinite number of samples and is recursive type. FIR filters: They are non-recursive type and h [n] has finite number of samples. The transfer function is of the form: ∑ − = − = 1 0 )( N n n n zhzH This implies that it has (N-1) zeros located anywhere in the z-plane and (N-1) poles at Z = h. THE FIR FILTER CAN BE DESIGNED BY: 103 UR11EC098 Ex. No :8 Date :10-2-14 Ex. No :8 Date :10-2-14 DESIGN OF FIR FILTERSDESIGN OF FIR FILTERS
  • 104.  Fourier series method  Frequency sampling method  Window method Most of the FIR design methods are interactive procedures and hence require more memory and execution time. Also implementation of narrow transition band filter is costly. But there are certain reasons to go for FIR. TYPES OF WINDOWS: 1. Rectangular 2. Triangular 3. Hamming 4. Hanning 5. Blackman 6. Kaiser LIBRARY FUNCTIONS: fir1 FIR filter design using the Window method. B = fir1(N,Wn) designs an Nth order low pass FIR digital filter and returns the filter coefficients of vector B of length (N+1). The cut-off frequency Wn must be between 0 < Wn < 1.0, with 1.0 corresponding to half the sample rate. The filter B is real and has linear phase. The normalized gain of the filter at Wn is -6 dB. B = fir1(N,Wn,'high') designs an Nth order high pass filter. You can also use B = fir1(N,Wn,'low') to design a low pass filter. 104 UR11EC098
  • 105. If Wn is a two-element vector, Wn = [W1 W2], fir1 returns an order N band pass filter with pass band W1 < W < W2.You can also specify B = fir1(N,Wn,'bandpass'). If Wn = [W1 W2], B = fir1(N,Wn,'stop') will design a band-stop filter. If Wn is a multi-element vector, Wn = [W1 W2 W3 W4 W5 ... WN], fir1 returns a N- order multi-band filter with bands 0 < W < W1, W1 < W < W2, ..., WN < W < 1. B = fir1(N,Wn,'DC-1') makes the first band a pass band. B = fir1(N,Wn,'DC-0') makes the first band a stop band. B = fir1(N,Wn,WIN) designs an N-th order FIR filter using the vector WIN of (N+1) length to window the impulse response. If empty or omitted, fir1 uses a Hamming window of length N+1. For a complete list of available windows, see the Help for the WINDOW function. KAISER and CHEBWIN can be specified with an optional trailing argument. For example, B = fir1(N,Wn,kaiser(N+1,4)) uses a Kaiser window with beta=4. B = fir1(N,Wn,'high',chebwin(N+1,R)) uses a Chebyshev window with R decibels of relative sidelobe attenuation.For filters with a gain other than zero at Fs/2, e.g., high pass and band stop filters, N must be even. Otherwise, N will be incremented by one. In this case, the window length should be specified as N+2. By default, the filter is scaled so the center of the first pass band has magnitude exactly one after windowing. Use a trailing 'noscale' argument to prevent this scaling, e.g. 105 UR11EC098
  • 106. B = fir1(N,Wn,'noscale'), B = fir1(N,Wn,'high','noscale'), B = fir1(N,Wn,wind,'noscale'). You can also specify the scaling explicitly, e.g. fir1(N,Wn,'scale'), etc. We can specify windows from the Signal Processing Toolbox, such as boxcar, hamming, hanning, bartlett, blackman, kaiser or chebwin w = hamming(n) returns an n-point symmetric Hamming window in the column vector w. n should be a positive integer. w = hanning(n) returns an n-point symmetric Hann window in the column vector w. n must be a positive integer. w=triang(n) returns an n-point triangular window in the column vector w. The triangular window is very similar to a Bartlett window. The Bartlett window always ends with zeros at samples 1 and n, while the triangular window is nonzero at those points. For n odd, the center (n-2) points of triang(n-2) are equivalent to bartlett(n). 106 UR11EC098
  • 107. w = rectwin(n) returns a rectangular window of length n in the column vector w. This function is provided for completeness. A rectangular window is equivalent to no window at all. ALGORITHM/PROCEDURE: 1. Click on the MATLAB icon on the desktop (or go to Start – All Programs and click on MATLAB) to get into the Command Window. 2. Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command window. 3. Write the program in the ‘Edit’ window and save it in ‘M-file’. 4. Run the program. 5. Enter the input in the Command Window. 6. The result is displayed in the Command window and the graphical output is displayed in the Figure Window. Source code :1 %windows technique of Rectangular window using low pass filter clc; clear all; close all; N=input('Size of window:'); 107 UR11EC098
  • 108. wc=input('Cut off frequency:'); h=fir1(N-1,wc/pi,boxcar(N)); tf(h,1,1,'variable','z^-1'); freqz(h); xlabel('Frequency'); ylabel('Magnitude'); title('FIR Filter'); Source code :2 %windows technique of Triangular(Bartlet Window) using High pass filter clc; clear all; close all; N=input('Size of window:'); wc=input('Cut off frequency:'); h=fir1(N-1,wc/pi,'high',triang(N)); tf(h,1,1,'variable','z^-1'); freqz(h); xlabel('Frequency'); ylabel('Magnitude'); title('FIR Filter'); Source code :3 %windows technique of Hamming using Band pass filter clc; clear all; close all; N=input('Size of window:'); wc1=input('Lower Cut off frequency:'); wc2=input('Upper Cut off frequency:'); wc=[wc1 wc2]; h=fir1(N-1,wc/pi,'bandpass',hamming(N)); tf(h,1,1,'variable','z^-1'); freqz(h); xlabel('Frequency'); ylabel('Magnitude'); 108 UR11EC098
  • 109. title('FIR Filter'); Source code :4 %windows technique of Hanning using Band stop filter clc; clear all; close all; N=input('Size of window:'); wc1=input('Lower Cut off frequency:'); wc2=input('Upper Cut off frequency:'); wc=[wc1 wc2]; h=fir1(N-1,wc/pi,'stop',hanning(N)); tf(h,1,1,'variable','z^-1'); freqz(h); xlabel('Frequency'); ylabel('Magnitude'); title('FIR Filter'); Source code :5 %windows technique of Blackman window using low pass filter clc; clear all; close all; N=input('Size of window:'); wc=input('Cut off frequency:'); h=fir1(N-1,wc/pi,blackman(N)); tf(h,1,1,'variable','z^-1'); freqz(h); xlabel('Frequency'); ylabel('Magnitude'); title('FIR Filter'); Command Window :1 109 UR11EC098
  • 114. The given low pass filter was designed using Window method and manually verified filter co- efficient of the filters. FLOWCHART: 114 UR11EC098 START ENTER THE FILTER SPECIFICATIONS (PASS, STOP BAND GAINS AND EDGE FREQUENCIES) DESIGN THE ANALOG BUTTERWORTH and chebyshev FILTER PLOT THE WAVEFORMS STOP
  • 115. AIM: Write a MATLAB Script to design Analog Butterworth filters for the given specifications. APPARATUS REQUIRED: PC, MATLAB software THEORY: BUTTERWORTH FILTER: Low pass Analog Butterworth filters are all pole filters characterised by magnitude frequency response by )( ωjH 2 = N c 2 1 1       Ω Ω + where N is the order of the filter and cΩ is the cut-off frequency. As N→α , the low pass filter is said to be normalized. All types of filters namely-Low pass, High pass, Band pass and Band elimination filters can be derived from the Normalized Low pass filter. STEPS IN DESIGNING ANALOG FILTER: 115 UR11EC098 Ex. No : 9 Date: 17-02-14 Ex. No : 9 Date: 17-02-14 9.DESIGN OF BUTTERWORTH FILTERS9.DESIGN OF BUTTERWORTH FILTERS
  • 116. 1. Transform the given specification to a Normalized Low pass specification 2. Find the order of the filter N and cut-off frequency Ωc 3. Find the transfer function H(s) of normalized LPF. 4. Use the applicable analog-to-analog transformation to get the transfer function of the required filter. LIBRARY FUNCTIONS: • butter: Butterworth digital and analog filter design. [B, A] = butter (N,Wn) designs an Nth order Low pass digital Butterworth filter and returns the filter coefficient vectors B (numerator) and A (denominator) in length N+1. The coefficients are listed in descending powers of z. The cut-off frequency Wn must be in the range 0.0 < Wn < 1.0, with 1.0 corresponding to half the sample rate. butter (N,Wn,'s'),butter (N,Wn,'low','s'),butter (N,Wn,'high','s'),butter (N,Wn,'pass','s')and butter (N,Wn,'stop','s')design analog Butterworth filters. In this case, Wn is in [rad/s] and it can be greater than 1.0. • buttord: Butterworth filter order selection. 116 UR11EC098
  • 117. [N, Wn] = buttord (Wp, Ws, Rp, Rs) returns the order N of the lowest order digital Butterworth filter that loses no more than Rp dB in the pass band and has at least Rs dB of attenuation in the stop band. Wp and Ws are the pass band and stop band edge frequencies, normalized from 0 to 1 (where 1 corresponds to pi radians/sample). For example, Lowpass: Wp = .1, Ws = .2 Highpass: Wp = .2, Ws = .1 Bandpass: Wp = [.2 .7], Ws = [.1 .8] Bandstop: Wp = [.1 .8], Ws = [.2 .7] buttord: also returns Wn, the Butterworth natural frequency (or) the "3 dB frequency" to be used with BUTTER to achieve the specifications. [N, Wn] = buttord (Wp, Ws, Rp, Rs, 's') does the computation for an analog filter, in which case Wp and Ws are in radians/second. When Rp is chosen as 3 dB, the Wn in BUTTER is equal to Wp in BUTTORD. • angle : Phase angle. Theta=angle (H) returns the phase angles, in radians, of a matrix with complex elements. • freqs : Laplace-transform (s-domain) frequency response. 117 UR11EC098
  • 118. H = freqs(B,A,W) returns the complex frequency response vector H of the filter B/A: B(s) b (1)s nb-1 + b(2)s nb- 2 + ... + b(nb) H(s) = ---- = -------------------------------------------------- A(s) a(1)s na-1 + a(2)s na-2 + ... + a(na) given the numerator and denominator coefficients in vectors B and A. The frequency response is evaluated at the points specified in vector W (in rad/s). The magnitude and phase can be graphed by calling freqs(B,A,W) with no output arguments. • tf: Transfer function SYS = tf(NUM,DEN) creates a continuous- time transfer function SYS with numerator(s) NUM and denominator(s) DEN. The output SYS is a tf object. ALGORITHM/PROCEDURE: 1. Click on the MATLAB icon on the desktop (or go to Start – All programs and click on 118 UR11EC098
  • 119. MATLAB) to get into the Command Window. 2. Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command window. 3. Write the program in the ‘Edit’ window and save it in ‘M-file’. 4. Run the program. 5. Enter the input in the command window. 6. The result is displayed in the Command window and the graphical output is displayed in the Figure Window. Butterworth Filters SOURCE CODE:1 clc; clear all; close all; %% Butterworth low pass Filter % Filter Specifications k1=input('Enter the passband gain in db:'); k2=input('Enter the stopband gain in db:'); w1=input('Enter the passband edge frequency in rad/Sec:'); w2=input('Enter the stopband edge frequency in rad/Sec:'); %Find the order and Cutofrf frequency using the given specification of %filter [n,Wc]=buttord(w1,w2,k1,k2,'s'); disp('The order is:'); disp(n); disp('The cutoff frequency is:'); 119 UR11EC098
  • 120. disp(Wc); % Low pass filtering [b,a]=butter(n,Wc,'low','s'); %Plotting magnitude & phase response f=linspace(1,512,1000); h=freqs(b,a,f); m=20*log(abs(h)); subplot(2,1,1); semilogx(f,m); xlabel('Frequency'); ylabel('Magnitude'); title('Magnitude response of Butterworth LPF'); % Phase response p=angle(h); subplot(2,1,2); semilogx(f,p); xlabel('Frequency'); ylabel('Phase'); title('Phase response of Butterworth LPF'); SOURCE CODE:2 clc; clear all; close all; %% Butterworth high pass Filter % Filter Specifications k1=input('Enter the passband gain in db:'); k2=input('Enter the stopband gain in db:'); w1=input('Enter the passband edge frequency in rad/Sec:'); w2=input('Enter the stopband edge frequency in rad/Sec:'); 120 UR11EC098
  • 121. %Find the order and Cutofrf frequency using the given specification of %filter [n,Wc]=buttord(w1,w2,k1,k2,'s'); disp('The order is:'); disp(n); disp('The cutoff frequency is:'); disp(Wc); % Low pass filtering [b,a]=butter(n,Wc,'high','s'); %Plotting magnitude & phase response f=linspace(1,512,1000); h=freqs(b,a,f); m=20*log(abs(h)); subplot(2,1,1); semilogx(f,m); xlabel('Frequency'); ylabel('Magnitude'); title('Magnitude response of Butterworth HPF'); % Phase response p=angle(h); subplot(2,1,2); semilogx(f,p); xlabel('Frequency'); ylabel('Phase'); title('Phase response of Butterworth HPF'); SOURCE CODE:3 clc; clear all; close all; %% Bandpass Filter Specifications Wp=input('Enter the pass band edge frequency : '); Ws=input('Enter the stop band edge frequency : '); 121 UR11EC098
  • 122. Rp=input('Enter the Pass band ripple: '); Rs=input('Enter the stop band gain: '); %To find order of the filter [N]=buttord(Wp,Ws,Rp,Rs,'s') %To find cut off frequency Wc=[Wp Ws]; %Band pass Filtering [b,a]=butter(N,Wc,'bandpass','s'); %plotting magnitude and phase response figure(1);freqs(b,a); SOURCE CODE:4 clc; clear all; close all; %% Bandstop Filter Specifications Wp=input('Enter the pass band edge frequency : '); Ws=input('Enter the stop band edge frequency : '); Rp=input('Enter the Pass band ripple: '); Rs=input('Enter the stop band gain: '); %To find order of the filter [N]=buttord(Wp,Ws,Rp,Rs,'s') %To find cut off frequency Wc=[Wp Ws]; %Band stop Filtering [b,a]=butter(N,Wc,'stop','s'); %plotting magnitude and phase response figure(1);freqs(b,a); Command Windows : 122 UR11EC098
  • 123. Using Low pass filter Using High pass filter Using Band pass filter Using Band stop filter 123 UR11EC098
  • 124. OUTPUTS: Using Low pass filter Using High pass filter 124 UR11EC098
  • 125. Using Band pass filter 125 UR11EC098
  • 126. Using Band stop filter 126 UR11EC098
  • 127. RESULT: Analog Butterworth Filter is designed for the given specifications, and manually verified the order, cut off frequency and filter co-efficient of the filter. FLOWCHART: 127 UR11EC098
  • 128. 128 UR11EC098 START ENTER THE FILTER SPECIFICATIONS (PASS, STOP BAND GAINS AND EDGE FREQUENCIES) DESIGN THE ANALOG BUTTERWORTH and chebyshev FILTER PLOT THE WAVEFORMS STOP
  • 129. AIM: Write a MATLAB Script to design Analog Chebyshev filter for the given specifications. APPARATUS REQUIRED: PC, MATLAB software THEORY: Chebyshev Filters : There are two types of Chebyshev filters. Type I are all-pole filters that exhibit equi-ripple behaviour in pass band and monotonic characteristics in stop band. Type II are having both poles and zeros and exhibit monotonic behavior in pass band and equi- ripple behavior in stop band. The zero lies on the imaginary axis. The magnitude-squared function is given as )/(1 1 )( 22 2 pC jH N ΩΩ+ = ε ω ε is the ripple parameter in pass band CN(x) is the Nth order Chebyshev polynomial defined as 129 UR11EC098 Ex. No : 10 Date: 17-02-14 Ex. No : 10 Date: 17-02-14 10.DESIGN OF CHEBYSHEV FILTERS10.DESIGN OF CHEBYSHEV FILTERS
  • 130. CN(x) =     > ≤ − − 1),cosh( 1,)cosh( 1 1 xxNCos xxNCos STEPS IN DESIGNING ANALOG FILTER: 1.Transform the given specification to a Normalized Low pass specification 2. Find the order of the filter N and cut-off frequency Ωc 3. Find the transfer function H(s) of normalized LPF. 4. Use the applicable analog-to-analog transformation to get the transfer function of the required filter. LIBRARY FUNCTIONS: • cheb1ord: Chebyshev Type I filter order selection. [N, Wn] = cheb1ord (Wp, Ws, Rp, Rs) returns the order N of the lowest order digital Chebyshev Type I filter that loses no more than Rp dB in the pass band and has at least Rs dB of attenuation in the stop band. Wp and Ws are the pass band and stop band edge frequencies, normalized 130 UR11EC098
  • 131. from 0 to 1 (where 1 corresponds to pi radians/sample). For example, Lowpass: Wp = .1, Ws = .2 Highpass: Wp = .2, Ws = .1 Bandpass: Wp = [.2 .7], Ws = [.1 .8] Bandstop: Wp = [.1 .8], Ws = [.2 .7] cheb1ord also returns Wn, the Chebyshev natural frequency to use with cheby1 to achieve the specifications. [N, Wn] = cheb1ord (Wp, Ws, Rp, Rs, 's') does the computation for an analog filter, in which case Wp and Ws are in radians/second. • cheby1 Chebyshev Type I digital and analog filter design. [B,A] = cheby1 (N,R,Wn) designs an Nth order Low pass digital Chebyshev filter with R decibels of peak-to-peak ripple in the pass band. cheby1 returns the filter coefficient vectors B (numerator) and A (denominator) of length N+1. The cut-off frequency Wn must be in the range 0.0 < Wn < 1.0, with 1.0 corresponding to half the sample rate. Use R=0.5 as a starting point, if you are unsure about choosing R. cheby1 (N,R,Wn,'s'), cheby1 (N,R,Wn,'low','s'), cheby1 (N,R,Wn,'high','s'), cheby1 (N,R,Wn,'pass','s') and cheby1 131 UR11EC098
  • 132. (N,R,Wn,'stop','s') design analog Chebyshev Type I filters. In this case, Wn is in [rad/s] and it can be greater than 1.0. ALGORITHM/PROCEDURE: 1. Click on the MATLAB icon on the desktop (or go to Start – All programs and click on MATLAB) to get into the Command Window. 2. Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command window. 3. Write the program in the ‘Edit’ window and save it in ‘M-file’. 4. Run the program. 5. Enter the input in the command window. 6. The result is displayed in the Command window and the graphical output is displayed in the Figure Window. CHEBYSHEV FILTERS : Source code:1 clc; clear all; close all; %% Chebyshev low pass Filter % Filter Specifications k1=input('Enter the passband ripple in db:'); k2=input('Enter the stopband attenuation in db:'); 132 UR11EC098
  • 133. w1=input('Enter the passband edge frequency in rad/Sec:'); w2=input('Enter the stopband edge frequency in rad/Sec:'); %Find the order and Cutofrf frequency using the given specification of %filter [n,Wc]=cheb1ord(w1,w2,k1,k2,'s'); disp('The order is:'); disp(n); disp('The cutoff frequency is:'); disp(Wc); % Low pass filtering [b,a]=cheby1(n,k1,w1,'low','s'); figure(1);freqs(b,a); Source code:2 clc; clear all; close all; %% Chebyshev High pass Filter % Filter Specifications k1=input('Enter the passband ripple in db:'); k2=input('Enter the stopband attenuation in db:'); w1=input('Enter the passband edge frequency in rad/Sec:'); w2=input('Enter the stopband edge frequency in rad/Sec:'); %Find the order and Cutofrf frequency using the given specification of %filter [n,Wc]=cheb1ord(w1,w2,k1,k2,'s'); disp('The order is:'); disp(n); disp('The cutoff frequency is:'); 133 UR11EC098
  • 134. disp(Wc); % High pass filtering [b,a]=cheby1(n,k1,w1,'high','s'); figure(1);freqs(b,a); Source code: 3 clc; clear all; close all; %% Bandpass Filter Specifications Wp=input('Enter the pass band edge frequency : '); Ws=input('Enter the stop band edge frequency : '); Rp=input('Enter the Pass band ripple: '); Rs=input('Enter the stop band gain: '); %To find order of the filter [N]=cheb1ord(Wp,Ws,Rp,Rs,'s') %To find cut off frequency Wc=[Wp Ws]; %Band pass Filtering [b,a]=cheby1(N,Rp,Wc,'bandpass','s'); %plotting magnitude and phase response figure(1);freqs(b,a); Source code: 4 clc; clear all; close all; %% Bandstop Filter Specifications Wp=input('Enter the pass band edge frequency : '); Ws=input('Enter the stop band edge frequency : '); Rp=input('Enter the Pass band ripple: '); Rs=input('Enter the stop band gain: '); 134 UR11EC098
  • 135. %To find order of the filter [N]=cheb1ord(Wp,Ws,Rp,Rs,'s') %To find cut off frequency Wc=[Wp Ws]; %Bandstop Filtering [b,a]=cheby1(N,Rp,Wc,'stop','s'); %plotting magnitude and phase response figure(1);freqs(b,a); Command Window :1(LPF) Output: 135 UR11EC098
  • 139. RESULT: Analog Chebyshev Filter is designed for the given specifications, and manually verified the 139 UR11EC098
  • 140. order, cut off frequency and filter co-efficient of the filter. FLOWCHART: 140 UR11EC098 START ENTER THE FILTER SPECIFICATIONS (PASS, STOP BAND GAINS AND EDGE FREQUENCIES) DESIGN THE ANALOG BUTTERWORTH and CHEBYSHEV LOW PASS FILTER PLOT THE WAVEFORMS STOP CONVERT THE LOW PASS FILTERS in to digital filterS by using the impulse invariant and bilinear TRANSFORMATIONS
  • 142. AIM: Write a MATLAB Script to design Butterworth and Chebyshev low pass filters using Bilinear Transformation Impulse Invariant Transformation . APPARATUS REQUIRED: PC, MATLAB software THEORY: A digital filter is a linear time invariant discrete time system. The digital filters are classified into two, based on their lengths of impulse response 1. Finite Impulse response (FIR) They are of non-recursive type and h [n] has finite number of samples 2. Infinite Impulse response (IIR) h[n] has finite number of samples. They are of recursive type. Hence, their transfer function is of the form ∑= − = α 0 )()( n n znhzH 142 UR11EC098 Ex. No : 11 Date: 03-03-14 Ex. No : 11 Date: 03-03-14 11.DESIGN OF IIR FILTERS11.DESIGN OF IIR FILTERS
  • 143. ∑ ∑ − = − − = − + = 1 1 1 0 1 )( N j j j M K k k Za Zb ZH The digital filters are designed from analog filters. The two widely used methods for digitizing the analog filters include 1. Bilinear transformation 2. Impulse Invariant transformation The bilinear transformation maps the s-plane into the z-plane by H(Z) = 1 1 1 12 |)( − − + − ×= Z Z T SH s This transformation maps the jΩ axis (from Ω = -∞ to +∞) repeatedly around the unit circle (exp ( jw), from w=-π to π ) by       =Ω 2 tan 2 ω T BILINEAR TRANSFORMATION: DESIGN STEPS: 1. From the given specifications, Find pre-warped analog frequencies using       =Ω 2 tan 2 ω T 2. Using the analog frequencies, find H(s) of the analog filter 143 UR11EC098
  • 144. 3. Substitute 1 1 1 12 − − + − ×= Z Z T S in the H(s) of Step:2 IMPULSE INVARIANT TRANSFORMATION: DESIGN STEPS: 1. Find the analog frequency using  = T/ω 2. Find the transfer function of analog filter Ha(s) 3. Express the analog filter transfer function as a sum of single pole filters 4. Compute H(Z) of digital filter using the formula ∑ = − − − = N k ZTP k k e C ZH 1 1 1 )( LIBRARY FUNCTIONS: • Impinvar: Impulse Invariant method for analog-to-digital filter conversion [bz,az] = impinvar(b,a,fs) creates a digital filter with numerator and denominator coefficients bz and az, respectively, whose impulse response is equal to the impulse response of the analog filter with coefficients b and a, scaled by 1/fs. If you leave out the argument 144 UR11EC098
  • 145. fs (or) specify fs as an empty vector [ ], it takes the default value of 1 Hz. • Bilinear: Bilinear transformation method for analog-to-digital filter conversion. The bilinear transformation is a mathematical mapping of variables. In digital filtering, it is a standard method of mapping the s or analog plane into the z or digital plane. It transforms analog filters, designed using classical filter design ALGORITHM/PROCEDURE: 1. Calculate the attenuation in dB for the given design parameters 2. Design the analog counterpart 3. Using Impulse Invariant /Bilinear transformation design the digital filter 145 UR11EC098
  • 146. 4. Display the transfer function. Plot the magnitude response and phase response SOURCE CODE: / Butterworth Lowpass Impulse invariant method clc; clear all; close all; warning off; % Design of IIR Filters %% Filter Specifications % Input Wp,Ws,Sp,Ss,T % T=1,bothe ripple gains should be b/w .1 to .3 disp(' Butterworth Lowpass filter using Impulse invariant method '); T=input('Enter the Sampling Frequency in rad/sec: '); Sp=input('Enter the Pass-band Ripple Gain: '); Wp=input('Enter the Pass-band Edge Frequency in rad/sec: '); Ss=input('Enter the Stop-band Ripple Gain: '); Ws=input('Enter the Stop-band Edge Frequency in rad/sec: '); % Calculation of ohmp,ohms,Ap,As Ap=abs(20*log10(1-Sp)); As=abs(20*log10(Ss)); ohmp=Wp/T; ohms=Ws/T; % Butterworth Filter 146 UR11EC098
  • 147. % Calculation of order and cutoff freq. for the above filter specs. [n,Wc]=buttord(ohmp,ohms,Ap,As,'s'); % Low Pass Filtering [b,a]=butter(n,Wc,'low','s'); [bz,az] = impinvar(b,a,T); tf(bz,az,T); O=linspace(-pi,pi,50); % O is the freq. axis H=freqz(bz,az,O); % Magnitude Response Hm=20*log10(abs(H)); subplot(2,1,1); semilogx(O,Hm); xlabel('Frequency'); ylabel('Magnitude'); title('Magnitude Response of IIR Filter using Impulse Invariant Method'); % Phase Response Ha=angle(H); subplot(2,1,2); semilogx(O,Ha); xlabel('Frequency'); ylabel('Phase'); title('Phase Response of IIR Filter using Impulse Invariant Method'); / Butterworth Lowpass Bilinear Transformation Method clc; clear all; close all; warning off; % Design of IIR Filters 147 UR11EC098
  • 148. %% Filter Specifications % Input Wp,Ws,Sp,Ss,T % T=1,both the ripple gains should have band width( .1 to .3) disp(' Butterworth Lowpass filter using Bilnear transformation method '); T=input('Enter the Sampling Frequency in rad/sec: '); Sp=input('Enter the Pass-band Ripple Gain: '); Wp=input('Enter the Pass-band Edge Frequency in rad/sec: '); Ss=input('Enter the Stop-band Ripple Gain: '); Ws=input('Enter the Stop-band Edge Frequency in rad/sec: '); % Calculation of ohmp,ohms,Ap,As Ap=abs(20*log10(1-Sp)); As=abs(20*log10(Ss)); ohmp=Wp/T; ohms=Ws/T; % Butterworth Filter % Calculation of order and cutoff freq. for the above filter specs. [n,Wc]=buttord(ohmp,ohms,Ap,As,'s'); % Low Pass Filtering [b,a]=butter(n,Wc,'low','s'); [bz,az] = bilinear(b,a,1/T); tf(bz,az,T); O=linspace(-pi,pi,50); % O is the freq. axis H=freqz(bz,az,O); % Magnitude Response Hm=20*log10(abs(H)); subplot(2,1,1); semilogx(O,Hm); xlabel('Frequency'); 148 UR11EC098
  • 149. ylabel('Magnitude'); title('Magnitude Response of IIR Filter using Bilinear Transformation Method'); % Phase Response Ha=angle(H); subplot(2,1,2); semilogx(O,Ha); xlabel('Frequency'); ylabel('Phase'); title('Phase Response of IIR Filter using Bilinear Transformation Method'); / Chebyshev Lowpass Impulse invariant method clc; clear all; close all; warning off; % Design of IIR Filters %% Filter Specifications % Input Wp,Ws,Sp,Ss,T % T=1,bothe ripple gains should be b/w .1 to .3 disp(' Chebyshev Lowpass filter using Impulse invariant method '); T=input('Enter the Sampling Frequency in rad/sec: '); Sp=input('Enter the Pass-band Ripple Gain: '); Wp=input('Enter the Pass-band Edge Frequency in rad/sec: '); Ss=input('Enter the Stop-band Ripple Gain: '); Ws=input('Enter the Stop-band Edge Frequency in rad/sec: '); % Calculation of ohmp,ohms,Ap,As Ap=abs(20*log10(1-Sp)); 149 UR11EC098
  • 150. As=abs(20*log10(Ss)); ohmp=Wp/T; ohms=Ws/T; % Chebyshev Filter % Calculation of order and cutoff freq. for the above filter specs. [n,Wc2]=cheb1ord(ohmp,ohms,Ap,As,'s') % Low Pass Filtering [b,a]=cheby1(n,Ap,Wc2,'low','s'); [bz,az] = impinvar(b,a,T); tf(bz,az,T); O=linspace(-pi,pi,50); % O is the freq. axis H=freqz(bz,az,O); % Magnitude Response Hm=20*log10(abs(H)); subplot(2,1,1); semilogx(O,Hm); xlabel('Frequency'); ylabel('Magnitude'); title('Magnitude Response of IIR Filter using Impulse Invariant Method'); % Phase Response Ha=angle(H); subplot(2,1,2); semilogx(O,Ha); xlabel('Frequency'); ylabel('Phase'); title('Phase Response of IIR Filter using Impulse Invariant Method'); /Chebyshev Lowpass Bilinear Transformation Method clc; 150 UR11EC098
  • 151. clear all; close all; warning off; % Design of IIR Filters %% Filter Specifications % Input Wp,Ws,Sp,Ss,T % T=1,bothe ripple gains should be b/w .1 to .3 disp(' Chebyshev Lowpass filter using Bilnear transformation method '); T=input('Enter the Sampling Frequency in rad/sec: '); Sp=input('Enter the Pass-band Ripple Gain: '); Wp=input('Enter the Pass-band Edge Frequency in rad/sec: '); Ss=input('Enter the Stop-band Ripple Gain: '); Ws=input('Enter the Stop-band Edge Frequency in rad/sec: '); % Calculation of ohmp,ohms,Ap,As Ap=abs(20*log10(1-Sp)); As=abs(20*log10(Ss)); ohmp=Wp/T; ohms=Ws/T; % Chebyshev Filter % Calculation of order and cutoff freq. for the above filter specs. [n,Wc2]=cheb1ord(ohmp,ohms,Ap,As,'s') % Low Pass Filtering [b,a]=cheby1(n,Ap,Wc2,'low','s'); [bz,az] = bilinear(b,a,1/T); tf(bz,az,T); O=linspace(-pi,pi,50); % O is the freq. axis H=freqz(bz,az,O); % Magnitude Response Hm=20*log10(abs(H)); 151 UR11EC098
  • 152. subplot(2,1,1); semilogx(O,Hm); xlabel('Frequency'); ylabel('Magnitude'); title('Magnitude Response of IIR Filter using Bilinear Transformation Method'); % Phase Response Ha=angle(H); subplot(2,1,2); semilogx(O,Ha); xlabel('Frequency'); ylabel('Phase'); title('Phase Response of IIR Filter using Bilinear Transformation Method'); / Butterworth Lowpass Impulse invariant method Command window: Output: 152 UR11EC098
  • 153. / Butterworth Lowpass Bilinear Transformation Method Command Window : 153 UR11EC098
  • 154. Output: / Chebyshev Lowpass Impulse invariant method Command Window: 154 UR11EC098
  • 157. RESULT: Butterworth and Chebyshev Lowpass filters were designed using Bilinear and Impulse Invariant transformations, and manually verified 157 UR11EC098
  • 158. the order, cut off frequency and filter co-efficient of the filters. FLOWCHART: 158 UR11EC098 START ENTER THE SYSTEM’S NUMERATOR AND DENOMINATOR COEFFICIENTS Generate the waveform of TIME DOMAIN response by using the appropriate library function PLOT THE WAVEFORMS STOP
  • 159. AIM: Write a MATLAB Script to find the time domain response (impulse response and step response) for the given FIR and IIR systems (filters). . APPARATUS REQUIRED: PC, MATLAB software THEORY: IMPULSE RESPONSE: δ[n] y1[n]=T[δ[n]]=h[n] If the input to the system is a unit impulse (ie) x[n] = δ[n], then the output of the system, known as the impulse response, is denoted by h [n] where, h[n]=T[δ[n]] STEP RESPONSE: 159 UR11EC098 Ex. No :12(a) Date:10-03-14 Ex. No :12(a) Date:10-03-14 TIME DOMAIN RESPONSE OF LTI SYSTEMSTIME DOMAIN RESPONSE OF LTI SYSTEMS T T
  • 160. u[n] y2[n]=T[u[n]]=s[n] If the input to the system is a unit step (ie) x[n] = u[n], then the output of the system, known as step response, is denoted by s[n] where, s[n]=T[u[n]] The relation between the impulse response and step response is given by s[n] = u[n]*h[n] * is the Convolution operator LIBRARY FUNCTIONS: • filter: Filters data with an infinite impulse response (IIR) or finite impulse response (FIR) filter .The filter function filters a data sequence using a digital filter which works for both real and complex inputs. The filter is a direct form II transposed implementation of the standard difference equation. y = filter (b, a, X) filters the data in vector X with the filter described by numerator coefficient vector b and denominator coefficient vector a. If a(1) is 160 UR11EC098
  • 161. not equal to 1, filter normalizes the filter coefficients by a(1). If a(1) equals 0, filter returns an error. ALGORITHM/PROCEDURE: 1. Click on the MATLAB icon on the desktop (or go to Start – All Programs and click on MATLAB) to get into the Command Window 2. Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command window. 3. Write the program in the ‘Edit’ window and save it in ‘M-file’ 4. Run the program 5. Enter the input in the command window 6. The result is displayed in the Command window and the graphical output is displayed in the Figure Window SOURCE CODE: PROGRAM 1 clc; clear all; close all; %% Input the samples % Time domain response of FIR filter N=16; %Input samples k=0:N-1; x=(k==0); 161 UR11EC098
  • 162. b0=1; b1= -1; b2=-2; B=[b0,b1,b2]; %Numerator coeff. A=1; %Denominator coeff. %Filtering y=filter(B, A ,x); %Plot the graph subplot(2,2,1), stem(k,x,'r'); xlabel('Time'); ylabel('Unit Impulse'); title('Impulse input'); subplot(2,2,2), stem(k,y,'r'); xlabel('Frequency'); ylabel('Magnitude'); title('Impulse Response FIR Filter'); % Time domain Response of IIR Filter N1=10; %input samples k1=0:N1-1; x1=(k1==0); B1=1; a=0.8; A1=[1,-a]; y1=filter(B1, A1 ,x1); %plot the graph subplot(2,2,3), stem(k1,x1,'r'); xlabel('Time'); ylabel('Unit Impulse'); title('Impulse input'); subplot(2,2,4), stem(k1,y1,'r'); xlabel('Frequency'); ylabel('Magnitude'); title('Impulse Response IIR Filter'); PROGRAM 2 clc; clear all; close all; %% Input the samples % Time domain Response of FIR filter 162 UR11EC098
  • 163. N=16; %Input samples k=0:N-1; x(1:N)=1; b0=1; b1= -1; b2=-2; B=[b0,b1,b2]; %Numerator coeff. A=1; %Denominator coeff. %Filtering y=filter(B, A ,x); %plot the graph subplot(2,2,1); stem(k,x,'r'); xlabel('Time'); ylabel('Unit step signal'); title('Unit step input signal'); subplot(2,2,2); stem(k,y,'r'); xlabel('Frequency'); ylabel('Magnitude'); title('Step Response FIR filter'); % Time domain response of IIR filter N1=10; %Input samples k1=0:N1-1; x1(1:N1)=1; B1=1; a=0.8; A1=[1,-a]; y1=filter(B1, A1 ,x1); %plot the graph subplot(2,2,3); stem(k1,x1,'r'); xlabel('Time'); ylabel('Unit step input'); title('Unit step input signal'); subplot(2,2,4); stem(k1,y1,'r'); xlabel('Frequency'); ylabel('Magnitude'); title('Step Response IIR Filter'); 163 UR11EC098
  • 164. Output for Unit impulse input: Output for Unit step input: 164 UR11EC098
  • 166. The Time domain responses of the given systems were found using MATLAB and manually verified. FLOWCHART: 166 UR11EC098 START ENTER THE SYSTEM’S NUMERATOR AND DENOMINATOR COEFFICIENTS Generate the waveform of frequencY PLOT THE WAVEFORMS STOP
  • 167. AIM: Write a MATLAB Script to find the frequency domain response (magnitude response and phase response) for the given FIR and IIR systems (filters). . APPARATUS REQUIRED: PC, MATLAB software THEORY: IMPULSE RESPONSE: x[n] y[n]=T[x[n]] If the input to the system is a unit impulse (ie) x[n]=δ[n], then the output of the system is known as impulse response denoted by h[n] where, h[n]=T[δ[n]] 167 UR11EC098 Ex. No : 12(b) Date:10-03-14 Ex. No : 12(b) Date:10-03-14 FREQUENCY DOMAIN RESPONSE OF LTI SYSTEMSFREQUENCY DOMAIN RESPONSE OF LTI SYSTEMS T T
  • 168. We know that any arbitrary sequence x[n] can be represented as a weighted sum of discrete impulses. Now the system response is given by, y[n]=T[x[n]]= T[ ∑ ∞ −∞= − k knkx )()( δ ] where x(k) denotes the kth sample. The response of DTLTI system to sequence x(k) δ[n-k] will be x(k)h[n-k].i.e. T[x(k) δ[n-k]] = x(k) T[δ[n- k]] = x(k) h[n-k].So response y[n] of DTLTI system to x[n] is y [n]= ∑ ∞ −∞= − k knhkx )()( This is known as convolution sum and can be represented as y[n] = x[n]*h[n] * is the Convolution operator FREQUENCY RESPONSE: y[n] can also be written as ∴y[n]= ∑ ∞ −∞= − k knxkh )()( If x[n] is a complex exponential of the form x[n] =ejωn where n varies from -∞ to ∞ Then y[n] = )()( khe k knj ∑ ∞ −∞= −ω = )(. khee nj k kj ωω ∑ ∞ −∞= − 168 UR11EC098
  • 169. = jwn k kj ekhe )(∑ ∞ −∞= − ω y[n]=H(ejω ) ejωn where H(ejω )= )(khe k kj ∑ ∞ −∞= − ω H(ejω ) is called the frequency response of DTLTI system. It is a complex function H(ejω ) =Hr(ejω )+j Him(ejω ) H(ejω )= )( ωj eH ejθ(ω) )( ωj eH is the magnitude response. )(ωθ is the phase response. LIBRARY FUNCTIONS: • exp: Exponential. exp (X) is the exponential of the elements of X, e to the power X. For complex Z=X+i*Y, exp (Z) = exp (X)*(COS(Y) +i*SIN(Y)). • disp: Display array. DISP (X) is called for the object X when the semicolon is not used to terminate a statement. • Freqz: Compute the frequency response of discrete-time filters, [h,w] = freqz (hd) returns the frequency response vector h and the corresponding frequency vector w for the discrete-time filter hd. When hd is a vector of discrete- time filters, freqz returns the matrix h. Each column of h corresponds to one filter in the vector hd. 169 UR11EC098
  • 170. • Angle: Phase angle P = angle (Z) returns the phase angle, in radians, for each element of complex array Z. • log10: The log10 function operates element-by- element on arrays. Its domain includes complex numbers, which may lead to unexpected results if used unintentionally ALGORITHM/PROCEDURE: 1. Click on the MATLAB icon on the desktop (or go to Start – All programs and click on MATLAB) to get into the Command Window 2. Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command window. 3. Write the program in the ‘Edit’ window and save it in ‘M-file’. 4. Run the program. 5. Enter the input in the command window. 6. The result is displayed in the Command window and the graphical output is displayed in the Figure Window. SOURCE CODE: clc; 170 UR11EC098
  • 171. clear all; close all; %Frequency Response num=input('Enter num:'); denum=input('Enter denum:'); n=linspace(0,pi,1000); h=freqz(num,denum,n); mag=20*log(abs(h)); subplot(2,2,1),semilogx(n,mag); xlabel('Frequency index'),ylabel('Magnitude'),title('Magnitude Response'); pha=angle(h); subplot(2,2,2),semilogx(n,pha); xlabel('Frequency index'),ylabel('Phase'),title('Phase Response'); z=tf(num,denum,1) COMMAND WINDOW: OUTPUT : 171 UR11EC098
  • 172. RESULT: The frequency response (magnitude and phase response) of the given system was found using MATLAB. 172 UR11EC098