Table of Contents
1 Experiment No.1: Verification of Sampling Theorem both in time and frequency domains ....................................... 5
1.1 Objective: To verify the sampling theorem for a signal of given frequency ........................................................ 5
1.2 Theory: ................................................................................................................................................................. 5
1.3 ALGORITHM: ..................................................................................................................................................... 6
1.4 MATLAB PROGRAM: ....................................................................................................................................... 7
1.5 RESULT: .............................................................................................................................................................. 9
1.6 EXPECTED WAVEFORM: ................................................................................................................................ 9
1.7 Exercise Problems: ............................................................................................................................................. 10
1.8 CONCLUSION: ................................................................................................................................................. 10
2 Experiment No.2: Evaluation of impulse response of a system ................................................................................. 11
2.1 Objective: ........................................................................................................................................................... 11
2.2 Theory: ............................................................................................................................................................... 11
2.3 Using the command deconv( ) (For Discrete time system): ............................................................................... 11
2.4 By solving the difference/differential equation: ................................................................................................. 12
2.5 ALGORITHM 1: ................................................................................................................................................ 13
2.5.1 MATLAB PROGRAM 1:........................................................................................................................... 13
2.5.2 RESULT: .................................................................................................................................................... 14
2.5.3 EXPECTED WAVEFORM: ...................................................................................................................... 14
2.6 ALGORITHM 2: ................................................................................................................................................ 14
2.6.1 MATLAB PROGRAM 2:........................................................................................................................... 15
2.6.2 RESULT: .................................................................................................................................................... 15
2.6.3 EXPECTED WAVEFORM: ...................................................................................................................... 15
2.7 Algorithm 3: ....................................................................................................................................................... 16
2.7.1 MATLAB PROGRAM 3:........................................................................................................................... 16
2.7.2 RESULT: .................................................................................................................................................... 17
2.7.3 EXPECTED WAVEFORM: ...................................................................................................................... 17
2.8 Exercise Problems: ............................................................................................................................................. 17
2.9 CONCLUSION: ................................................................................................................................................. 17
3 Experiment No.3: To perform linear convolution of given sequences ....................................................................... 18
3.1 Objective: To obtain the convolution of two finite duration sequences ............................................................. 18
3.2 Theory: ............................................................................................................................................................... 18
3.3 ALGORITHM 1: ................................................................................................................................................ 18
3.4 MATLAB PROGRAM 1: .................................................................................................................................. 18
3.5 RESULT: ............................................................................................................................................................ 19
3.6 EXPECTED WAVEFORM: .............................................................................................................................. 19
3.7 ALGORITHM 2: ................................................................................................................................................ 20
3.8 MATLAB PROGRAM 2: .................................................................................................................................. 20
3.9 RESULT: ............................................................................................................................................................ 21
3.10 EXPECTED WAVEFORM: .............................................................................................................................. 21
3.11 ALGORITHM 3: ................................................................................................................................................ 21
3.12 MATLAB PROGRAM 3: .................................................................................................................................. 22
3.13 EXPECTED WAVEFORM: .............................................................................................................................. 23
3.14 Exercise Problems .............................................................................................................................................. 23
3.15 CONCLUSION: ................................................................................................................................................. 23
4 Experiment No.4: To perform circular convolution of given sequences using (a) the convolution summation formula
(b) the matrix method and (c) Linear convolution from circular convolution with zero padding. ..................................... 24
4.1 Objective: To obtain the circular convolution of two finite duration sequences ................................................ 24
4.2 Theory: ............................................................................................................................................................... 24
4.3 Convolution summation formula: ....................................................................................................................... 25
4.3.1 ALGORITHM 1: ........................................................................................................................................ 25
4.3.2 MATLAB PROGRAM 1:........................................................................................................................... 25
4.3.3 RESULT: .................................................................................................................................................... 26
1.1 Objective: To verify the sampling theorem for a signal of given frequency
1.2 Theory:
Sampling is a process of converting a continuous time signal x(t) (analog signal) into
discrete time signal x(n) (digital signal) which is represented as a sequence of numbers.
Sampling theorem generates x(n) from x(t) based on the sampling frequency (fs) which
determines the spacing between each samples.
Sampling of input signal x(t) can be obtained by multiplying x(t) with an impulse train δ(t)
of period Ts as shown in Fig.1.1., as the sampled signal takes the period of impulse. The
process of sampling can be explained by the following mathematical expression Eq. (1).
(2)
Substitute δ(t) in Eq. 1 and obtain Eq. (3).
(3)
Take Fourier transform on both sides of Eq. (3).
(4)
To reconstruct x(t) , input signal spectrum X(w) should be recovered from sampled signal
spectrum Y(w) in Eq. (4), which is possible when there is no overlapping between the cycles
of Y(w) as shown in Fig.1.2.
A continuous time signal can be represented in its samples and can be recovered back when
sampling frequency fs is greater than or equal to the twice the highest frequency component
of message signal given by Eq.(5)
𝒇𝒔 ≥ 𝟐 𝒇𝒎 (5)
1.3 ALGORITHM:
Step 1: For an appropriate analog signal consider the spacing between the samples to be very small,
approximately 0.001sec with time duration of 0.2sec, represented as time base: t=0:0.001:0.2;
Step 2: Obtain the analog signal x(t) based on the frequencies f1 and f2 , i.e.,
x(t)=cos(2*pi*f1*t)+cos(2*pi*f2*t);
Step 3: Select the sampling frequency to be the maximum frequency among f1 and f2 .
Step 4: Illustrate the three conditions: under sampling, Nyquist rate sampling and over sampling for
a discrete time vector n=0:1/fs:0.2;
Step 5: To generate sampled signals, consider:
Case (i) Under sampling with fs=fm;
Case (ii) Nyquist rate sampling with fs=2*fm; and
Case (iii) Over sampling with fs=20*fm;
Step 5: Plot the reconstructed signals for the respective sampling frequencies in discrete time
domain ‘n’: x1=cos(2*pi*f1*n)+cos(2*pi*f2*n).
Step 6: The frequency domain sampling can be obtained using the command freqz( ) to observe the
reconstructed signal in frequency domain.
1.4 MATLAB PROGRAM:
subplot(3,3,2);
stem(n,x1);
xlabel('---->n');
ylabel('amplitude');
title('under sampled signal');
subplot(3,3,3);
plot(n,x1);
xlabel('---->n');
ylabel('amplitude');
title('reconstructed signal');
fs=2*fm;
n=0:1/fs:0.2;
x2=cos(2*pi*f1*n)+cos(2*pi*f2*n);
subplot(3,3,4);
plot(t,x,'r');
xlabel('---->t');
ylabel('amplitude');
title('input signal');
subplot(3,3,5);
stem(n,x2);
xlabel('---->n');
ylabel('amplitude');
title('sampled at Nyquist rate');
subplot(3,3,6);
plot(n,x2);
xlabel('---->n');
ylabel('amplitude');
title('reconstructed signal');
ylabel('amplitude');
title('reconstructed signal');
%For Frequency Domain Sampling
figure(2)%To perform
subplot(3,1,1)
[m,w]=freqz(x1,1,128);
plot(fs1*w/(2*pi), abs(m));
title('spectrum of undersampled signal');
subplot(3,1,2);
[m,w]=freqz(x2,1,128);
plot(fs2*w/(2*pi), abs(m));
title('spectrum of Nyquist sampled signal');
subplot(3,1,3);
[m,w]=freqz(x3,1,128);
plot(fs3*w/(2*pi), abs(m));
title('spectrum of over sampled signal');
1.5 RESULT:
1 1.5 1.5
amplitude
amplitude
amplitude
0 1 1
-1 0.5 0.5
-2 0 0
0 0.05 0.1 0.15 0.2 0 0.05 0.1 0.15 0.2 0 0.05 0.1 0.15 0.2
---->t ---->n ---->n
input signal sampled at Nyquist rate reconstructed signal
2 2 2
1
1 1
amplitude
amplitude
amplitude
0
0 0
-1
-2 -1 -1
0 0.05 0.1 0.15 0.2 0 0.05 0.1 0.15 0.2 0 0.05 0.1 0.15 0.2
---->t ---->n ---->n
input signal oversampled signal reconstructed signal
2 2 2
1 1 1
amplitude
amplitude
amplitude
0 0 0
-1 -1 -1
-2 -2 -2
0 0.05 0.1 0.15 0.2 0 0.05 0.1 0.15 0.2 0 0.05 0.1 0.15 0.2
---->t ---->n ---->n
Fig. 1.3 Input signal, Sampled signal and reconstructed signal for three sampling frequencies.
0
0 1 2 3 4 5 6 7 8 9 10
spectrum of Nyquist sampled signal
10
0
0 2 4 6 8 10 12 14 16 18 20
spectrum of over sampled signal
50
0
0 20 40 60 80 100 120 140 160 180 200
Fig. 1.4 Reconstructed signal for three sampling frequencies in Frequency Domain
1.8 CONCLUSION:
The analog signals should be sampled at frequencies greater than the sampling frequency based on
Nyquist rate to obtain a perfect smooth reconstructed signal.
2.1 Objective:
2.2 Theory:
A linear system with input, x(t), and output, y(t), can be described in terms of its impulse response,
h(t) as shown in Fig 2.1, where Impulse Response of the system is the output signal of the system when
the input signal is an impulse function applied at time t = 0.
The practical significance of Fourier deconvolution in signal processing is that it can be used as a
computational way to reverse the result of a convolution occurring in the physical domain .
Deconvolution is usually performed by computing the Fourier Transform of the recorded
signal x(n) and the transfer function y(n), apply deconvolution in the Frequency domain, which in
the case of absence of noise is merely H(Ω)=Y(Ω)/X(Ω) where F, G, and H being the Fourier
Transforms of f(n), y(n), and h(n) respectively.
The command deconv(u,v:) deconvolves a vector v out of a vector u using long division, and returns
the quotient q and remainder r such that u = conv(v,q)+r. If u and v are vectors of polynomial
coefficients, then deconvolving them is equivalent to dividing the polynomial represented by u by
the polynomial represented by v.
An LTI discrete system can also be described by a linear constant coefficient difference equation of
the form shown in Eq. 8, or linear constant coefficient differential equation represented as given by
Eq. 9. This equation describes a recursive approach for computing the current output y(n), given the
input values x(n) and previously computed output values y(n-k).
∑N M
k=o a k y(n − k) = ∑k=0 bk x(n − k) (8)
𝑑𝑦(𝑡) 𝑑𝑥(𝑡)
∑N
k=o a k = ∑M
k=0 bk (9)
𝑑𝑡 𝑑𝑡
The impulse response for any system described by a differential equation can be represented using
the impulse command in MATLAB, i.e., idtf(), lsim( ), impulse()and impz().
The command idtf(): Constructs or converts to a transfer function with identifiable parameters.
Construction of SYS = idtf(NUM,DEN) creates a continuous-time transfer function SYS with
numerator NUM and denominator DEN. The parameter SYS consists of numerator and denominator
coefficients.
The command lsim(SYS,U,T) plots the time response of the dynamic system SYS to the input signal
described by U and T. The time vector T is expressed in the time units of SYS and consists of
regularly spaced time samples. The matrix U has as many columns as inputs in SYS and its ith row
specifies the input value at time T(i). For example,
Simulates the response of a single-input model SYS to the input u(t)=sin(t) during 5 time units.
The command impulse(SYS) : plots the impulse response of the dynamic system SYS. For systems
with more than one input, independent impulse commands are applied to each input channel uses the
time vector T for simulation (expressed in the time units of SYS).
For discrete-time models, T should be of the form Ti:Ts:Tf where Ts is the sampling time. For
continuous-time models, T should be of the form Ti:dt:Tf where dt is the sampling period for the
discrete approximation of SYS. The impulse is always assumed to arise at t=0 (regardless of Ti).
h = impulse(b, a, t)
Where b and a, are the vectors containing the ak and bj coefficients of the differential
equation, and t is the time over which the impulse response is to be found.
The command impz(B,A,N)computes the impulse response of an LTI system, where the numerator
and denominator coefficients are vectors B and A,for N samples of the impulse response.
2.5 ALGORITHM 1:
Step (1) Obtain the input and output sequences.
Step (2) Use the command deconv() to obtain the impulse response of the given system
Step (3) Plot the impulse response h(n) for the obtained length N
Step (4) Verify the correctness of impulse response using the command conv( ), i.e., the output y1(n)
obtained using conv( ) should be same as the original Output sequence y(n).
2.5.2 RESULT:
COMMAND WINDOW:
>> impulse1
The input sequence of the given system is x(n)=[1,1,1,1]
x=
1 1 1 1
The output sequence of the given system is y(n)=[1,1,1,1]
y=
1 1 1 1
The impulse response of the system is=
1
The output sequence of the system is y1(n)
1 1 1 1
This output y1(n) is same as that of given output y(n)
0.9
Impulse Response of the system h(n)
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1
Time Index (n)
2.6 ALGORITHM 2:
Step (1) Obtain the numerator and denominator coefficients as num and den respectively.
Step (2) Use the command idtf() to create the transfer function ‘G’ of the given continuous time
system with num and den.
Step (3) Select a suitable time frame ‘t’ in order to display the plot for impulse response.
Step (4) Use the command lsim(G,u,t), to plot the time response of the dynamic system ‘G’ to the
input signal described by u and t
Step (5) Plot the response y for the mentioned time frame.
2.6.2 RESULT:
COMMAND WINDOW:
G=
s+4
--------------
s^2 + 20 s + 5
0.3
0.25
0.2
0.15
0.1
0.05
-0.05
-0.1
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
2.7 Algorithm 3:
Step (1) Select an appropriate length ‘N’ for the impulse response.
Step (2) Obtain the numerator and denominator coefficients as ‘a’ and ‘b’ respectively
Step (3) Use the command impz() to obtain the impulse response of the given system.
Step (4) Plot the impulse response h(n) for the length N.
2.7.2 RESULT:
COMMAND WINDOW:
Length of impulse response required=100
N = 100
0.8
0.6
0.4
0.2
h(n)
-0.2
-0.4
-0.6
-0.8
-1
0 10 20 30 40 50 60 70 80 90 100
n
2.9 CONCLUSION:
A given system is stable if the impulse response is absolutely summable, i.e. if
∑∞
𝑘=−∞|ℎ(𝑘)| < ∞
Convolution of two signals can be obtained using the MATLAB command conv(A, B) convolves
vectors A and B. The resulting vector is of length:
length MAX([LENGTH(A)+LENGTH(B)-1,LENGTH(A),LENGTH(B)]).
If A and B are vectors of polynomial coefficients, convolving them is equivalent to multiplying the
two polynomials.
3.3 ALGORITHM 1:
Step (1) Initialize the two discrete time sequences as x(n) and h(n).
Step (2) Identify the start and end point of both the sequences.
Step (3) Set the start and end point for the resultant sequence y(n)
Step (4) Perform convolution of x(n) and h(n) using the MATLAB command conv( )
Step (5) Plot the input sequence x(n), impulse sequence h(n) and the output sequence y(n).
h=[1,2,1,-1];
nx=[0:3];
nh=[-1:2];
ystart=nx(1)+nh(1);
yend=nx(length(x))+nh(length(h));
ny=[nyb:nye]
y=conv(x,h)
disp(y);
subplot(1,3,1);
stem(nx,x);
xlabel('---->n');
ylabel('Amplitude');
title('First input: x[n]');
subplot(1,3,2);
stem(nh,h);
xlabel('---->n');
ylabel('Amplitude');
title('Second input: h[n]');
subplot(1,3,3);
stem(ny,y);
xlabel('---->n');
ylabel('Amplitude');
title('Linear Convolution Output: y[n]');
3.5 RESULT:
COMMAND WINDOW:
First input: x[n] Second input: h[n] Linear Convolution Output: y[n]
2 4 16
1.8
3.5 14
1.6
3 12
1.4
2.5 10
1.2
Amplitude
Amplitude
Amplitude
1 2 8
0.8
1.5 6
0.6
1 4
0.4
0.5 2
0.2
0 0 0
0 2 4 0 2 4 0 5 10
---->n ---->n ---->n
Fig. 3.2Input sequence x(n), Impulse sequence h(n) and Output sequence y(n)
3.7 ALGORITHM 2:
Step (1) Initialize the two discrete time sequences as x(n) and h(n).
Step (2) Identify the start point, end point and length of both the sequences.
Step (3) Set the length for the resultant sequence y(n)
Step (4) Perform convolution of x(n) and h(n) using ‘for’ loop with the convolution sum formula
mentioned in Eq. (7).
Step (5) Plot the input sequence x(n), impulse sequence h(n) and the output sequence y(n).
stem(n2,h);
xlabel('---->n');
ylabel('Amplitude');
3.9 RESULT:
COMMAND WINDOW:
Enter the first sequence: [1 2]
Enter the second sequence: [1 2 4]
Enter the range of the first sequence: [0:1]
Enter the range of the second sequence: [0:2]
1 4 8 8
3.10 EXPECTED WAVEFORM:
The input sequence x(n), impulse sequence h(n) and the output sequence y(n) using the convolution
sum is as shown in Fig.3.3
First input: x[n] Second input: h[n] Linear Convolution Output: y[n]
2 4 8
1.8
3.5 7
1.6
3 6
1.4
2.5 5
1.2
Amplitude
Amplitude
Amplitude
1 2 4
0.8
1.5 3
0.6
1 2
0.4
0.5 1
0.2
0 0 0
0 0.5 1 0 1 2 0 2 4
---->n ---->n ---->n
Fig. 3.3Input sequence x(n), Impulse sequence h(n) and Output sequence y(n)
3.11 ALGORITHM 3:
Step (1) Define the continuous time input signal x(t) and impulse signal h(t).
Step (2) Express x(t) and h(t) in the form of step function using the MATLAB command
‘heaviside ()’ for the mentioned time range.
Step (3) Plot the signals x(t) and h(t) within the time range.
Step (4) Perform convolution of x(n) and h(n) using MATLAB command conv( ).
Step (5) Plot the output sequence y(n) for the mentioned time range.
2
1.5 1.5
1.5
1 1
1
x(t)
0.5
y(t)
z(t)
0.5
0.5
0
0
0
-0.5
-0.5
-0.5
-1
-6 -4 -2 0 2 4 6 -1 -1
t -6 -4 -2 0 2 4 6 -10 -8 -6 -4 -2 0 2 4 6 8 10
t t
Fig. 3.4 Input signal x(t), Impulse signal h(t) and Output signal y(t)
4.1 Objective: To obtain the circular convolution of two finite duration sequences
4.2 Theory:
Circular convolution is “the fundamental operation to compute discrete time signals”. Consider two
finite sequence discrete time signals with length N are x1[n] & x2[n], the Linear convolution of
periodic signals is represented by Eq. (10).
𝑦(𝑛) = 𝑥1 (𝑛) ∗ 𝑥2 (𝑛) = ∑∞
𝑛=−∞ 𝑥1 (𝑘) ∙ 𝑥2 (𝑛 − 𝑘) (10)
The circular convolution of x1(n) and x2(n) is represented in Eq.(11), where the shifting in this
operation is circular shifting for the given sequence of length N.
𝑦(𝑛) = 𝑥1 (𝑛) ⊛ 𝑥2 (𝑛) = ∑∞
𝑛=−∞ 𝑥1 (𝑘) ∙ 𝑥2 (𝑛 − 𝑘)𝑁 (11)
The Discrete Fourier Transformation (DFT) of signals x1(n) and x2(n) are represented as X1(k)
& X2(k) respectively. According to convolution property (time domain) of DFT, the convolution of
signals x1(n) and x2(n) is the product of signals their DFT signals given as Eq.(12).
(12)
If x1(n) contains L number of samples and x2(n) contains M number of samples, for L>M, the
circular convolution is performed using N=Max(L,M), by adding L-M number of zero samples to the
sequencex2(n) so that both the sequences are periodic with N.
The difference between circular an linear convolution is, in circular convolution the folding and
shifting operation of sequences is performed circularly by computing the index of one of the
sequence using modulus operation mod(N), while for linear convolution these is no modulus
operation
Circular convolution of two finite duration discrete time sequences can be found using: (a) the
convolution summation formula (b) the matrix method and (c) Linear convolution from circular
convolution with zero padding.
4.3.3 RESULT:
COMMAND WINDOW:
Enter the first sequence[2 1 2 1]
Enter the second sequence[1 2 3 4]
Circular convolution of x(n) and h(n)is y(n)=
14 16 14 16
4.3.4 EXPECTED WAVEFORM:
The Input signalx(t), Impulse signal h(t) and Output signal y(t) using the circular convolution sum
formula is as shown in Fig.4.1.
First input Signal x[n]
2
Amplitude
0
0 0.5 1 1.5 2 2.5 3
---->n
Second input Signal h[n]
4
Amplitude
0
0 0.5 1 1.5 2 2.5 3
---->n
Circular convolution y[n]
20
Amplitude
10
0
0 0.5 1 1.5 2 2.5 3
---->n
Fig. 4.1Circular Convolution using convolution summation formula
4.4.1 ALGORITHM 2:
Step (1) Initialize the two discrete time sequences as x(n) and h(n).
Step (2) Identify the length of both the sequences.
Step (3) Set the length for the resultant sequence y(n)
Step (4)Append zeros to either of the sequences such that both the sequences are of length N.
Step (4) Perform convolution of x(n) and h(n) using ‘for’ loop with the circular convolution sum
formula mentioned in Eq. (9).
Step (5) Plot the input sequence x(n), impulse sequence h(n) and the output sequence y(n).
clc;
close all;
clear all;
x1=input('enter the 1st sequence x(n)=')
h1=input('enter the 1st sequence h(n)=')
N1=length(x1)
N2=length(h1)
N=max(N1,N2)
if(N1>N2);
h1=[h1,zeros(1,N-N2)]
else
x1=[x1,zeros(1,N2-N1)]
end;
x=transpose(x1);
h=transpose(h1);
temp=h;
for i=1:N-1;
temp=circshift(temp,1);
h=horzcat(h,temp);
end;
h
x
y=h*x
subplot(3,1,2);
stem(h1);
xlabel('N-->')
ylabel('Amplitude-->')
subplot(3,1,3);
stem(y);
xlabel('N-->')
ylabel('Amplitude-->')
title('Circular convolved output y[n]');
4.4.3 RESULT:
COMMAND WINDOW:
0
1 1.5 2 2.5 3 3.5 4
Impulse Response: h(n)
4
0
1 1.5 2 2.5 3 3.5 4
Circular Convolution using MATRIX METHOD
20
10
0
1 1.5 2 2.5 3 3.5 4
Fig. 4.2 Circular Convolution using Matrix Method
y(n+1)=0;
for k=0:N-1
i=mod((n-k),N);% Calculation of x index
if i<0
i=i+N;
end
y(n+1)=y(n+1)+g2e(k+1)*g1e(i+1);
end
end
4.5.3 RESULT:
Circular Convolution :
y(m)==>
2
5
10
16
12
11
4.5.4 Expected Waveform:
The Input signalx(t), Impulse signal h(t) and Output signal y(t) using Linear convolution from
circular convolution with zero padding is as shown in Fig.4.3.
First input: x[n] Second input: h[n] Linear Convolution Output: y[n]
1 3 6
0.9
2.5 5
0.8
0.7
2 4
0.6
Amplitude
Amplitude
Amplitude
0.5 1.5 3
0.4
1 2
0.3
0.2
0.5 1
0.1
0 0 0
0 1 2 0 2 4 0 5
---->n ---->n ---->n
Fig. 4.3 Linear convolution from circular convolution with zero padding
5.1 Objective: To obtain the Discrete Fourier Transform (DFT) of a given finite duration
sequences
5.2 Theory:
The Discrete Time Fourier Transform (DTFT) of a signal x(n) is given by Eq.13.
𝑋(𝜔) = ∑∞
𝑛=−∞ 𝑥(𝑛)𝑒
−𝑗𝜔𝑛
(13)
DTFT is a continuous function of frequency hence frequency analysis of digital systems cannot be
performed using DTFT, since, frequency domain signals are expected to be discrete in nature. Such
signals are discretized by sampling in one period and the resulting frequency domain signal is called
as Discrete Fourier Transform (DFT). These discrete time signal are of finite length L≤ N, the
number of frequency samples considered.
The N-pt DFT , X(k), of an N-pt sequence x(n), is now given by Eq.14.
−𝑗2𝜋𝑘𝑛
𝑋(𝑘) = ∑𝑁−1
𝑛=0 𝑥(𝑛)𝑒 𝑁 for 0 ≤ k ≤N-1 (14)
−𝑗2𝜋
Replacing 𝑒 𝑁 by WN , referred as phase factor or twiddle factor given by Eq.15.
𝑛𝑘
𝑋(𝑘) = ∑𝑁−1
𝑛=0 𝑥(𝑛)𝑊𝑁 for 0 ≤ k ≤N-1 (15)
WN satisfies property of periodicity and property of symmetry
𝑟+𝑁 𝑟+𝑁/2
𝑊𝑁 = 𝑊𝑁𝑟 ( periodicity) and 𝑊𝑁 = −𝑊𝑁𝑟 (symmetry)
5.3 ALGORITHM:
Step (1) Initialize the discrete time sequence as x(n).
Step (2) Identify the length of the sequence as N.
Step (3) Initialize the resultant DFT sequenceX(k) with zeros based on the length N.
Step (4)Perform DFT of the sequence x(n) using the Eq. (11).
Step (5)Plot the input sequence x(n) and the magnitude & phase angle for resultant sequence X(k).
5.4 MATLAB PROGRAM:
%N-point DFT of x(n)
x = [2 3 -1 4];
N = length(x);
X = zeros(4,1)
for k = 0:N-1
for n = 0:N-1
X(k+1) = X(k+1) + x(n+1)*exp(-j*pi/2*n*k)
magX=abs(X(k+1))
angX=angle(X(k+1))
end
end
t = 0:N-1
subplot(311)
stem(t,x);
xlabel('Time (s)');
ylabel('Amplitude');
title('Time domain - Input sequence')
subplot(312)
stem(t,X)
xlabel('Frequency');
ylabel('|X(k)|');
title('Frequency domain - Magnitude response')
subplot(313)
stem(t,angle(X))
xlabel('Frequency');
ylabel('angle(X(k))');
title('Frequency domain - Magnitude response')
Amplitude
0
-5
0 0.5 1 1.5 2 2.5 3
Time (s)
6
x 10 Frequency domain - Magnitude response
10
|X(k)|
5
0
0 0.5 1 1.5 2 2.5 3
Frequency
Frequency domain - Magnitude response
1
angle(X(k))
-1
0 0.5 1 1.5 2 2.5 3
Frequency
5.7 CONCLUSION:
The N-point DFT for a finite duration sequence x(n) of length L should be such that N>=L
The N point DFT of x(n) should satisfy periodicity and symmetry properties.
6 Experiment No.6: Linear and circular convolution by DFT and IDFT method
6.1 Objective: To obtain Linear and circular convolution using Discrete Fourier Transform
(DFT) of two finite duration sequences
6.2 Theory:
Discrete Fourier Transform (DFT) provides the frequency-domain (ω) representation for absolutely
summable time domain sequence x(n). The DFT of x(n) is expressed as X(k) as given by Eq. (16).
𝑗2𝜋𝑘
−
𝑋(𝑘) = ∑𝑁−1
𝑛=0 𝑥(𝑛) 𝑒 𝑁 (16)
DFT of a signal can be obtained by sampling the DTFT of the signal at N uniform sampling points.
Hence it is also referred to as N-point DFT. The value of N for a finite duration sequence x(n) of
length L should be such that N>=L in order to avoid aliasing of frequency response.
The Inverse DFT of X(k) gives back the time domain sequence given by Eq.17.
𝒋𝟐𝝅𝒌𝒏
𝟏 𝟏
𝒙(𝒏) = ∑𝑵−𝟏
𝒌=𝟎 𝑿(𝒌)𝒆
𝑵 = ∑𝑵−𝟏 −𝒌𝒏
𝒌=𝟎 𝑿(𝒌)𝑾𝑵 0 ≤ n ≤ N-1 (17)
𝑵 𝑵
According to Linear Convolution for discrete time system is given as Eq.(7) of Experiment No.3
𝑦(𝑛) = 𝑥(𝑛) ∗ ℎ(𝑛) = ∑∞
𝑛=−∞ 𝑥(𝑘) ∙ ℎ(𝑛 − 𝑘) (7)
Given x(n) and h(n) are transformed to respective DTFTs, X(ω) and H(ω), applying convolution
property of DTFT, i.e., DTFT{𝑥(𝑛) ∗ ℎ(𝑛)} = X(ω) H(ω), Y(ω) is obtained. Performing IDFT Y(ω)
can be converted back to time domain y(n). The process of Linear convolution using DFT & IDFT is
as shown in the block diagram Fig.6.1
y(n) = ∑N−1
m=0 x(m) h((n − m))N = x(n) N h(n) 0 ≤ n ≤ N-1 (18)
Given x(n) and h(n) are transformed to respective DFTs, X(k) and H(k). Apply the property of DFT:
DFT {x(n) N h(n) } = X(k) · H(k). By performing IDFT on Y(k), it can be converted back to time
domain y(n).
Here the size of DFT, N = L1 +L2 -1, represents the length of circular convolution length. Therefore,
circular convolution will be same as linear convolution, when both x(n) and y(n) are of same length.
6.3 Linear convolution by DFT and IDFT method:
6.3.1 ALGORITHM 1:
Step (1) Initialize the discrete time sequences as x1(n) and x2(n).
Step (2) Identify the length of the sequences as N1 and N2.
Step (3) Initialize the length of resultant DFT sequence X1(k) and X2(k) as n1 and n2
Step (4)Set the DFT sequences X1(k) and X2(h) by appending zeros based on the lengths N1 and
N2, such that both sequences are of same length.
Step (5) Perform DFT of the sequences x1(n) and x2(n), using the command fft( ).
Step (6) Obtain the Linear convolution y(n) using DFT as given in Eq.(12).
Step (7) Plot the input sequences x1(n) & x2(n) and the resultant sequence y(n).
L1=length(x);
L2=length(h);
N=L1+L2-1;
X=fft(x,N)
H=fft(h,N)
Y=X.*H;
y=ifft(Y,N)
n = 0:L1-1;
subplot(3,1,1)
stem(n,x);
xlabel('Time (n)');
ylabel('x(n)');
title('Time domain - First sequence')
n = 0:L2-1;
subplot(3,1,2)
stem(n,h);
xlabel('Time (n)');
ylabel('h(n)');
title('Time domain - Second sequence')
n = 0:N-1;
subplot(3,1,3)
stem(n,y);
xlabel('Time (n)');
ylabel('y(n)');
title('Time domain - Linear Convolition sequence')
6.3.3 RESULT:
x=
1 2 2 1
Enter the second time domain sequence [3 1 1 2 3]
h=
3 1 1 2 3
y=
Columns 1 through 9
3.0000 7.0000 9.0000 9.0000 10.0000 11.0000 8.0000 3.0000
6.3.4 Expected Waveform:
The input signals x1(n) & x2(n) and resultant signal y(n) using DFT & IDFT method is as shown in
Fig.6.2.
x(n)
1
0
0 0.5 1 1.5 2 2.5 3
Time (n)
Time domain - Second sequence
4
h(n)
2
0
0 0.5 1 1.5 2 2.5 3 3.5 4
Time (n)
Time domain - Linear Convolition sequence
20
y(n) 10
0
0 1 2 3 4 5 6 7
Time (n)
Fig. 6.2 Linear Convolution of two sequences x1(n) and x2(n) using DFT& IDFT method
6.3.6 CONCLUSION:
When the sequence x(n) is of length L1 and h(n) is of length L2 then the resultant
sequence of linear convolution y(n) is of length, N= L1 +L2 -1.
Linear Convolution satisfies folding, multiplication, addition and shifting properties.
Linear convolution using DFT & IDFT method satisfies the Convolution property of
DTFT.
6.4 Circular convolution by DFT and IDFT method:
6.4.1 ALGORITHM 2:
Step (1) Initialize the discrete time sequences as x(n)and h(n).
Step (2) Identify the length of the sequences as L1 and L2 & N-point for the DFT of the sequences.
Step (3) Initialize the length of resultant DFT sequenceX(k) and H(k) as n1 and n2
Step (4) Set the DFT sequences X(k) and H(k) by appending zeros based on the lengths L1 and L2,
such that both sequences are of same length with reference to N.
Step (5)Perform DFT of the sequences x(n) and h(n), using the Eq. (12).
Step (6)Obtain the circular convolution y(n) as product of two DFTs X(k) and H(k) using Eq.(13).
Step (7)Plot the input sequences x(n) & h(n) and the resultant sequence y(n).
N-point DFT
clc; clear all; close all;
x=input('Enter the first sequence x[n]: ');
N1=input('Enter the DFT size: ');
L1=length(x);
x=[x,zeros(1,N1-L1)];
for k=0:1:N1-1
X(k+1)=0;
for n=0:1:N1-1
X(k+1)=X(k+1)+x(n+1)*exp(-i*2*pi*k*n/N1);
end
end
Xmag=abs(X);
Xang=angle(X);
disp('DFT of First sequence X(k)');
disp(Xmag);
disp(Xang);
k=0:1:N1-1;
subplot(2,1,1); stem(k,Xmag); xlabel('-->k'); ylabel('Magnitude of X(k)');
title('Magnitudespectrum');
subplot(2,1,2); stem(k,Xang); xlabel('-->k'); ylabel('Phase of X(k) in
radians'); title('Phasespectrum');
pause;
h=input('Enter the second sequence h[n]: ');
N2=input('Enter the DFT size: ');
L2=length(h);
h=[h,zeros(1,N2-L2)];
for k=0:1:N2-1
H(k+1)=0;
for n=0:1:N2-1
H(k+1)=H(k+1)+h(n+1)*exp(-i*2*pi*k*n/N2);
end
end
Hmag=abs(H);
Hang=angle(H);
6.4.3 RESULT:
Enter the first sequence x[n]: [2 1 2 1]
Enter the DFT size: 4
DFT of First sequence X(k)
6.0000 0.0000 2.0000 0.0000 0 -2.2620 0 -1.1703
Enter the second sequence h[n]: [1 2 3 4]
Enter the DFT size: 4
DFT of Second sequence H(k)
10.0000 2.8284 2.0000 2.8284 0 2.3562 -3.1416 -2.3562
DFT of Output sequence Y(k)
60.0000 0.0000 4.0000 0.0000 0 0.0942 -3.1416 2.7567
Amplitude
1
0
0 0.5 1 1.5 2 2.5 3 3.5 4
---->nSignal h[n]
Second input
4
Amplitude
2
0
0 0.5 1 1.5 2 2.5 3 3.5 4
---->n
Circular convolution via DFT is y[n]
20
Amplitude
10
X= 4
0 Y= 10
0 0.5 1 1.5 2 2.5 3 3.5 4
---->n
Fig. 6.3 Circular Convolution of two sequences x(n) and h(n) using DFT & IDFT method
6.4.6 CONCLUSION:
Circular convolution is said be same as linear convolution, when both x(n) and y(n) are of
same length.
If the sequence x(n) is of length L1 and h(n) is of length L2, then length N of resultant
sequence of circular convolution is chosen as >= to max(L1, L2)
When circular convolution length, N < L1+L2 -1, then circular convolution is linear
convolution plus aliasing.
The linear convolution is generally applied to aperiodic sequences. Whereas the Circular
Convolution is used to study the interaction of two signals that are periodic
7.1 Objective: To solve a given difference equation and obtain the output of an LTI system.
7.2 Theory:
A discrete time LTI system (also called digital filters) as shown in Fig.7.1 is represented by a linear
constant coefficient difference equation Eq.19.
The system function H(z) is obtained by applying Z transform to the difference equation as shown in
Eq.20 . Further, Inverse Z transform of H(z) yields h(n) – impulse response.
Y ( z ) b0 b1 z 1 b2 z 2 (20)
H ( z)
X ( z ) 1 a1 z 1 a 2 z 2
A LTI system is characterized in time domain using impulse response h(n), which is obtained by
applying an impulse input to the LTI system as shown in Fig.7.2 ,where the LTI system is normally
represented as a black box.
This difference equation can be solved to obtain y[n], the output for a given input x[n] by
rearranging as: y[n] = x[n] + 0.7x[n-1]+0.5x[n-2]- 0.8y[n-2]- 0.6y[n-3].
The solution of the above difference equation is output y(n), that depends on the input x[n]
If x[n]= δ[n], an impulse, then the computed output y[n] is the impulse response.
If x[n]=u[n], a unit step input, then the computed output y[n] is a step response.
If x[n] = cos(wn), a sinusoidal sequence, then the computed output y[n] is a steady state
response (wherein y[n] is of the same frequency as x[n], with only an amplitude gain and
phase shift.
The MATLAB function filter is used to compute the impulse response/ step response/ response
for any given input x[n].
Note: filter function evaluates the convolution of infinite sequences, h[n] and x[n], which is not
possible with conv function (since conv requires both the sequences to be finite).
7.3 ALGORITHM 1:
Step (1) Identify a difference equation of an LTI system
Step (2) Set the coefficients of x as vector ‘a’ and the coefficients of y as vector ‘b’.
Step (3) Initialize the length of output sequence y(n) as N.
Step (4) Set the given expression for input sequence as x.
Step (5)Calculate the output y(n) of the given LTI system using the command filter ( ) .
Step (6)Plot the input sequences x(n) and the output sequence y(n).
%Solve the given difference equation of an LTI system using the command filter( )
clc; clear all; close all;
b=input('Enter the coefficients of x: ');
a=input('Enter the coefficients of y: ');
N=input('Enter the length of the input: ');
n=0:1:N-1;
x=(1/2).^n;
y=filter(b,a,x);
disp(y);
subplot(2,1,1); stem(n,x); xlabel('---->n'); ylabel('Amplitude');
0.5
0
0 2 4 6 8 10 12 14
---->n
response of the system
1.5
Amplitude
0.5
0
0 2 4 6 8 10 12 14
---->n
CONCLUSION:
−𝑗2𝜋
The phase factor or twiddle factor represented as 𝑒 𝑁 or WN satisfies property of
periodicity and property of symmetry
These DFT signals can be used for Linear filtering, Power Spectrum estimation and
Frequency analysis of signals
8.1 Objective: To DFT & IDFT of a given sequence using FFT method .
8.2 Theory:
Radix-2 Decimation in Time Fast Fourier Transform Algorithm (DIT-FFT) makes use of the Divide
and Conquer approach. The N-point DFT is obtained by decimating time-sequence, the number of
points of DFT, N, is expressed as a power of 2, i.e., N= 2v, as the value of N increases, the
computational efficiency of FFT increases. The time sequence is split into even indexed sequence
and odd indexed sequence. Each of them is used to obtain separate N/2 –point DFTs. The samples
of N/2-pt DFTs are suitably combined by an N- point combining algebra to obtain N- point DFT.
This is called as first level decomposition.
Further, each of the subsequences is split into even and odd samples. This leads to each of the N/2-pt
DFTs to be expressed as two N/4-pt DFTs. This is called as second level decomposition. The
decomposition process is continued until, the N-point DFT is obtained using 2-pt DFTs. N point
DFT is expressed as
−j2πkn
X(k) = ∑N−1
n=0 x(n)e N 0 ≤ k ≤N-1
Consider the case of N=8;
−j2πkn
X(k) = ∑7n=0 x(n)e 8 0≤k≤7
The complete signal flow graph for 8-point DFT is as shown in Fig. the 8-point DFT computation
requires 3 stages with 4 (N/2) butterfly operations in each stage. The processor performs in-place
computation. The input is fed in bit reversed while the outputs are extracted in normal order.
8.3 ALGORITHM:
Step (1) Initialize the discrete time sequences as x(n) and set the required DFT as N-point.
Step (2) Obtain the DFT of the sequence x(n) as X(k) using the command fft( ).
Step (3) Obtain the IDFT of the sequence X(k) as x(n) using the command ifft( ).
Step (4) Plot the input sequence x(n) corresponding to time domain ‘n’.
Step (5) Plot the magnitude and phase response of DFT sequence X(k).
X=fft(x,N)
x1=ifft(X,N)
n = 0:length(x)-1;
stem(n,x);
title('Time sequence')
xlabel('Time (n)');
ylabel('x(n)');
k=0:N-1
figure
subplot(2,1,1)
stem(k,abs(X));
title('Frequency domain - Magnitude response')
xlabel('Frequency-k');
ylabel('Mag |X(k)|');
subplot(2,1,2)
stem(k,angle(X))
xlabel('Frequency k');
ylabel('angle(X)');
title('Frequency domain - Phase response')
8.5 RESULT:
Enter the time domain sequence: [1 2 2 1 2 1 1 2]
x= 1 2 2 1 2 1 1 2
Enter the No. of points of DFT8 N = 8
X=
Columns 1 through 3
12.0000 + 0.0000i 0.4142 - 1.0000i 0.0000 + 0.0000i
Columns 4 through 6
-2.4142 + 1.0000i 0.0000 + 0.0000i -2.4142 - 1.0000i
Columns 7 through 8
0.0000 + 0.0000i 0.4142 + 1.0000i
1.8
1.6
1.4
1.2
x(n)
0.8
0.6
0.4
0.2
0
0 1 2 3 4 5 6 7
Time (n)
10
0
0 1 2 3 4 5 6 7
Frequency-k
Frequency domain - Phase response
4
2
angle(X)
-2
-4
0 1 2 3 4 5 6 7
Frequency k
Exercise Problems
1. Obtain the DFT and IDFT of a signal x(n) = {1,2, 2,1,2,1,1,2} using DIT- FFT algorithm.
2. Obtain the 4-point DFT of the sequence x(n) = [1,1,2,3] using FFT and sketch the
magnitude and phase spectrum. Also perform IDFT on the frequency domain sequence
using IFFT to extract the time domain sequence.
CONCLUSION:
The DFT X(k) obtained using FFT satisfies symmetry property.
Computation of DFT using FFT is faster than the direct method
9 Design and implementation of IIR filters to meet given specification (Low pass, high pass,
band pass and band reject filters)
9.1 Objective: To Design an IIR filter using Butterworth / Chebyshev filter and obtain the
magnitude and frequency response for the given system.
9.2 Theory:
IIR filters have infinite-duration impulse response. Two types of IIR Filters: Butterworth Filter and
Chebyshev Filter (Types I). Typically any IIR filters has the following approach as shown in Fig.9.1.
1 (𝑗𝛺)2𝑁
𝐻𝑎 (𝑠)𝐻𝑎 (−𝑠) = |𝐻𝑎 (𝑗𝛺)|2 |𝛺=𝑠⁄ = 𝑠 2𝑁
= 𝑠2𝑁 +(𝑗𝛺 2𝑁
(22)
𝑗 1+( ) 𝑐)
𝑗𝛺𝑐
1 𝜋
(2𝑘+𝑁+1)
𝑝𝑘 = (−1)2𝑁 (𝑗𝛺) = 𝛺𝑐 𝑒 𝑗2𝑁 , 𝑘 = 0, 1, 2, … . , 2𝑁 − 1 (23)
The Butterworth analog low pass filter is specified by the parameters passband edge frequency Ωp,
stopband edge frequency Ωs, passband attenuation in dB, Ap and stopband attenuation in dB As and
sampling frequency fsamp. The design of the this filter depends on the order N and the cut-off
frequency Ωc for given specifications as mentioned in Eq.24 & Eq.25.
𝛺𝑝
𝛺𝑐 = 2𝑁
(25)
√(10𝐴𝑝 ⁄10 −1)
where N is the order of the filter, 𝜖 is the passband ripple factor, which is related to Ap and CN (x) is
the Nth-order Chebyshev polynomial given by Eq.27
cos(𝑁 cos −1 (𝑥)), 0 ≤ 𝑥 ≤ 1
𝐶𝑁 (𝑥) = { (27)
𝑐𝑜𝑠ℎ(cosh−1 (𝑥)), 1 ≤ 𝑥 ≤ ∞
𝛺
Where 𝑥 = 𝛺𝑐
The equiripple response of the Chebyshev filters is due to this polynomial CN(x). Its key properties
are:
(a) for 0 <x<1, CN(x) oscillates between −1 and 1, and
(b) for 1 < x < ∞, CN(x) increases monotonically to ∞.
There are two possible shapes of|Ha(jΩ)|2, one for N odd and one for N even as shown in Fig.9.3
The poles are given by pk = σk + jΩk, k =0,...,N−1 are the (left half-poles) as given in Eq.29
π (2k+1)π
σk = (aΩc ) cos [ 2 + ]
2N
π (2k+1)π
} k = 0, … . , N − 1 (29)
Ωk = (bΩc ) sin [ 2 + ]
2N
where
1 N N 1 N 1 1
a= ( μ − √1⁄μ), b = ( N√μ + √1⁄μ) and μ = ϵ + √1 + ϵ2
2 √ 2
For Analog-to-Digital (ADC) filter transformations, i.e., conversion from s-domain to z-domain, the
most popular techniques used in practice are the Bilinear and Impulse Invariance transformations,
which preserve the system function representation from analog to digital domain.
In Impulse Invariance transformation, analog poles {pk} into digital poles {epkT} are represented
using the system function as in Eq.31 to obtain the digital filter.
R
H(z) = ∑N k
k=1 1−epkT z−1 (31)
In Bilinear transformation the analog to digital conversion is obtained as H(z) a rational function in
−1
z as given in Eq.32
2 1−z−1
H(z) = Ha (T 1+z−1 ) (32)
Step (2) Express the passband edge frequency fp & stopband edge frequency fs in terms of sampling
frequency fsamp (in radians/sec).
Step (3) Obtain the order N as the lowest order and analog Butterworth filter using the command
buttord (N, wc ) for the cut-off frequency wc to use with Butterworth filter of the given
specifications.
Step (4) Design an order N, low pass analog (‘s’) Butterworth filter with angular cutoff frequency
wc rad/s using the command butter (N, wc,’s’) that returns the filter coefficients in length
Step (5) Convert the s-domain transfer function to a z-transform discrete equivalent obtained from
the bilinear transformation command bilinear(a,b,fsamp), where a and b are row vectors containing
numerator and denominator transfer function coefficients, where a(s)/b(s), in descending powers of
s, transforms to z-transform coefficients num(z)/den(z).
Step (6) Obtain the N-point frequency response of digital filter using the command
freqz(num,den,256,fsamp), where N=256 and sampling frequency as fsamp in Hz.
Step (7) Plot the magnitude and frequency response of the IIR Butterworth Low pass filter.
9.5.3 RESULT:
Enter the passband edge frequency: 200
Enter the stopband edge frequency: 400
Enter the passband attenuation in dB: 3
Enter the stopband attenuation in dB: 15
Enter the sampling frequency in Hz: 2000
N= 3
wc = 1.6430e+03
Numerator, a=
0.0311 0.0933 0.0933 0.0311
Denominator, d=
1.0000 -1.4703 0.9195 -0.2004
9.5.4 Expected Waveform:
The magnitude and frequency response of the IIR Butterworth Low pass filter is as shown in Fig.9.4.
magnitude in dB
-50
-100
-150
-200
0 100 200 300 400 500 600 700 800 900 1000
frequency in Hz
Phase (degrees) 0
-100
-200
-300
0 100 200 300 400 500 600 700 800 900 1000
Frequency (Hz)
Fig. 9.4 Magnitude and frequency response of the IIR Butterworth Low pass filter
the following specifications: passband edge frequency: 1500, stopband edge frequency:
2000, passband attenuation in dB: 1, stopband attenuation in dB: 20 and sampling
frequency: 8000 Hz
2. Design a Butterworth digital IIR high pass filter using bilinear transformation by taking
T=0.1sec to satisfy the following specifications: passband edge frequency: 0.65π,
stopband edge frequency: 0.45 π, passband attenuation in dB: 0.707, stopband
attenuation in dB: 0.2.
Step (4) Design an order N, low pass analog (‘s’) Chebyshev filter with angular cutoff frequency
wc rad/s using the command butter (N, wc,’s’) that returns the filter coefficients in length N+1
vectors of b (numerator) and a (denominator).
Step (5) Convert the s-domain transfer function to a z-transform discrete equivalent obtained from
the bilinear transformation command bilinear(a,b,fsamp), where a and b are row vectors containing
numerator and denominator transfer function coefficients, where a(s)/b(s), in descending powers of
s, transforms to z-transform coefficients num(z)/den(z).
Step (6) Obtain the frequency response of digital filter using the command freqz( ).
Step (7) Plot the magnitude and frequency response of the IIR Chebyshev Low pass filter.
display('Digital trf')
Hz=tf(num,den,1/fsamp)
w=0:pi/16:pi;
display('Frequency response is');
Hfreq=freqz(num,den,w)%Freq Response in z domain
display('Magnitude response is');
Hmag=abs(Hfreq)
plot(w/pi,Hmag,'k')
grid on;
ylabel('magnitude in dB');
title('Frequency response of IIR Chebyshev LPF');
9.6.3 RESULT:
Enter the passband edge frequency: 0.2*pi
Enter the stopband edge frequency: 0.32*pi
Enter the passband attenuation: 0.8
Enter the stopband attenuation: 0.2
Enter the sampling frequency: 1
Apdb = 1.9382
Asdb = 13.9794
N= 3
wc = 0.6498
0.9
0.8
0.7
magnitude in dB
0.6
0.5
0.4
0.3
0.2
0.1
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Fig. 9.5 magnitude and frequency response of the IIR Chebyshev Low pass filter
9.6.6 CONCLUSION:
From the analysis of Butterworth digital IIR low pass filter, it can be observed that the
magnitude response is flat in both passband and stop band, hence it is referred to as
maximally flat response
From the magnitude and frequency response of Chebyshev digital IIR low pass, it can be
observed that magnitude is monotonic outside the passband and satisfy the properties of
Chebyshev filters.
Due to aliasing effect the Impulse Invariance method is restricted for lower frequencies,
while the bilinear transformation can applied either for lower or higher frequencies without
aliasing problem.
It can be observed that the system function varies based on the order of the given system,
where sharp cut-off characteristics can be obtained with minimum order of the filter.
10.2 Theory:
Finite impulse response (FIR) filters demonstrate the property of linear phase. There are three design
techniques for FIR filters, namely: (i) the window design,(ii) the frequency sampling design, and (iii)
the optimal equiripple design technique. In this experiment, the window design technique has been
discussed for design and implementation.
The system function for an impulse response h(n) of length M, is represented in Eq.33 and the
frequency response function is represented in Eq. For linear-phase: H(ejω) = −αω, −π<ω≤ π , where α
is a constant phase delay. Here h(n) must be symmetric, that is, h(n) = h(M −1 − n), 0 ≤ n ≤ (M −1)
with α = (M −1)/ 2. Hence h(n) is symmetric about α, which is the index of symmetry. The two
possible types of symmetry are: M odd, then α = (M−1)/2 is an integer and M even, then
α = (M −1)/2 is not an integer.
If the type of linear phase h(n)=−h(M−1−n), 0 ≤ n ≤(M−1); α = (M −1)/ 2 ,β = ±π/ 2, this indicates
that the impulse response h(n) is anti-symmetric where the index of symmetry is α = (M −1)/2.
𝑀−1
𝐻(𝑧) = ∑𝑀−1
𝑛=0 ℎ(𝑛)𝑧
−1
= 𝑧 −(𝑀−1) ∑𝑀−1
𝑛=0 ℎ(𝑛)𝑧
𝑀−1−𝑛
(33)
In order to design a linear-phase and causal FIR filter, a proper system that is non-causal & with
infinite-duration impulse response is to be selected. This system is truncated (or windowed) by
selecting an appropriate windowing function and with an appropriate ideal filter as shown in Table 1.
Consider an ideal LPF of bandwidth ωc < π is given by Eq.34
1 ∙ 𝑒 −𝑗𝛼𝜔 , |𝜔| ≤ 𝜔𝑐
𝐻𝑑 (𝑒 𝑗𝜔 ) = { (34)
0, 𝜔𝑐 ≤ |𝜔| ≤ 𝜋
where ωc is the cut-off frequency, and α is the sample delay.
The impulse response of this filter is of infinite duration and is given by Eq.35
𝜋
1
ℎ𝑑 (𝑛) = ℱ −1 [𝐻𝑑 (𝑒 𝑗𝜔 )] = ∫ 𝐻𝑑 (𝑒 𝑗𝜔 )𝑒 𝑗𝜔𝑛 𝑑𝜔
2𝜋
−𝜋
1 𝜋 sin[𝜔𝑐 (𝑛−𝛼)]
= 2𝜋 ∫−𝜋 1 ∙ 𝑒 −𝑗𝜔𝛼 𝑒 𝑗𝜔𝑛 𝑑𝜔 = (35)
𝜋(𝑛−𝛼)
To obtain a causal and linear-phase FIR filter h(n) of length M as per the Eq.36
ℎ (𝑛), 0 ≤ 𝑛 ≤ 𝑀 − 1 𝑀−1
ℎ(𝑛) = { 𝑑 𝑎𝑛𝑑 𝛼 = 2 (36)
0, 𝑒𝑙𝑠𝑒𝑤ℎ𝑒𝑟𝑒
This system is truncated (or windowed) by selecting an appropriate windowing function and with an
appropriate ideal filter. In general, h(n) can be thought of as being formed by the product of hd(n)
and a window function w(n) as given by Eq.37
h(n) = hd(n)·w(n) (37)
𝑆𝑜𝑚𝑒 𝑠𝑦𝑚𝑚𝑒𝑡𝑟𝑖𝑐 𝑓𝑢𝑛𝑐𝑡𝑖𝑜𝑛 𝑤𝑖𝑡ℎ 𝑟𝑒𝑠𝑝𝑒𝑐𝑡 𝑡𝑜 𝛼 𝑜𝑣𝑒𝑟 0 ≤ 𝑛 ≤ 𝑀 − 1
where w(n) ={
0, 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
Commonly used window function characteristics are as shown in Table 1
Table 1: Window Function characteristics
Window Transition width Min.
Name ∆𝜔 Stopband
Attenuation Representative Equation
Approx. Exact
Value
Rectangular 4𝜋 1.8𝜋 21dB 1, 0 ≤ 𝑛 ≤ 𝑀 − 1
𝑤(𝑛) = {
𝑀 𝑀 0, 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
Bartlett 8𝜋 6.1𝜋 25dB 2𝑛 𝑀−1
, 0≤𝑛≤
𝑀 𝑀 𝑀−1 2
𝑤(𝑛) 2𝑛 𝑀−1
2− , ≤ 𝑛 ≤ 𝑀 − 1,
𝑀−1 2
{ 0, 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
Hann 8𝜋 6.2𝜋 44dB 2𝜋𝑛
0.5 [1 − cos ( )] 0 ≤ 𝑛 ≤ 𝑀 − 1
𝑀 𝑀 𝑤(𝑛) = { 𝑀−1
0, 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
Hamming 8𝜋 6.6𝜋 53dB 2𝜋𝑛
𝑀 𝑀 𝑤(𝑛) = {0.54 − 0.46 cos (𝑀 − 1) 0≤𝑛 ≤𝑀−1
0, 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
Ideal or desired impulse response functions for different filters is as mentioned in Table 2
10.3 ALGORITHM 1:
Step (1) Set the values of passband edge frequency and length of the filter to obtain the desired
frequency response.
Step (2) Assign the variables hd as desired impulse response and hna as the cut-off frequency in
rad/sec.
Step (3) For adjusting the filter order of the given window, it must be an odd number and the order
of filter must be one less than that of the window
Step (4) Design an order N for a low pass digital FIR filter with angular cutoff frequency wc rad/s
using the command fir1( ).
Step (5) Obtain the frequency response of digital filter using the command freqz( ).
Step (6) Plot the magnitude and frequency response of the FIR Low pass filter.
10.4 MATLAB PROGRAM 1:
% Program for designing and implementing the low pass FIR filter using
% window functions
clear all
wc = input('Enter the pass band edge frequency in radians:');% example wc =
0.2*pi
N = input('Enter the length of the filter:');
hd = zeros(1,N);
a = (N-1)/2;
hna = wc/pi;
k = 1:1:((N-1)/2);
n = k - 1-((N-1)/2);
hd(k) = (sin(wc*n))./(pi*n);% Desired response for low pass filter
w_rec(k) = 1;
% w_bar = 1-2*abs(k -(N-1)/2)/(N-1);
% w_ham = 0.54 - 0.46*cos(2*pi*(k-1)/(N-1));
% w_han = 0.5 - 0.5*cos(2*pi*(k-1)/(N-1));
% w_blk = 0.42 - 0.5*cos(2*pi*(k-1)/(N-1))+0.08*cos(2*pi*(k-1)/(N-1));
hn(k) = hd(k);% if the window function is rectangular window, otherwise
%hd(k) should be multiplied by the window function given.
hn = [hn hna]
w =0:pi/16:pi
Hw1 = hna*exp(-j*w*a);
Hw2 = 0;
for m =1:1:a
Hw3 = hn(m)* ((exp(j*w*(1-m)))+(exp(-j*w*(1-m+2*a))));
Hw2 = Hw2+Hw3;
end
Hw = Hw2 +Hw1
H_mag = abs(Hw)
plot(w/pi,H_mag,'k');
grid;
title('Magnitude response of LPF FIR filter')
xlabel('Normalized frequency,\omega/\pi')
ylabel('Magnitude')
10.5 RESULT:
Enter the pass band edge frequency in radians: 1
Enter the length of the filter: 7
hn =
0.0150 0.1447 0.2678 0.3183
10.6 Expected Waveform:
The magnitude response of the FIR Low pass filter is as shown in Fig.10.1. for rectangular window
and Fig.10.1. for Hanning window
1.2
0.8
Magnitude
0.6
0.4
0.2
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized frequency, /
Fig. 10.1 magnitude response of the FIR Low pass filter for Rectangular window
Magnitude response of LPF FIR filter
1.4
1.2
0.8
Magnitude
0.6
0.4
0.2
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized frequency, /
Fig. 10.2 magnitude response of the FIR Low pass filter for Hanning window
magnitude response.
π 3π
2. Design an ideal band pass filter with frequency response Hd (ω) = 1, for ≤ |ω| ≤ .
4 4
10.8 CONCLUSION:
From the magnitude response of FIR low pass filter, it can be observed that the ringing
effect or the oscillations near the band edges are very prominent in rectangular window,
while the other window functions display tapering of oscillations decaying to zero.
FIR filters are inherently stable and satisfy the linear phase property
The type of window function to be used depends on the specifications of the given
system including pass band frequency, stop band frequency and order of the filter ‘M’.
11.1 Objective: To Design an FIR filter for the given specifications and frequency response for the
given system using frequency sampling technique.
11.2 Theory:
In frequency sampling technique, the design approach for the system function H (z) can be obtained
from the samples H(k) of the frequency response H(ejω) given by Eq.38. If h(n) is the impulse
response of an M-point FIR filter and H(k) be its M-point DFT then system function H(z) is
represented as Eq.39.
1−𝑒 −𝑗𝜔𝑀 𝐻(𝑘)
𝐻(𝑒 𝑗𝜔 ) = ∑𝑀−1
𝑘=0 (38)
𝑀 1−𝑒 −𝑗𝜔 𝑒 𝑗2𝜋𝑘/𝑀
1−𝑧 −𝑀 𝐻(𝑘)
H(z) = ∑𝑀−1
𝑛=0 ℎ(𝑛)𝑧
−𝑛
= ∑𝑀−1
𝑘=0 (39)
𝑀 1−𝑧 −1 𝑒 𝑗2𝜋𝑘/𝑀
𝐻(0) 𝑘=0
Where, H(k) = 𝐻(𝑒 𝑗2𝜋𝑘/𝑀 ) = {
𝐻 ∗ (𝑀 − 𝑘) 𝑘 = 1, 2, … , 𝑀 − 1
For linear phase filters, h(n) = ± h(M – 1 – N). where + for type 1 and type 2 linear phase filters
and – for type 3 and type 4 linear phase filters.
Consider an ideal low pass filter Hd(ejω), choose the filter length M and then sample Hd(ejω) at M
equi-spaced frequencies between 0 and 2π. The actual response H(ejω) is represented as interpolation
of the samples H(k) as shown in Fig.11.1
.
Fig. 11.1 Ideal and approximated response H(ejω) represented as interpolation of the samples H(k)
From the frequency samples, the approximation error, which is the difference between the ideal and
the actual response, is zero at the sampled frequencies. This approximation error at all other
frequencies depends on the shape of the ideal response; that is, the sharper the ideal response, the
larger the approximation error. The error is larger near the band edges and smaller within the band.
Usually, the optimum design method with variation of number of samples ‘M’, is used to minimize
error in the stopband by varying values of the transition band samples.
11.3 ALGORITHM:
Step (1) Set the values of length of the filter (M) to obtain the desired frequency response.
Step (2) Calculate the frequency sampling index ‘α’ and frequency of sampling ‘w1’
Step (3) Assign the variables Hrs as Ideal impulse response, Hdr as the desired frequency response
and wd1 as the ideal frequency to obtain the impulse response plot.
Step (4) The function Hr_Type 2 is used to obtain the low pass filter coefficients for the impulse
response.
Step (5) Obtain the frequency response of digital filter using the function freqz_m( ).
Step (6) Plot the magnitude and frequency response of the FIR Low pass filter using Frequency
Sampling technique.
% Consider low pass filter specifications: Example 14, Page 246 Vinay K Ingle.
% wp =0 .2*pi
% ws =0 .3*pi,
% Rp =0 .25 dB
% As = 50 dB
% Design an FIR filter using the frequency sampling approach.
% Solution Let us choose M =20 sothat we have a frequency sample at wp, that is,
% at k = 2:
% wp =0.2*pi = (2*pi/20)* 2
% and the next sample at ws, that is, at k = 3:
% ws =(0.3*pi/20)% 3
% Thus we have 3 samples in the passband [0 < w <wp] and 7 samples in the
stopband [ws < w < pi].
%We have Hr (k) = [1 ,1,1,0,...,0(15 zeros) ,1,1]
%Since M = 20, a = (20-1)/2 =9.5 and since this is a Type-2 linear-phase filter,
we have
% angle of H(k)= [-9.5 *pi*k for 0< k < 9 and +9.5 *pi*(20 -k) for 10< k < 19
% we assemble H (k) and determine the impulse response h(n). The MATLAB script
follows:
clear all
M = 20;
alpha = (M-1)/2;
l = 0:M-1;
wl = (2*pi/M)*l;
Hrs = [1,1,1,zeros(1,15),1,1]; %Ideal Amp Res sampled
Hdr = [1,1,0,0];
wd1 = [0,0.25,0.25,1]; %Ideal Amp Res for plotting
k1 = 0:floor((M-1)/2);
k2 = floor((M-1)/2)+1:M-1;
angH = [-alpha*(2*pi)/M*k1, alpha*(2*pi)/M*(M-k2)];
H = Hrs.*exp(j*angH);
h = real(ifft(H,M));
[db,mag,pha,rd,w]=freqz_m(h,1);
[Hr,ww,a,L]=Hr_Type2(h);
subplot(2,2,1);plot(wl(1:11)/pi,Hrs(1:11),'o',wd1,Hdr);
axis([0,1,-0.1,1.1]);
title('Frequency Samples: M=20')
xlabel('frequency in pi units');
ylabel('Hr(k)')
subplot(2,2,2);
stem(l,h);
axis([-1,M,-0.1,0.3])
title('Impulse Response');
xlabel('n');
ylabel('h(n)');
subplot(2,2,3);
plot(ww/pi,Hr,wl(1:11)/pi,Hrs(1:11),'o');
axis([0,1,-0.2,1.2]);
title('Amplitude Respons')
xlabel('frequency in pi units');
ylabel('Hr(w)')
subplot(2,2,4);
plot(w/pi,db);
axis([0,1,-60,10]);
grid
title('Magnitude Response');
xlabel('frequency in pi units');
ylabel('Decibels');
mag = abs(H);
db = 20*log10((mag+eps)/max(mag));
pha = angle(H);
% pha = unwrap(angle(H));
grd = grpdelay(b,a,w);
% grd = diff(pha);
% grd = [grd(1) grd];
% grd = [0 grd(1:1:500); grd; grd(2:1:501) 0];
% grd = median(grd)*500/pi;
11.5 RESULT:
The magnitude response of the FIR Low pass filter using frequency sampling technique is as shown
in Fig.11.2.
Frequency Samples: M=20 Impulse Response
0.3
1
0.2
Hr(k)
h(n)
0.5 0.1
0
0
-0.1
0 0.5 1 0 5 10 15 20
frequency in pi units n
Amplitude Respons Magnitude Response
1 0
Decibels
-20
Hr(w)
0.5
-40
0
-60
0 0.5 1 0 0.5 1
frequency in pi units frequency in pi units
Fig. 11.2 Magnitude response of the FIR Low pass filter using frequency sampling technique
11.7 Conclusion:
Observe the sampling technique with different values of ‘M’ and analyze the ripples present in
the transition band to get better result of attenuation in stopband of specified range.
Perform the frequency sampling technique for low pass, high pass and band pass filters and
analyze the frequency response for optimized design of FIR filters.
Implementation of Filters for a LTI systems requires the three important elements to describe digital
filter structures. These elements are (i) Adder, (ii) Multiplier (gain) and (iii) Delay element (shift)
These basic elements can be used to describe various structures of both IIR and FIR filters.
MATLAB is a convenient tool in the development of these structures that require operations on
polynomials.
where bn and an are the coefficients of the filter. We have assumed without loss of generality that a0
=1. The order of such an IIR filter is called N if aN ≠ 0. The difference equation representation of an
IIR filter is expressed as Eq.41.
𝑦(𝑛) = ∑𝑀 𝑁
𝑚=0 𝑏𝑚 𝑥(𝑛 − 𝑚) − ∑𝑚=1 𝑎𝑚 𝑦(𝑛 − 𝑚) (41)
Three different structures can be used to implement an IIR filter:
1. Direct form: In this form the difference equation is implemented directly as given. There are two
parts to this filter, namely the moving average part and the recursive part (or equivalently, the
numerator and denominator parts). Therefore this implementation leads to two versions: direct form
I and direct form II structures.
2. Cascade form: In this form the system function H(z) is factored into smaller 2nd-order sections,
called biquads. The system function is then represented as a product of these biquads. Each biquad is
implemented in a direct form, and the entire system function is implemented as a cascade of biquad
sections.
3. Parallel form: This is similar to the cascade form, but after factorization, a partial fraction
expansion is used to represent H(z) as a sum of smaller 2nd-order sections. Each section is again
implemented in a direct form, and the entire system function is implemented as a parallel network of
sections. IIR filters are generally described using the rational form version (or the direct form
structure) of the system function.
12.3.1 Example : CASCADE FORM
In this form the system function H(z) is written as a product of 2nd-order sections with real
coefficients as in Eq.42. This is done by factoring the numerator and denominator polynomials into
their respective roots and then combining either a complex conjugate root pair or any two real roots
into 2nd-order polynomials in Eq.42. If we assume that N is an even integer, then H(z) is represented
as in Eq.44.
𝑏0 +𝑏1 𝑧 −1 +⋯+𝑏𝑀 𝑧 −𝑁
𝐻(𝑧) = (42)
1+𝑎1 𝑧 −1 +⋯+𝑎𝑁 𝑧 −𝑁
𝑏 𝑏
1+ 1 𝑧 −1 +⋯+ 𝑁 𝑧 −𝑁
𝑏 𝑏
= 𝑏0 1+𝑎0 𝑧 −1 +⋯+𝑎0 𝑧 −𝑁 (43)
1 𝑁
1+𝐵 𝑧 −1 +𝐵 𝑧 −2
𝑏0 ∏𝑁 𝑘,1 𝑘,2
𝑘=1 1+𝐴 𝑧 −1 +𝐴 𝑧 −2 (44)
𝑘,1 𝑘,2
Where, K is equal to N/2 , and Bk,1, Bk,2, Ak,1, and Ak,2 are real numbers representing the
coefficients of 2nd-order sections. The 2nd-order section Hk(z) is given in Eq.45
𝑌𝑘+1 (𝑧) 1+𝐵𝑘,1 𝑧 −1 +𝐵𝑘,2 𝑧 −2
𝐻𝑘 (𝑧) = = ; 𝑘 = 1, 2, … , 𝐾 (45)
𝑌𝑘 (𝑧) 1+𝐴𝑘,1 𝑧 −1 +𝐴𝑘,2 𝑧 −2
With 𝑌1 (𝑧) = 𝑏0 𝑋(𝑧); 𝑌𝐾+1 (𝑧) = 𝑌(𝑧) is called the kth biquad section. The input to the kth
biquad section is the output from the (k − 1)th biquad section, and the output from the kth biquad is
the input to the (k+1)th biquad. Now each biquad section Hk(z) can be implemented in direct form II,
as shown in Fig.12.1.The entire filter is then implemented as a cascade of biquads .
𝑏 ,0 ≤ 𝑛 ≤ 𝑀 −1
ℎ(𝑛) = { 𝑛 (47)
0, 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
The difference equation representation is giveN as Eq.48.
y(n) = b0x(n) + b1x(n − 1) +… + bM−1x(n −M + 1) (48)
which is a linear convolution of finite support.
The order of the filter is M − 1, and the length of the filter (which is equal to the number of
coefficients) is M. The FIR filter structures are always stable, and they are relatively simple
compared to IIR structures.
Furthermore, FIR filters can be designed to have a linear-phase response, which is desirable in some
applications.
We will consider the following four structures:
1. Direct form: In this form the difference equation is implemented directly as given.
2. Cascade form: In this form the system function H(z) is factored into 2nd-order factors, which are
then implemented in a cascade connection.
3. Linear-phase form: When an FIR filter has a linear-phase response, its impulse response exhibits
certain symmetry conditions. In this form we exploit these symmetry relations to reduce
multiplications by about half.
4. Frequency-sampling form: This structure is based on the DFT of the impulse response h(n) and
leads to a parallel structure. It is also suitable for a design technique based on the sampling of
frequency response H(ejω).
= 𝑏0 ∏𝐾
𝑘=1(1 + 𝐵𝑘,1 𝑧
−1
+ 𝐵𝑘,2 𝑧 −2 ) (50)
𝑀
where K is equal to ⌊ 2 ⌋, and Bk,1 and Bk,2 are real numbers representing the coefficients of 2nd -order
Example:
b=[1 -3 11 -27 18]; a=[16 12 2 -4 -1];
b0 = b(1); b = b/b0; a0 = a(1); a = a/a0; b0 = b0/a0;
M = length(b); N = length(a);
if N > M
b = [b zeros(1,N-M)];
elseif M > N
a = [a zeros(1,M-N)]; N = M;
else
NM = 0;
end
K = floor(N/2); B = zeros(K,3); A = zeros(K,3);
if K*2 == N
b = [b 0]; a = [a 0];
end
broots = cplxpair(roots(b)); aroots = cplxpair(roots(a));
for i=1:2:2*K
Brow = broots(i:1:i+1,:); Brow = real(poly(Brow));
B(fix((i+1)/2),:) = Brow;
Arow = aroots(i:1:i+1,:); Arow = real(poly(Arow));
A(fix((i+1)/2),:) = Arow;
end
12.6 Result:
Output
A=
1.0000 1.0000 0.5000
1.0000 -0.2500 -0.1250
B=
1.0000 -0.0000 9.0000
1.0000 -3.0000 2.0000
b0 = 0.0625
12.7 Expected Block Diagram:
The Digital FIR Low pass filter structure using Direct to Cascade form is as shown in Fig.12.2
Fig 12.2 Digital FIR Low pass filter structure using Direct to Cascade form
Step 5: Compile
Project compile file (Ctrl + F7)
Step 6: Build
Project build (F7)
(This will create a .out file in project folder)
Step 7: Load the program
N=ceil(2*pi*k/tw);
if((N%2)==0)
N=N+1;
printf(“%d”,N);
for(n=0;n<N;n++)
{
if(As<=21)
win[n]=1;
else if(As>21 && As<=53)
win[n]=0.54-0.46*cos(2*pi*n/(N-1));
else
win[n]=0.42-0.5*cos(2*pi*n/(N-1))+0.08*cos(4*pi*n/(N-1));
}
alpha=(N-1)/2;
for(n=0;n<N;n++)
{
if(n==alpha)
{
h[n]=wc/pi;
hd[n]=h[n]*win[n];
}
else
{
h[n]=sin(wc*(n-alpha))/(pi*(n-alpha));
hd[n]=h[n]*win[n];
}
}
printf("low pass filter coeffs:");
for(n=0;n<N;n++)
printf("%f\t",hd[n]);
}
13.5 Simulation:
Enter the pass band frequency: 1500
Enter the stop band frequency: 2000
Enter the stop band attenuation in dB: 60
Enter the sampling frequency: 8000
N=97
Low pass filter coeffs:
0.000000 0.000003 0.000005 -0.000019 -0.000035 0.000036 0.000106
-0.000019 -0.000214 -0.000076 0.000330 0.000288 -0.000387 -
0.000631 0.000287 0.001069 0.000078 -0.001495
-0.000794 0.001722 0.001874 -0.001505 -0.003204 0.000584 0.004513
Fig.13.1 Magnitude response of the FIR Low pass filter using rectangular window technique