Documente Academic
Documente Profesional
Documente Cultură
START
ENTER THE SIGNAL
PARAMETERS (AMPLITUDE,
TIME AND FREQUENCY)
GENERATE THE WAVEFORM BY USING THE
APPROPRIATE LIBRARY FUNCTION
PLOT THE WAVEFORMS
STOP
EX.
:1
EX. NO
NO
:1
DATE:09-12-13
DATE:09-12-13
WAVEFORM GENERATION
AIM:
Write a program in MATLAB to generate the following waveforms
(Discrete Time signal and Continuous Time
signal)
1. Unit
3. Ramp signal
Impulse
4. Sinusoidal
sequence,
2. Unit
step
sequence,
3. Unit Ramp
sequence,
4. Sinusoidal
signal,
5. Exponential
signal,
6. R
a
n
sequence,
5. Exponential
sequence,
6. Random
sequence,
i
g
1. Pulse signal,
2. Unit
step
signal
APPARATUS REQUIRED:
Pentium 4 Processor, MATLAB software
THEORY:
2
1, for n 0
0, otherwise
n, for n 0
0, otherwise
x (t ) u(t )
t , for t 0
0, otherwise
x (t ) r ( t )
Sinusoidal signal.
x(t ) A sin t )
( , where A
Exponential signal.
x (t ) = A e
at
a
t
LIBRARY FUNCTIONS:
clc:
3
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.
5
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);
plot(t5,x5)
xlabel('time');
ylabel('Amplitude');
title('Sinusoidal signal');
%RANDOM SIGNAL
t6=-10:1:20;
x6=rand(1,31);
7
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);
stem(n3,x3);
xlabel('time');
ylabel('Amplitude');
title('Exponential signal');
%UNIT RAMP SIGNAL
n4=-10:1:20;
x4=n4;
subplot(2,3,4);
8
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:
DISCRETE TIME :
OUTPUT WAVEFORM(CONTINUOUS
TIME):
10
RESULT:
11
START
STOP
12
EX.
:2
EX. NO
NO
:2
DATE
:21-12-13
DATE :21-12-13
reversal
sequence
13
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
.*
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
14
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;
15
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:');
n1=input('Enter the -ve shift:');
16
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);
stem(0:l1-1,x1);
xlabel('time');
17
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');
title('Multiplication of two signals');
else
y1=x1+x2;
18
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 :
20
OUTPUT(Time
variable) :
21
RESULT:
22
STOP
23
EX.
::
EX. NO
NO
33
DATE:
DATE: 06-1-14
06-1-14
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.
T [a1 x1 (n) a 2 x 2 (n)] a1T [ x1 ( n)] a 2T [ x 2 ( n)]
METHODS OF PROOF:
Individual inputs are applied and the
weighted sum of the outputs is taken. Then the
24
25
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
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
objects.
subs
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
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;
Source code :2
clc;
clear all;
close all;
%Properties of DT Systems(Linearity)
29
%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');
title('L.H.S');
subplot(2,2,4);
stem(rhs);
xlabel('time');
ylabel('Amplitude');
title('R.H.S');
30
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);
xlabel('time');
ylabel('Amplitude');
title('L.H.S');
subplot(2,2,4);
stem(y3);
xlabel('time');
ylabel('Amplitude');
title('R.H.S');
31
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');
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');
32
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
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);
33
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 :
34
Linear System :2
Output :
35
Output :
36
Output :
37
Non-Causal system :5
Unstable system :6
Output :
38
39
RESULT:
The properties of Discrete Time system is
verified using MATLAB
FLOWCHART:
40
START
ENTER THE SIGNAL
PARAMETERS (AMPLITUDE,
TIME AND FREQUENCY)
STOP
EX.
::
EX. NO
NO
44
DATE:
DATE: 13-1-14
13-1-14
AIM:
upsampling,
downsampling
and
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),
42
To avoid
ANTIALIASING
FILTER H (Z)
y[n]
between
an
output
sequence
y[n]
0,
n = 0, 1, 2 .
otherwise
ANTI IMAGING
FILTER H (Z)
44
ANTI
IMAGING
y[n]
FILTER
ANTI
ALIASING
FILTER
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:
45
DOWN
SAMPLER
to
remove
all
phase
distortion,
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');
ylabel('Amplitude');
title('Decimated signal');
%interpolating the signal
47
48
Output :
49
50
RESULT:
The program written using library functions
and the sampling rate conversion process is
studied.
51
FLOWCHART:
START
STOP
52
EX.
::
EX. NO
NO
55
DATE
DATE :: 20-1-14
20-1-14
DISCRETE CONVOLUTION
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] =
x[k ]h[n k ]
or
h[k ]x[n k ]
The
x2 (k) or
N 1
x
k 0
N 1
x
k 0
[(n-k) mod N]
( k ) x2 [(n-k) mod N]
54
of
polynomial
convolving
them
multiplying
the
coefficients,
is
equivalent
to
two
polynomials
in
frequency domain.
length: Length of vector.
55
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
56
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');
57
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 :
58
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);
59
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 :
60
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');
61
62
OUTPUT:
SOURCE CODE :4
clc;
63
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');
X=fft(x,length(y));
64
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');
65
Command window :
OUTPUT :
66
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);
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)
67
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 :
OUTPUT :
68
69
RESULT:
The linear and circular convolutions are
performed by using MATLAB script and the
program results are verified by manual calculation.
FLOWCHART:
70
START
STOP
71
EX.
::
EX. NO
NO
66
DATE
DATE :: 27-127-114
14
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.
72
Where x is a
number
Further,
1 N 1
j2 n k N
x ( n) e
, for k 0...N 1
N n 0
73
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.
operation is applied to each column. For NDimensional 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
74
and
the
graphical
output
is
75
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 :
77
OUTPUT :
78
RESULT:
The program for DFT calculation was
performed with library functions and without
library functions. The results were verified by
manual calculation.
79
FLOWCHART:
START
STOP
80
EX.
EX. NO
NO
:7
:7
DATE
DATE :3-2-14
:3-2-14
FAST
FAST FOURIER TRANSFORM
TRANSFORM ALGORITHMS
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) =
N 1
x(n)e j 2nk/N
n 0
k=0,
1.N-1
which may conveniently be written in the
form
N 1
X (k) =
n 0
nk
x ( n) w N
k=0,
1.N-1
81
efficient
algorithms
for
the
in
point
DFT
for
complex
1 N 1
X(k )WN nk
N n0
82
where, wN=e-j2/N.
Taking conjugate and multiplying by N, we get,
N 1
N x*[n] =
k 0
X* (k )WNnk
1 N 1 *
[ X (k ) W Nnk ]*
N k 0
and
second
N/2
samples
of
x[n]
Decimation
in
t i me
( D I T ) fft
ditfft(x) is the discrete Fourier transform (DFT)
of vector x in time domain decimation
diffft:
D e c i ma t i o n i n f r e q u e n c y
( D I F ) fft
84
the
Discrete
Fourier
again
take
conjugate
for
SOURCE CODE:(DITFFT)
clc;
clear all;
close all;
N=input('Enter the number of elements:');
for i=1:N
re(i)= input('Enter the real part of the element:');
85
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;
im(i)=ti;
end
k=N2;
while k<=j
j=j-k;
k=k/2;
87
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
% Detailed explanation goes here
N1=N-1;
N2=N/2;
j=N2+1;
M=log2(N);
%Bit reversal sorting
88
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;
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
89
end
end
Command Window:
Output:
90
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);
stem(im1);
92
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;
ur=tr*sr-ui*si;
ui=tr*si+ui*sr;
93
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;
ui=0;
sr=cos(pi/le2);
si=-sin(pi/le2);
94
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
Command Window:
95
y
p
a
rt
o
f
t
h
e
e
l
e
m
e
n
t:
0
r
e
97
1
=
4
im1 =
0
im1 =
0
Output:
98
99
RESULT:
The DFT and IDFT of the given sequence
are computed using FFT algorithm both DITFFT
and DIFFFT.
FLOWCHART:
100
START
STOP
101
EX.
EX. NO
NO
:8
:8
DATE
DATE :10-2-14
:10-2-14
H ( z ) hn z n
n 0
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.
103
104
fir1(N,Wn,'noscale'),
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
hamming,
Toolbox,
hanning,
such
as
bartlett,
boxcar,
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
105
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
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');
title('FIR Filter');
107
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
108
Output:1
Command Window :2
OUTPUT: 2
109
Command Window :3
Output:3
110
Command Window :4
Output:4
Command Window :5
111
Output:
RESULT:
The given low pass filter was designed using
Window method and manually verified filter coefficient of the filters.
112
FLOWCHART:
START
STOP
113
EX.
::
EX. NO
NO
99
DATE:
DATE: 17-0217-0214
14
9.DESIGN
9.DESIGN OF
OF BUTTERWORTH
BUTTERWORTH FILTERS
FILTERS
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
1
H ( j ) 2
2N
the
transfer
function
H(s)
of
normalized LPF.
4. Use
the
applicable
analog-to-analog
digital
and
selection.
115
Wp = .1,
Ws = .2
Highpass: Wp = .2,
Ws = .1
B(s)
+ ... + b(nb)
b (1)s nb-1
+ b(2)s 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
freqs(B,A,W)
with
no
output
arguments.
ALGORITHM/PROCEDURE:
1. Click on the MATLAB icon on the desktop
(or go to Start All programs and click on
117
and
the
graphical
output
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:');
118
is
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:');
119
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 :
Using Low pass filter
121
122
OUTPUTS:
Using Low pass filter
123
124
125
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:
126
START
STOP
127
EX.
::
EX. NO
NO
10
10
DATE:
DATE: 17-0217-0214
14
10.DESIGN
10.DESIGN OF
OF CHEBYSHEV
CHEBYSHEV FILTERS
FILTERS
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
1
1
2
CN
( / p )
128
CN(x)
Cos( N cosh 1 x) ,
x 1
x 1
the
transfer
function
H(s)
of
normalized LPF.
4. Use
the
applicable
analog-to-analog
Wp = .1,
Highpass: Wp = .2,
Ws = .2
Ws = .1
and
the
graphical
output
is
[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: ');
%To find order of the filter
[N]=cheb1ord(Wp,Ws,Rp,Rs,'s')
%To find cut off frequency
133
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:
134
Output:
135
Output:
136
Output:
137
RESULT:
Analog Chebyshev Filter is designed for the
given specifications, and manually verified the
order, cut off frequency and filter co-efficient of
the filter.
138
FLOWCHART:
START
STOP
139
EX.
::
EX. NO
NO
11
11
DATE:
DATE: 03-0303-0314
14
MATLAB
Script
to
design
H ( z ) h( n) z n
n 0
140
M 1
bk Z k
K 0
N 1
H (Z )
a jZ j
j 1
H (S ) |s
2 1 Z 1
T 1 Z 1
2
tan
T
2
BILINEAR TRANSFORMATION:
DESIGN STEPS:
1. From the given specifications, Find
pre-warped analog frequencies using
2
tan
T
2
141
3. Substitute
2 1 Z 1
T 1 Z 1
in the H(s)
of Step:2
IMPULSE
INVARIANT
TRANSFORMATION:
DESIGN STEPS:
1. Find the analog frequency using =
/T
Ck
k 1 1 e
TPk Z 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
142
ALGORITHM/PROCEDURE:
1. Calculate the attenuation in dB for the given
design parameters
2. Design the analog counterpart
3. Using
Impulse
Invariant
/Bilinear
143
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
144
% 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');
ylabel('Magnitude');
146
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;
clear all;
close all;
warning off;
148
Output:
150
151
Output:
152
Output:
Command Window:
Output:
154
RESULT:
Butterworth and Chebyshev Lowpass filters
were
designed
using
Bilinear
and Impulse
155
FLOWCHART:
START
STOP
156
EX.
EX. NO
NO
::12(A)
12(A)
DATE:10-03-14
DATE:10-03-14
TIME DOMAIN
DOMAIN RESPONSE OF
OF LTI SYSTEMS
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:
T
157
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]
coefficient
vector
and
and
the
graphical
output
is
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');
Output for Unit impulse input:
161
162
RESULT:
163
START
STOP
164
EX.
::
EX. NO
NO
12(B)
12(B)
DATE:10-03-14
DATE:10-03-14
FREQUENCY
FREQUENCY DOMAIN
DOMAIN RESPONSE
RESPONSE OF
OF LTI
LTI SYSTEMS
SYSTEMS
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:
T
T
x[n]
y[n]=T[x[n]]
165
x(k ) (n k ) ]
The
y [n]= x( k )h(n k )
k
= x[n]*h[n]
y[n]= h( k ) x(n k )
k
j ( n k )
h( k )
Then y[n] = e
k
j k
.e jn h( k )
= e
k
j k
h( k )e jwn
= e
k
166
y[n]=H(ej) ejn
jk
h(k )
where H(ej)= e
k
H ( e j )
ej()
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
and
the
graphical
output
is
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 :
169
RESULT:
The frequency response (magnitude and
phase response) of the given system was found
using MATLAB.
170
171