Documente Academic
Documente Profesional
Documente Cultură
ylabel('Amplitude')
Enter the value of initial condition y(-1)
I=4
Enter the frequency
f =10
Amplitude
1
0.5
0
Amplitude
-0.5
40 -1
0
0.2
0.3
0.4
30
0.5
Time
0.6
0.7
0.8
0.9
20
10
0
0
0.1
0.2
0.3
0.4
0.5
Time
0.6
0.7
0.8
0.9
The sinusoidal response can also be obtained by using the in-built function filter.
For filtering, the input and output coefficients of the given difference equation
should be entered as two separate row vectors, starting from x(n) coefficient in the
matrix a /y(n) coefficient in the matrix b.
The given initial conditions should be entered as Y=[y(-1) y(-2) ..y(-N)] and X=[x(1) x(-2) x(-N)]. If x(n)=0, for n-1, X matrix need not be mentioned.
The equivalent initial condition input array is to be computed as xic= filter(a,b,Y,X).
The overall response of the given discrete system for the given input, is obtained
as
y=filter(a, b , given input, xic).
Using In-Built Function:
I=input('Enter the initial conditions in the form of row vector starting from y(-1)')
n=0:0.001:1;
f=input('Enter the frequency')
x=sin(2*pi*f*n);
a=input('Enter the input coefficients in the given system equation, starting from
x(n) coefficient')
b=input('Enter the input coefficients in the given system equation, starting from
y(n) coefficient')
xic=filter(a,b,I);
%Overall response of the system for the given input
y=filter(a,b,x,xic);
subplot(2,1,1)
plot(n,x)
title('Input signal x(n) applied')
xlabel('Time')
ylabel('Amplitude')
subplot(2,1,2)
plot(n,y)
title('Sinusoidal Response y(n) of the given first order system')
xlabel('Time')
ylabel('Amplitude')
Enter the initial conditions in the form of row vector starting from y(-1)
I=4
Enter the frequency
f =10
Enter the input coefficients in the given system equation, starting from x(n)
coefficient
a=1
Enter the input coefficients in the given system equation, starting from y(n)
coefficient
b=1
-1
Amplitude
1
0.5
0
-0.5
Amplitude
40 -1
0
0.2
0.3
0.4
30
0.5
Time
0.6
0.7
0.8
0.9
20
10
0
0
0.1
0.2
0.3
0.4
0.5
Time
0.6
0.7
0.8
0.9
Amplitude
1
0.5
0
-0.5
-1
0.1
0.1
Amplitude
80
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
Time
Sinusoidal Response y(n) of the given first order system
0.2
0.3
0.4
60
40
20
0
0.5
Time
0.6
0.7
0.8
0.9
n=0:0.001:1;
f=input('Enter the frequency')
x=sin(2*pi*f*n);
a=input('Enter the input coefficients in the given system equation, starting from
x(n) coefficient')
b=input('Enter the input coefficients in the given system equation, starting from
y(n) coefficient')
xic=filter(a, b, Iy, Ix);
%Overall response of the system for the given input
y=filter(a, b, x, xic);
subplot(2,1,1)
plot(n,x)
title('Input signal x(n) applied')
xlabel('Time')
ylabel('Amplitude')
subplot(2,1,2)
plot(n,y)
title('Sinusoidal Response y(n) of the given first order system')
xlabel('Time')
ylabel('Amplitude')
Enter the initial conditions in the from of row vector starting from x(-1)
Ix =1
Enter the initial conditions in the from of row vector starting from y(-1)
Iy =4
Enter the frequency
f =10
Enter the input coefficients in the given system equation, starting from x(n)
coefficient
a=1
Enter the input coefficients in the given system equation, starting from y(n)
coefficient
b=1
-1
Input signal x(n) applied
Amplitude
1
0.5
0
-0.5
-1
0.1
0.1
Amplitude
80
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
Time
Sinusoidal Response y(n) of the given first order system
0.2
0.3
0.4
60
40
20
0
0.5
Time
0.6
0.7
0.8
0.9
1.%This program plots the frequency and phase response of a discrete system
specified by
H(z)=1/(1-0.9z -1)
n= input('enter the number of frequency points over which the response is to be
plotted')
w=0:2*pi/n:2*pi;
%Enter the System function with z replaced by exp(jw)
h1=zeros(1,length(w));
for i=1:length(w)
h1(i)=1/(1-0.9*exp(-j*w(i)));
end
Magh1=abs(h1);
phaseh1=angle(h1);
subplot(2,1,1)
plot(w/pi,Magh1,'k')
title('Magnitude Response of 1/(1-0.9exp(-jw)) with n=100')
xlabel('frequency normalized with respect to pi')
ylabel('Magnitude')
grid
subplot(2,1,2)
plot(w/pi,phaseh1/pi,'k')
title('phase Response of 1/(1-0.9exp(-jw)) with n=100')
xlabel('frequency normalized with respect to pi')
ylabel('phase in pi units')
grid
enter the number of frequency points over which the response is to be plotted100
n = 100
Magnitude
15
10
5
0
0.2
0.4
0.6
0.8
1
1.2
1.4
1.6
frequency normalized with respect to pi
phase Response of 1/(1-0.9exp(-jw))
1.8
0.2
0.4
0.6
0.8
1
1.2
1.4
1.6
frequency normalized with respect to pi
1.8
phase in pi units
0.4
0.2
0
-0.2
-0.4
enter the number of frequency points over which the response is to be plotted
n = 100
enter the numerator coefficients as a vector starting from constant
a=1
Mag
nitud
e
15
10
5
phase in pi units
0
0
0.2
0.4
0.6
0.8
1.1 1.2
1.4
1 .6
frequency normalized with respect to pi
phase Response of (1/(1-0.9exp(-jw))
1.8
0.2
0.4
0.6
0.8
1
1.2
1.4
1.6
frequency normalized with respct to pi
1.8
0.4
0.2
0
-0.2
-0.4
0
2.%This program plots the frequency and phase response of a discrete system
specified by
H(z)=(1-0.9z -1)
n=input('enter the number of frequency points over which the response is to be
plotted')
w=0:2*pi/n:2*pi;
%Enter the System function with z replaced by exp(jw)
h1=zeros(1,length(w));
for i=1:length(w)
h1(i)=1-0.9*exp(-j*w(i));
end
Magh1=abs(h1);
phaseh1=angle(h1);
subplot(2,1,1)
plot(w/pi,Magh1,'k')
title('Magnitude Response of 1/(1-0.9exp(-jw))with n=100')
xlabel('frequency normalized with respect to pi')
ylabel('Magnitude')
grid
subplot(2,1,2)
plot(w/pi,phaseh1/pi,'k')
title('phase Response of 1/(1-0.9exp(-jw))with n=100')
xlabel('frequency normalized with respect to pi')
ylabel('phase in pi units')
grid
enter the number of frequency points over which the response is to be plotted100
n =100
2
Magnitude
1.5
1
0.5
phase in pi units
0.4
0.2
0.2
0.4
0.6
0.8
1
1.2
1.4
1.6
frequency normalized with respect to pi
1.8
0
-0.2
-0.4
0
0.2
0.4
0.6
0.8
1
1.2
1.4
1.6
frequency normalized with respect to pi
1.8
%This program plots the frequency and phase response of a discrete system
specified by
H(z)=(1-0.9z -1)using the In-Built function
n=input('enter the number of frequency points over which the response is to be
plotted')
a=input('Enter the denominator coefficients as a vector starting from constant')
b=input('Enter the numerator coefficients as a vector starting from constant')
[H w]=freqz(a,b,n,'whole');
magH=abs(H);
phaH=angle(H);
subplot(2,1,1)
plot(w/pi,magH,'k')
title('Magnitude Response of 1-0.9exp(-jw) with n=100')
xlabel('frequency normalised with respect to pi')
ylabel('Magnitude')
grid
subplot(2,1,2)
plot(w/pi,phaH/pi,'k')
title('phase Response of 1-0.9exp(-jw) with n=100')
xlabel('frequency normalised with respect to pi')
ylabel('phase in pi units')
grid
Enter the number of frequency points over which the response is to be plotted100
n = 100
Enter the denominator coefficients as a vector starting from constant
a=1
Enter the numerator coefficients as a vector starting from constant
b =[ 1.0000 -0.9000]
Magnitude
15
10
Phase in pi units
5
0
0
0.2
0.4
0.4
0.8 of (1-0.9exp(-w))
1
1.2
1.4
1.6
phase0.6
Response
frequency normalised with respect to pi
1.8
0.2
0
-0.2
-0.4
0
0.2
0.4
0.6
0.8
1
1.2
1.4
1.6
frequency normalised with respect to pi
1.8
-2
0 -0.810
Magnitude
phase in pi units
2
0
phase Response
the system
y(n)=0.81y(n-2)+x(n)-x(n-2)
0
0.1 of 0.2
0.3 represented
0.4
0.5 by
0.6
0.7
0.8
0.9
1
1
frequency normalised with respect to pi
0.5
0
-0.5
-1
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
frequency normalised with respect to pi
0.9
h=filter(a,b,x);
stem(n,h)
title('Unit sample response of the discrete system y(n)=x(n)+2.y(n-1) )
xlabel('Time ')
ylabel('Unit Sample Response')
axis([-1 7 0 35])
enter the coefficient vector of input starting from the coefficient of x(n) term
a=1
enter the coefficient vector of output starting from the coefficient of y(n)
term
b =1
-2
35
30
Ampl
25
itude
20
15
10
0
-1
3
Time
-2
35
Amplitude
30
25
20
15
10
0
-1
3
time
1.6667
enter the coefficient vector of output starting from the coefficient of y(n)
term
b = 1.0000 -0.7500
0.1250
Amplitude
2.5
1.5
0.5
0
-1
3
Time
5z
3
1
The Transfer function of the given system is H(z)=
3z
z 2
[1
+
]
4
8
1+
7.66
8.66
+
1
z
z 1
1
1
4
2
The poles are and . These are available in the matrix p, after executing
the residuez instruction.
The residues -7.66 and -8.66 will be available in r matrix.
The inverse Z-transform of above H(z) is h(n)= -7.66(1/4) n +8.66(1/2)n.
end
stem(n,x)
xlabel('time')
ylabel('Amplitude')
title('Inverse Z-Transfrom,i.e.Unit Sample response of given discrete system
')
axis([-1 7 0 3])
enter the numerator coefficients as a vector starting from constant
a = 1.0000
1.6667
0.1250
Amplitude
2.5
1.5
0.5
0
-1
3
time
%This program finds the unit step response of the given discrete system, expressed in
its difference Equation as y(n)-y(n-1)+0.9y(n-2)=x(n).
a=input('enter the coefficient vector of input starting from the coefficient of x(n) term')
b=input('enter the coefficient vector of output starting from the coefficient of y(n)
term')
n1=input('enter the lower limit of the range of step response')
n2=input('enter the upper limit of the range of step response')
n=[n1:n2];
x=zeros(1,length(n));
for i=1:length(n)
if n(i)>=0
x(i)=1;
end
end
h=filter(a,b,x);
stem(n,h,'k')
title('Unit step response of y(n)-y(n-1)+0.9y(n-2)=x(n) ')
xlabel('Time')
ylabel('Amplitude')
axis([-1 6 0 3])
enter the coefficient vector of input starting from the coefficient of x(n) term
a =1
enter the coefficient vector of output starting from the coefficient of y(n)
term
b = 1.0000 -1.0000
0.9000
Amplitude
2.5
1.5
0.5
0
-1
3
Time
%This program finds the unit sample response of the discrete system
expressed as y(n)+0.1y(n-1)-0.72y(n-2)=0.3x(n)-0.075x(n-2), from its unit
step response.
a=input('enter the coefficient vector of input starting from the coefficient of
x(n) term')
b=input('enter the coefficient vector of output starting from the coefficient
of y(n) term')
n1=input('enter the lower limit of the range of impulse response')
n2=input('enter the upper limit of the range of impulse response')
n=[n1:n2];
x=zeros(1,length(n));
for i=1:length(n)
if n(i)==0
x(i)=1;
end
end
h=filter(a,b,x);
x1=zeros(1,length(n));
x2=x1;
for i=1:length(n)
if n(i)>=0
x1(i)=1;
end
end
h1=filter(a,b,x1);
for i=1:length(n)
if n(i)>=1
x2(i)=1;
end
end
h2=filter(a,b,x2);
h3=h1-h2;
subplot(2,1,1)
plot(n,h)
title('Unit sample response obtained from Step response')
xlabel('Time')
ylabel('Amplitude')
axis([-1 6 -0.07 0.35])
subplot(2,1,2)
plot(n,h3)
title('Unit sample response obtained from step Response')
xlabel('Time')
ylabel('Amplitude')
axis([-1 6 -0.07 0.35])
Enter the coefficient vector of input starting from the coefficient of x(n)
term
a = 0.3000
0 -0.0750
Enter the coefficient vector of output starting from the coefficient of y(n)
term
b = 1.0000 0.1000 -0.7200
Enter the lower limit of the range of impulse response
n1 = 0
Enter the upper limit of the range of impulse response
n2 =5
Amplitude
Amplitude
-1
0.3
0.2
0.1
0
-1
Time
ylabel('Amplitude')
title('The sequence x(n) decimated by a factor of 3')
axis([-1 21 0 7])
enter the Decimation factor
N =3
Amplitude
6
4
Amplitude
2
6 0
10
Time
12
14
16
18
20
2
0
10
Time
12
14
16
18
20
Amplitude
Amplitude
-2
-4
-1
4
2
0
-2
-4
-1
Time
3. A sinusoidal signal of 10Hz frequency is to be sampled at 100 times per sec, and the
sampled signal is to be decimated by a factor of 2.
n=-T:T/fs:T;
x1= sin(2*pi*10*n*Ts);
N=input('Enter the decimation factor')
xd=[];
n1=n/N;
n11=[];
j=1;
for i=1:N:length(n)
xd(j)=x1(i);
n11(j)=n1(i);
j=j+1;
end
subplot(3,1,1)
stem(t,x)
title('The given sinusoidal signal of frequency 10Hz')
xlabel('Time')
ylabel('Amplitude')
subplot(3,1,2)
stem(n,x1)
title('The sinusoidal signal sampled at 100Hz')
xlabel('Time')
ylabel('Amplitude')
subplot(3,1,3)
stem(n11,xd)
title('The sampled signal decimated bya factor of 2')
xlabel('Time')
ylabel('Amplitude')
f = 10
enter the sampling frequency
fs = 100
Enter the decimation factor
N= 2
Amplitude
Amplitude
Amplitude
1
0
-1
-0.1
-0.08
-0.06
-0.04
-0.02
0.08
0.1
-0.08
-0.06
-0.04
-0.02
0.08
0.1
-0.04
-0.03
-0.02
-0.01
0.04
0.05
0.1
0
0.02 0.04 0.06
Time
The sinusoidal signal sampled at 100Hz
0
-0.1
-0.1
0.1
0
0.02 0.04 0.06
Time
The sampled signal decimated bya factor of 2
0
-0.1
-0.05
0
Time
0.01
0.02
0.03
x1=a.^(n*Ts);
N=input('Enter the decimation factor')
n1=n/M;
j=1;
xd=[];
n11=[];
for i=1:N:length(n)
xd(j)=x1(i);
n11(j)=n1(i);
j=j+1;
end
subplot(3,1,1)
plot(t,x)
title('The given exponential signal x(n)')
xlabel('Time')
ylabel('Amplitude')
subplot(3,1,2)
stem(n,x1)
title('The sampled exponential signal ')
xlabel('Time')
ylabel('Amplitude')
subplot(3,1,3)
stem(n11,xd)
title('Decimated signal')
xlabel('Time')
ylabel('Amplitude')
Amplitude
Amplitude
Amplitude
1
0.5
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
Time
The sampled exponential signal
0.8
0.9
0.1
0.2
0.3
0.4
0.5
0.6
Time
Decimated signal
0.7
0.8
0.9
0.05
0.1
0.15
0.2
0.35
0.4
0.45
0.5
1
0.5
0
1
0.5
0
0.25
Time
0.3
stem(t1,y)
title('The Decimated signal ')
xlabel('Time')
ylabel('Amplitude')
axis([-0.1 2.1 -2 2])
Enter the Decimation Factor
N =2
Amplitude
2
1
0
-1
-2
0.2
0.4
0.6
0.2
0.4
0.6
Amplitude
0.8
1
1.2
1.4
Time
The Decimated signal
1.6
1.8
1.6
1.8
1
0
-1
-2
0.8
1
Time
1.2
1.4
6.Let the given sequence be x(n)=2(n)+4(n-1)+7(n-3)+(n-4)+4(n5)+3N-6). Down sample the sequence by a factor of 2.
x=[2 4 7 1 4 3];
n=[0 1 2 3 4 5];
N=input('Enter the downsampling Factor')
x1=downsample(x,N);
n1=downsample(n,N);
subplot(2,1,1)
stem(n,x)
title('The given sequence x(n)')
xlabel('Time')
ylabel('Amplitude')
axis([-1 6 0 8])
subplot(2,1,2)
stem(n1,x1)
title('Down sampled sequence ')
xlabel('Time')
ylabel('Amplitude')
axis([min(n1)-1 max(n1)+1 0 8])
Amplitude
8
6
4
2
0
-1
Amplitude
3
Time
Down sampled sequence
6
4
2
0
-1
2
Time
Amplitude
6
4
2
0
15
Time
The Interpolated sequence
6
Amplitude
10
4
2
0
10
15
20
Time
25
30
35
40
2. Interpolate the sequence x(n)=n, for n>0, and zero for otherwise by a
factor of 2. The sequence to be obtained is y(n)=x(n/2).
Since Interpolation factor is 2, One zero is introduced between any two
adjacent samples of x(n).
Amplitude
10
0
-1
Amplitude
10
5
6
Time
Interpolated sequence
10
Time
10
12
14
16
18
3. A sinusoidal signal of 5Hz frequency is to be sampled at 20 times per sec, and the
sampled signal is to be interpolated by a factor of 2.
stem(t,x)
title('The given sinusoidal signal of frequency 10Hz')
xlabel('Time')
ylabel('Amplitude')
subplot(3,1,2)
stem(n,x1)
title('The sinusoidal signal sampled at 30Hz')
xlabel('Time')
ylabel('Amplitude')
subplot(3,1,3)
stem(n1,xI)
title('The sampled signal Interpolated by a factor of 2')
Amplitude
Amplitude
1
0
-1
-0.2
-0.15
-0.1
-0.05
0.15
0.2
-0.15
-0.1
-0.05
0.15
0.2
-0.1
-0.05
0.15
0.2
0
0.05
0.1
Time
The sinusoidal signal sampled at 20Hz
0
-1
-0.2
1
0
0.05
0.1
Time
The sampled signal Interpolated by a factor of 2
0
-1
-0.2
-0.15
0.05
0.1
Amplitude
2
1
0
-1
-2
0.2
0.4
0.6
0.2
0.4
0.6
Amplitude
0.8
1
1.2
1.4
Time
The Interpolated signal
1.6
1.8
1.6
1.8
1
0
-1
-2
0.8
1
Time
1.2
1.4
This function increases the sampling rate of the sequence x, by inserting (n1) zeros between its samples.
4. Interpolate the sequence x(n)= (n-1)+2.(n-2)+3(n-3)+4(n-4)+5(n5)+6(n-6) +(n-8) +2(n-9) +3(n-10)+4(n-11)+5(n-12)+6(n-13)+(n15)+2(n-16)+3(n-17)+4(n-18)+
5(n-19) +6(n-20), by a
factor of 2.
x=[0 1 2 3 4 5 6 0 1 2 3 4 5 6 0 1 2 3 4 5 6];
n=[0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20];
N=input('Enter the Interpolation factor')
x1=upsample(x,N);
n1=0:N*max(n)+1;
subplot(2,1,1)
stem(n,x)
title('The given sequence x(n)')
xlabel('Time')
ylabel('Amplitude')
axis([-1 21 0 7])
subplot(2,1,2)
stem(n1,x1)
title('upsampled sequence ')
xlabel('Time')
ylabel('Amplitude')
axis([-1 42 0 7])
Enter the Interpolation factor
N =2
Amplitude
6
4
2
0
0
10
12
14
Time
upsampled sequence
16
18
20
Amplitude
6
4
2
0
0
10
15
20
Time
25
30
35
40
h1(k
)
h1(k
)
Interpolator
Decimator
The two LPFs h1(k) and h2(k) can be combined into a single filter, since they
are in cascade and have a common sampling frequency to give the
generalized sampling rate converter.
x(n)
y(m)
Fs
IFs/D
w(i)
v(i)
h(k)
IFs
IFs
It is given by
1
Pxx ( f )= x ( n ) . e j 2 fn 2 .
N i=0
Pxx
N1
( j 2 n)
k
1
N
= x (n) . e
2 , where k=0,1,2,--N
N i=0
( )
N-1.
If more samples are required in the frequency domain, the length of the
sequence can be increased by zero padding. Let the new length be L.
The PSD is
Pxx
L1
( j2 n)
k
1
L
= x ( n ) . e
2 , where k=0,1,2,--- L-1.
L L i=0
()
X ( k ) 2
1
, where
** The following program finds the 8 Point, 16 Point and 32 Point DFT of the
sequence x(n) of length n=8, and the corresponding Power Spectrum will be
plotted.
Power Spectrum
6
4
2
Power Spectrum(dB)
20
3
4
5
6
Frequency Variable K
Power Spectrum of the given sequence computed from 8 Point DFT
0
-20
-40
-60
3
4
Frequency Variable K
Power Spectrum
Power Spectrum of length=8 sequence computed from 32 Point DFT using zero padding
1.5
1
0.5
0
15
20
25
30
35
Frequency Variable K
Power Spectrum of length=8 sequence computed from 32 Point DFT using zero padding
50
Power Spectrum(dB)
10
10
0
-50
-100
15
20
Frequency Variable K
25
30
35
Power Spectrum
8
6
4
2
Power Spectrum(dB)
20
10
15
20
25
30
35
Frequency Variable K
Power Spectrum of length=32 sequence computed from 32 Point DFT
10
0
-20
-40
15
20
Frequency Variable K
25
30
35
jn
x ( n ) .e
n=
)=
2
N , and X(k) is computed at k=0,1,2,N-1 and is
N 1
X(k)=
If
WN
= e
(2N )
j(
x ( n) . e
2
)nk
N
n=0
, where, k=0,1,2,N-1.
x( n)W nkN
n=0
, where, k=0,1,2,N-1.
The sequence x(n) can be obtained from X(k), by taking the Inverse Discrete
1
Fourier Transform (IDFT), and is given by x(n)= N
N 1
X (k ) W nk
N
k=0
n=0,1,2,N-1.
1. Find the 4 point DFT of the sequence x(n)= [ (n), (n-3)].
The given sequence is x= [1 0 0 1] and n=[0 1 2 3].
x=input('enter the given sequence');
n=input('Enter the time indices')
N=input('Enter the length of the DFT sequence required')
k=n;
nk=zeros(N,N);
WN=exp(-j*2*pi/N);
DF=[];
twid=[];
for i=1:length(k)
for m=1:length(n)
nk(i,m)=n(i)*k(m);
twid(i,m)=WN^nk(i,m);
end
, where,
end
DF=zeros(1,N);
for i=1:length(DF)
for m=1:length(DF)
DF(i)=DF(i)+x(m)*twid(i,m);
end
end
magDF=abs(DF);
phaDF=angle(DF)*180/pi;
disp('The DFT of the given sequence is ')
disp(DF)
disp('The corresponding Magnitude Vector is ')
disp(magDF)
disp('The corresponding Phase Vector is')
disp(phaDF)
subplot(2,1,1)
stem(k,magDF)
title('Magnitude Spectrum')
xlabel('k')
ylabel('Magnitude')
axis([-1 N 0 max(magDF)+1])
subplot(2,1,2)
stem(k,phaDF)
title('Phase Spectrum')
xlabel('k')
ylabel('Phase')
axis([-1 N min(phaDF) max(phaDF)])
3]
1.0000 + 1.0000i
1.4142
0.0000
1.4142
Magnitude Spectrum
Magnitude
3
2
1
0
-1
-0.5
0.5 Phase
1 Spectrum
1.5
2
k
Phase
40
20
2.5
3.5
0
-20
-40
-60
-80
-1
-0.5
0.5
1.5
k
2.5
3.5
n=
[0
3]
-0.0000 - 0.0000i
0.0000
0.0000
0.0000
Magnitude Spectrum
Magnitude
5
4
3
2
Phase
1
0
0
-1
-0.5
0.5
Phase Spectrum
1
1.5
2
k
2.5
3.5
-50
-100
-1
-0.5
0.5
1.5
k
2.5
3.5
nk=zeros(N,N);
WN=exp(-j*2*pi/N);
IDF=[];
twidd=[];
for i=1:length(k)
for m=1:length(n)
nk(i,m)=n(i)*k(m);
twidd(i,m)=WN^-nk(i,m);
end
end
IDF=zeros(1,N);
for i=1:length(IDF)
for m=1:length(IDF)
IDF(i)=IDF(i)+X(m)*twidd(i,m);
end
end
IDFF=IDF/N;
disp('The IDFT of the given sequence X(k) is ')
disp(IDFF)
stem(n,IDFF)
title('The Time domain sequence obtained')
xlabel('n-->')
ylabel('Amplitude-->')
axis([-1 N+1 0 max(IDFF)+0.2])
1.0000 + 1.0000i
1.0000 - 1.0000i]
Ampl
0.8
itude
0.6
0.4
0.2
0
-1
2
n-->
4.Find the Time domain representation of the sequence whose 4 point DFT is
X(k)=[3.8428, 0.3-j2.8572,-2.4428, 0.3+j2.8572].
enter the given sequence
X = [3.8428
0.3000 - 2.8572i
-2.4428
0.3000 + 2.8572i]
2.5
Ampl
itude
-
1.5
0.5
0
-1
2
n-->
phaDF=angle(DF)*180/pi;
disp('The DFT of the given sequence is ')
disp(DF)
disp('The corresponding Magnitude Vector is ')
disp(magDF)
disp('The corresponding Phase Vector is')
disp(phaDF)
subplot(2,1,1)
stem(k,magDF)
title('Magnitude Spectrum')
xlabel('k')
ylabel('Magnitude')
axis([-1 N 0 max(magDF)+1])
subplot(2,1,2)
stem(k,phaDF)
title('Phase Spectrum')
xlabel('k')
ylabel('Phase')
axis([-1 N min(phaDF) max(phaDF)])
N =8
The DFT of the given sequence is
4.0000 1.0000 - 2.4142i
-0.0000 - 0.0000i
1.0000 - 0.4142i
0 - 0.0000i
1.0000 + 0.4142i
0.0000 - 0.0000i
1.0000 +
2.4142i
The corresponding Magnitude Vector is
4.0000
2.6131
0.0000
1.0824
0.0000
1.0824
0.0000
2.6131
Magnitude Spectrum
Magnitude
5
4
3
2
1
Phase
50
0
-1
Phase Spectrum
2
3
4
k
0
-50
-100
-1
x= cos(0.48*n*pi)+cos(0.52*n*pi);
%Take only 10 samples of x and find the corresponding 10 point DFT.
n1=0:9;
x1=x(1:10);
N=input('Enter the length of the DFT sequence required')
k=n1;
n1k=zeros(N,N);
WN=exp(-j*2*pi/N);
DF=[];
twid=[];
for i=1:length(k)
for m=1:length(n1)
n1k(i,m)=n1(i)*k(m);
twid(i,m)=WN^n1k(i,m);
end
end
DF=zeros(1,N);
for i=1:length(DF)
for m=1:length(DF)
DF(i)=DF(i)+x1(m)*twid(i,m);
end
end
magDF=abs(DF);
disp('The DFT of the given sequence is ')
disp(DF)
disp('The corresponding Magnitude Vector is ')
disp(magDF)
subplot(2,1,1)
stem(n,x)
title('The given sequence')
xlabel('n')
ylabel('Magnitude')
axis([-1 N -3 3])
subplot(2,1,2)
%Plotting the result with respect to 2*pi*k/N. Then, normalize wrt pi
plot(k*2/N,magDF)
stem(k,magDF)
title('Magnitude Spectrum')
xlabel('k')
ylabel('Magnitude')
axis([-1 N min(magDF)-1 max(magDF)+1])
required
2.2867
6.2141
6.2141
2.2867
1.8460
2.2867
6.2141
6.2141
Magnitude
2
0
-2
-1
5
6
n
Magnitude Spectrum
10
10
Magnitude
6
4
2
-1
Magnitude
2
0
-2
-1
5
6
n
Magnitude Spectrum
Magnitude
10
6
4
2
0
0.2
0.4
0.6
0.8
1
1.2
K in terms of pi units
1.4
1.6
1.8
Magnitude
2
0
-2
-1
5
6
n
Magnitude Spectrum
Magnitude
10
6
4
2
0
0.2
0.4
0.6
0.8
1
1.2
K in terms of pi units
1.4
1.6
1.8
1.5052
0.5984
0.6496
1.7243
2.2867
2.0294
0.8586
1.2201
3.6997
6.2141
8.2494
9.3857
9.3857
8.2494
6.2141
3.6997
1.2201
0.8586
2.0294
2.2867
1.7243
0.6496
0.5984
1.5052
1.8460
1.5052
0.5984
0.6496
1.7243
2.2867
2.0294
0.8586
1.2201
3.6997
6.2141
8.2494
9.3857
9.3857
8.2494
6.2141
3.6997
1.2201
0.8586
2.0294
35
40
45
50
35
40
45
50
2.2867
1.7243
0.6496
0.5984
1.5052
Magnitude
2
0
-2
0
10
15
Magnitude
10
20
25
30
n
Magnitude Spectrum
10
15
20
25
k
30
Magnitude
2
0
-2
0
10
15
Magnitude
10
20
25
30
n
Magnitude Spectrum
35
40
45
50
35
40
45
50
10
15
20
25
k
30
Magnitude
2
0
-2
0
10
15
Magnitude
10
20
25
30
n
Magnitude Spectrum
35
40
45
50
0.8
1
1.2
K in terms of pi units
1.4
1.6
1.8
0.2
0.4
0.6
For the same sequence, find 100 point DFT, using zero padding.
The given sequence
Magnitude
2
0
-2
0
Magnitude
10
10
20
30
0.2
0.4
0.6
40
50
60
70
80
90
n
Magnitude Spectrum from 100 Point DFT using zero padding
100
0.8
1
1.2
K in terms of pi units
1.4
1.6
1.8
c)To get better spectral information, take the first 100 samples of the sequence, and find the
100 Point DFT of the sequence.
n=0:1:99;
x= cos(0.48*n*pi)+cos(0.52*n*pi);
%Take only 100 samples of x and find the corresponding 100 point DFT.
n1=0:99;
x1=x(1:100);
N=input('Enter the length of the DFT sequence required')
k=n1;
n1k=zeros(N,N);
WN=exp(-j*2*pi/N);
DF=[];
twid=[];
for i=1:length(k)
for m=1:length(n1)
n1k(i,m)=n1(i)*k(m);
twid(i,m)=WN^n1k(i,m);
end
end
DF=zeros(1,N);
for i=1:length(DF)
for m=1:length(DF)
DF(i)=DF(i)+x1(m)*twid(i,m);
end
end
magDF=abs(DF);
disp('The DFT of the given sequence is ')
disp(DF)
disp('The corresponding Magnitude Vector is ')
disp(magDF)
subplot(2,1,1)
stem(n1,x1)
title('The given sequence')
xlabel('n')
ylabel('Magnitude')
axis([-1 N -3 3])
subplot(2,1,2)
%Plotting the result with respect to 2*pi*k/N. Then, normalize wrt pi.
plot(k*2/N,magDF)
title('Magnitude Spectrum from 100 Point DFT, taking 100 samples of x(n)')
xlabel('K in terms of pi units')
ylabel('Magnitude')
Magnitude
2
0
-2
0
Magnitude
60
10
20
30
0.2
0.4
0.6
40
50
60
70
80
90
100
n
Magnitude Spectrum from 100 Point DFT, taking 100 samples of x(n)
40
20
0
0.8
1
1.2
K in terms of pi units
1.4
1.6
1.8
Magnitude
2
0
-2
0
Magnitude
60
10
20
30
0.2
0.4
0.6
40
50
60
70
80
90
100
n
Magnitude Spectrum from 100 Point DFT, taking 100 samples of x(n)
40
20
0
0.8
1
1.2
K in terms of pi units
1.4
1.6
1.8
The above plot clearly shows that, there are two frequencies, which are very close to each
other. This is the high resolution spectrum of x(n).
It can be observed that, padding more zeros to the 100-point sequence, will result in a
smoother rendition of the above spectrum, but, will not reveal any new information.
Consider 200 point DFT of the above 100 point sequence, by using zero padding.
Magnitude
2
0
-2
0
20
40
60
0.2
0.4
0.6
80
100
120
140
160
180
200
n
Magnitude Spectrum from 200 Point DFT, by zero padding for 100 samples of x(n)
60
Magnitude
40
20
0
0.8
1
1.2
K in terms of pi units
1.4
1.6
1.8
Magnitude
2
0
-2
100
120
140
160
180
200
n
Magnitude Spectrum from 200 Point DFT, by zero padding for 100 samples of x(n)
60
Magnitude
20
40
60
0.2
0.4
0.6
80
40
20
0
0.8
1
1.2
K in terms of pi units
1.4
1.6
1.8
The spectrum is repeating, since the signal is also repeating. The given sequence x(n) is
Magnitude
-1
-2
-3
20
40
60
80
100
n
120
140
160
180
200
Baseband signal
2
1.5
1
Amplitude
0.5
0
-0.5
-1
-1.5
-2
50
100
150
Time
200
250
300
200
250
300
Carrier signal
1
0.8
0.6
Amplitude
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
50
100
150
Time
Modulated signal
2
1.5
1
Amplitude
0.5
0
-0.5
-1
-1.5
-2
50
100
150
Time
200
250
300
Magnitude
2
0
-2
0
Magnitude
40
20
40
60
80
100
120
n
Magnitude Spectrum of 128 Point DFT, taking 128 samples of y(n)
30
20
10
0
0.2
0.4
0.6
0.8
1
1.2
K in terms of pi units
1.4
1.6
1.8
Magnitude
2
0
-2
0
Magnitude
40
20
40
60
80
100
120
n
Magnitude Spectrum of 128 Point DFT, taking 128 samples of y(n)
30
20
10
0
0.2
0.4
0.6
0.8
1
1.2
K in terms of pi units
1.4
1.6
1.8
The above spectrum shows that there are 4 frequencies, which are available after
multiplication.
Consider 256 point DFT of the same sequence of length 127, using zero padding.
n=0:1:127;
x=cos(2*pi*n/128)+cos(2*pi*5*n/128);
xc=cos(2*pi*50*n/128);
y=x.*xc;
%Take 128 samples of x and find the corresponding 128 point DFT.
n1=0:255;
y1=[y(1:128) zeros(1,128)];
N=input('Enter the length of the DFT sequence required')
k=n1;
n1k=zeros(N,N);
WN=exp(-j*2*pi/N);
DF=[];
twid=[];
for i=1:length(k)
for m=1:length(n1)
n1k(i,m)=n1(i)*k(m);
twid(i,m)=WN^n1k(i,m);
end
end
DF=zeros(1,N);
for i=1:length(DF)
for m=1:length(DF)
DF(i)=DF(i)+y1(m)*twid(i,m);
end
end
magDF=abs(DF);
subplot(2,1,1)
stem(n1,y1)
title('The given sequence')
xlabel('n')
ylabel('Magnitude')
axis([-1 N -3 3])
subplot(2,1,2)
%Plotting the result with respect to 2*pi*k/N. Then, normalize
wrt pi.
plot(k*2/N,magDF)
title('Magnitude Spectrum of 128 Point DFT, taking 128 samples of
y(n)')
xlabel('K in terms of pi units')
ylabel('Magnitude')
Magnitude
2
0
-2
0
Magnitude
40
50
100
150
200
250
n
Magnitude Spectrum of 128 Point DFT, taking 128 samples of y(n)
30
20
10
0
0.2
0.4
0.6
0.8
1
1.2
K in terms of pi units
1.4
1.6
1.8
Magnitude
2
0
-2
0
Magnitude
40
50
100
150
200
250
n
Magnitude Spectrum of 128 Point DFT, taking 128 samples of y(n)
30
20
10
0
0.2
0.4
0.6
0.8
1
1.2
K in terms of pi units
1.4
1.6
1.8
This shows that, no new information about the signal is revealed, except smoothing the
spectrum.
c) Find the 128 point DFT of y(n), for 0n99. Here, zero padding is to be done.
The given sequence
Magnitude
2
0
-2
0
Magnitude
30
20
40
60
80
100
120
n
Magnitude Spectrum of 128 Point DFT, taking 128 samples of y(n)
20
10
0
0.2
0.4
0.6
0.8
1
1.2
K in terms of pi units
1.4
1.6
1.8
Magnitude
2
0
-2
0
Magnitude
30
20
40
60
80
100
120
n
Magnitude Spectrum of 128 Point DFT, taking 128 samples of y(n)
20
10
0
0.2
0.4
0.6
0.8
1
1.2
K in terms of pi units
1.4
1.6
1.8
2
.
N
N 1 1
ms
rm
} W N }W N , for 0l N 11 , 0r N 21 , 0m N 21 ,
l =0
N 21
m=0
0s
N 11
The N-Point FFT of a given sequence x(n) can be computed using the Built-in
function fft(x,n), where x is the given sequence and n is the length of the
DFT sequence required.
clear all
x=input('Enter the given sequence')
n=input('Enter the Time Indices')
N=input('Enter the length of the DFT sequence')
%Represent N=N1.N2
N1=input('Enter the Number of rows')
N2=input('Enter the Number of Columns')
%Zero Padding
if N>length(x)
for i=length(x)+1:N
x(i)=0;
n(i)=n(i-1)+1;
end
end
a=1;
x1=[];
w=[];
w2(r,m)=exp(-j*(2*pi/N2)*(r-1)*(m-1));
end
end
Column DFT
X1=G1'*w2;
X=reshape(X1,1,N1*N2);
disp('The DFT of the given sequence is')
disp(X)
%Computation of fft using built in Function.
Y=fft(x,N)
Disp(The DFT of the given sequence computed using Built-in function is)
Disp(Y)
-1
0]
3]
2.0000 + 0.0000i
2.0000 + 0.0000i
n =[0
1
1
1
2
1
3
1]
4
5]
1]
3]
M 1
.
2
M 1
, is an integer
2
M 1
, is not an integer
2
There is a second Type of Linear Phase FIR filter, if the phase response
j
arg[H( e )] = , which is a straight line, but not through the origin.
arg[ H (e j)]
= - , is a
M 1
,
=
2
2 . This means that the impulse response h(n) is anti
symmetric. The index of symmetry is still =
M 1
.
2
*M odd: =
M 1
2
*M Even : =
is an integer .
M 1
2
is not an integer.
When the cases of Symmetry and Anti-symmetry are combined with Odd and
Even M, there will be four types of Linear Phase FIR filters.
Frequency Response of the Above Filters:
j
The Frequency Response , H( e ) =
M 1
H r ( e j )e j( ) , =
.
2 , =
2
-----(1)
Here,
response function.
The amplitude response function is a real function, but, unlike the magnitude
response, which is always positive, the amplitude response may be both
positive and negative.
The phase response associated with the magnitude response is a
discontinuous function, while that associated with the amplitude response is
a continuous linear function.
Type-1:Linear Phase FIR Filter: Symmetrical Impulse Response: M
Odd:
In this case, =0, =
M 1
2
1).
j
H( e ) =
M 1
2
a ( n ) .Cosn
n=0
. e j(M 1)/2
---------(2)
a(n)=2. h(
M 1
, which is the
2
M 1
n , 1n
2
M 3
.
2
M1
2
H r ( ) = a ( n ) . Cosn .
n=0
M 1
2
0n(M-1).
n
b ( n ) . cos { (
j
H( e ) =
1
)}
2
M
2
---------(3)
n=1
M
Where b(n)= 2h( 2 n , for n= 1,2,---M/2.
n
b ( n ) . cos { (
By Comparing (1) and (3),
H r ( ) =
M
2
1
)}
2
n=1
At =,
H r ( ) =0, regardless of b(n) or h(n). Thus, this type of filter can not
M 1
2
0n(M-1), and h(
H( e
)=
M 1
=0.
2
M 1
2
( M1)
j[
]
2
2
c ( n ) . Sinn . e
n=1
M 1
n ,
2
M 1
2
H r ( ) = c ( n ) . Sinn.
n=1
0n(M-1), and h(
M 1
2
M 1
=0.
2
n
d ( n ) .sin {(
j
H( e ) =
M
2
1
)}
2
, where d(n)= 2h(
M
n ,
2
n=1
n
d ( n ) .sin {(
for n= 1,2,---M/2, and
1
)}
2
M
2
H r ( ) =
n=1
1.To find and to Plot the Amplitude Response of Various Linear Phase FIR
Filters:
function[Hr,a,w,M,L,pha]=Type1(h,w1)
M=length(h);
L=(M-1)/2;
a=[h(L+1) 2*h(L:-1:1)];
n=[0:1:L];
w=[0:1:w1]'*pi/w1;
Hr=cos(w*n)*a';
pha=[-w*(M-1)/2];
function[Hr,a,w,M,L,pha]=Type2(h,w1)
M=length(h);
L=M/2;
a=2*[h(L:-1:1)];
n=[1:1:L];
n=n-0.5;
w=[0:1:w1]'*pi/w1;
Hr=cos(w*n)*a';
pha=[-w*(M-1)/2];
%Save the function
function[Hr,a,w,M,L,pha]=Type3(h,w1)
M=length(h);
L=(M-1)/2;
a=[2*h(L+1:-1:1)];
n=[0:1:L];
w=[0:1:w1]'*pi/w1;
Hr=sin(w*n)*a';
pha=[(pi/2)-w*(M-1)/2];
%save the function
function[Hr,a,w,M,L,pha]=Type4(h,w1)
M=length(h);
L=M/2;
a=2*[h(L:-1:1)];
n=[1:1:L];
n=n-0.5;
w=[0:1:500]'*pi/500;
Hr=sin(w*n)*a';
pha=[(pi/2)-w*(M-1)/2];
%save the function
end
end
if rem(length(h),2)==0
p=1;
else
p=0;
end
subplot(4,1,1)
stem(0:M-1,h)
title('Impulse Response sequence of the given linear Phase System')
xlabel('n')
ylabel('h(n)')
axis([-1 length(h)+1 min(a)-1 max(a)+1])
subplot(4,1,2)
stem(p:L,a)
title('a(n) coefficients')
xlabel('n')
ylabel('a(n)')
axis([-1 L+1 min(a)-1 max(a)+1])
subplot(4,1,3)
plot(w/pi,Hr)
grid
title('Amplitude Response')
xlabel('Frequency in pi units')
ylabel('Hr')
subplot(4,1,4)
zplane(h,1)
title('Pole-Zero Plot of the given Linear Phase FIR System')
a)Plot the Amplitude Response of the linear Phase FIR system with
Impulse Response h(n)={-4,1,-1,-2,5,6,5,-2,-1,1,-4}
The given system is a Type-1 FIR Filter, where M=11(odd), and h(n)
is symmetric with respect to = (11-1)/2=5
-4
-1
-2
-2
-1
-4
The given system is a Type-1 FIR Filter, where M=11(odd), and h(n)
is symmetric with respect to = (12-1)/2=5.
h(n)
4
2
0
-2
-4
-6
-8
0
10
12
a(n) coeffcients
10
8
6
4
a(n)
2
0
-2
-4
-6
-8
-1
Amplitude Response
20
15
10
Hr
5
0
-5
-10
-15
0.1
0.2
0.3
0.4
0.5
0.6
Frequency in pi units
0.7
0.8
0.9
2
0
-2
phase
-4
-6
-8
-10
-12
-14
-16
0.1
0.2
0.3
0.4
0.5
0.6
frequency in pi units
0.7
0.8
0.9
Imaginary Part
0.5
10
-0.5
-1
-1.5
-1
-0.5
0
Real Part
0.5
1.5
b)Plot the Amplitude Response of the linear Phase FIR system with
Impulse Response h(n)={-4,1,-1,-2,5,6,6,5,-2,-1,1,-4}.
The given system is a Type-2 FIR Filter, where M=12(even), and
h(n) is symmetric with respect to = (12-1)/2=5.5.
-4
-1
-2
-2
-1
h(n)
4
2
0
-2
-4
-6
-8
0
6
n
10
12
-4
a(n) coeffcients
12
10
8
6
a(n)
4
2
0
-2
-4
-6
-8
-1
3
n
Amplitude Response
25
20
15
10
Hr
5
0
-5
-10
-15
-20
0.1
0.2
0.3
0.4
0.5
0.6
Frequency in pi units
0.7
0.8
0.9
2
0
-2
phase
-4
-6
-8
-10
-12
-14
-16
0.1
0.2
0.3
0.4
0.5
0.6
frequency in pi units
0.7
0.8
Imaginary Part
0.5
11
-0.5
-1
-1
-0.5
0
0.5
Real Part
1.5
0.9
c) Plot the Amplitude Response of the linear Phase FIR system with
Impulse Response h(n)={-4,1,-1,-2,5,0,-5,2,1,-1,4}.
The given system is a Type-3 FIR Filter, where M=11(odd), and h(n)
is symmetric with respect to = (11-1)/2=5.
Enter the Impulse response Sequence
h = -4
-1
-2
-5
-1
h(n)
4
2
0
-2
-4
-6
-8
0
10
12
a(n) coefficients
10
8
6
a(n)
4
2
0
-2
-4
-6
-8
-1
Amplitude Response
25
20
15
Hr
10
5
0
-5
-10
0.1
0.2
0.3
0.4
0.5
0.6
Frequency in pi units
0.7
0.8
0.9
2
0
-2
phase
-4
-6
-8
-10
-12
-14
-16
0.1
0.2
0.3
0.4
0.5
0.6
frequency in pi units
0.7
0.8
0.9
Imaginary Part
0.5
10
-0.5
-1
-1.5
-1
-0.5
0
Real Part
0.5
1.5
d) Plot the Amplitude Response of the linear Phase FIR system with
Impulse Response h(n)={-4,1,-1,-2,5,6,-6,-5,2,1,-1,4}.
-4
-1
-2
-6
-5
h(n)
4
2
0
-2
-4
-6
-8
0
6
n
10
12
-1
a(n) coefficients
12
10
8
6
a(n)
4
2
0
-2
-4
-6
-8
-1
3
n
Amplitude Response
25
20
15
Hr
10
5
0
-5
-10
0.1
0.2
0.3
0.4
0.5
0.6
Frequency in pi units
0.7
0.8
0.9
2
0
-2
phase
-4
-6
-8
-10
-12
-14
-16
0.1
0.2
0.3
0.4
0.5
0.6
frequency in pi units
0.7
0.8
0.9
Imaginary Part
0.5
11
-0.5
-1
-1.5
-1
-0.5
0
Real Part
0.5
1.5
magnitude gain, and linear phase characteristics over its pass band, and
zero response over its stop Band.
An ideal LPF, of band width
, is given by
H d (e ) = 1.
e j for c
= 0 for
where,
for n
1
hd ( n )=
H d ( e j ) . ( e jn ) .d
,wc
, for n= .
hd ( n ) ,
obtain a causal and linear phase FIR filter h(n) of length M, we must have
h(n)= hd ( n ) , for 0nM-1
=0 else
M 1
where, and =
.
2
This operation is called Windowing.
hd ( n ) ,
and a
2. Hamming Window:
W(n)= 0.54 0.46
cos
n
( N2 1
) for 0 n N 1
= 0 otherwise.
3.Hanning Window:
W(n)= 0.5 0.5
cos
= 0 otherwise.
4.Blackman Window:
W(n)= 0.42 0.5
cos
n
n
( N2 1
)+0.08 cos ( N4 1
) for 0 n N 1
=0 otherwise.
n
( N2 1
) for 0 n N 1
5.Bartlett(Triangular) Window:
W(n)=
|
1
N1
2
for 0 n N 1
N 1
2 n
=0 otherwise.
Commonly used window functions characteristics:
Window
Name
Rectangular
Bartlett
Hanning
Hamming
Blackman
Transition width
Approxima Exact
te
Value
4/M
1.8/M
8/M
6.1/M
8/M
6.2/M
8/M
6.6/M
12/M
11/M
Min. Stop
Band
Attenuation.
21 dB
25dB
44dB
53dB
74dB
xlabel('n')
ylabel('w(n)')
%Computation of Amplitude response of Rectangular Window
%using expression for Frequency Response
w=linspace(0,pi,512);
for k=1:m
for l=1:length(w)
if n(k)==0||w(l)==0
h(l)=1;
else
h(l)=m*((sin(n(k)*w(l))/2)/(sin(n(k))/2))*(exp(-i*(w(l)*((m-1)/2))));
end
end
end
subplot(2,1,1)
plot(w/pi,20*log10(abs(h)))
grid
xlabel('w/pi Units')
ylabel('Amplitude Response')
axis([0 1 -40 40])
%Computation of Amplitude response of Rectangular Window
%using Built-in function
[FREWR1,w]=freqz(WR,1,512);
subplot(2,1,2)
plot(w/pi,20*log10(abs(FREWR1)))
grid
xlabel('w/pi Units')
ylabel('Amplitude Response')
1.Design a Low Pass FIR filter for N=4 and Wc=0.4 rad, using
hamming Window
%Design of the required filter using hamming window
N=input('enter the length of the filter')
Wc=input('enter the digital cut off frequency')
n=0:N-1;
%Computation of window coefficients
w=0.54-0.46*cos((2*pi*n)/(N-1));
alpha=(N-1)/2;
%Computation of coefficients of Ideal LPF
for i=0:N-1
if i==alpha
hd(i+1)=Wc/pi;
else
hd(i+1)=sin(Wc*(i-alpha))/(pi*(i-alpha));
end
end
%hn will be filter coefficients of the windowed filter
hn=hd.*w;
%Computation of filter coefficients using built-in function.
%The Built-in function gives the window coefficients in a column vector
w1=hamming(N);
hn1=hd.*w1';
disp('Filter coefficients computed using window function')
disp(hn)
disp('Filter coefficients computed using Built-in function')
disp(hn1)
enter the length of the filter N =4
enter the digital cut off frequency Wc = 0.4000
Filter coefficients computed using window function
0.0096
0.0974
0.0974
0.0096
0.0974
0.0974
0.0096