Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 46

ELECTRONICS AND COMMUNICATION

ENGINEERING DEPARTMENT

ORIENTATION COURSE ON

SYSTEMS LAB

MAR ATHANASIUS COLLEGE OF ENGINEERING


KOTHAMANGALAM
LIST OF EXPERIMENTS

1. LTI system response and testing

2. Discrete Fourier Transform (DFT) and Inverse Discrete Fourier Transform (IDFT)

3. Analog filter design using MathLab

4. IIR filter design

5. FIR filter design using window techniques

6. Control systems

7. PLDs

8. CPLDs

9. FPGAs

10. DSPs

2
Experiment No:1 LTI system response and testing Date:

Aim:
To plot the Impulse response, step response ,and to test linearity, causality, and stability.

Tools and functions:


Matlab, Randan, filter,

Theory:
A signal is a description of how one parameter varies with another parameter. For instance,
voltage changing over time in an electronic circuit, or brightness varying with distance in an image.
A system is any process that produces an output signal in response to an input signal.

. Continuous signals are


usually represented with
parentheses, while discrete
signals use brackets. All signals
use lower case letters, reserving
the upper case for the
frequency domain. the input
signal is called: x(t) or x[n],
while the output is called: y(t) or
y[n].

A system is said to be
homogeneous if an amplitude change in
the input results in an identical amplitude
change in the output. That is, if x[n] results
in y[n], then kx[n] results in ky[n], for any
signal, x[n], and any constant, k.

3
A system is said to be additive if added signals pass through it without interacting. Formally,
if x1[n] results in y1[n], and if x2[n] results in y2[n], then x1[n]+x2[n] results in y1[n]+y2[n]

%To plot IMPULSE RESPONSE


b=[1];
a=[1,-1,0.9];
x=impulseinput (0,-20,100);
n=[-20:100];
h=filter(b,a,x);
stem(n,h);
title('IMPULSE RESPONSE');
xlabel('TIME INDEX');
ylabel('h(n)');

%To generate unit IMPULSE INPUT


function[x,n]=input(n0,n1,n2);%n0-start of pulse position;
n=[n1:n2]; %n1,n2=lower & upper limits resply
x=[(n-n0)>=0]; %if (n-n0)>=0,returns 1 else 0
stem(n,x); % Descrete sequence plot to visualise
title('STEP INPUT');
xlabel('TIME INDEX');
% saving the file as stepinput.m

To plot IMPULSE RESPONSE


b=[1];
a=[1,-1,0.9];
x=impulseinput (0,-20,100);
n=[-20:100];
h=filter(b,a,x);
stem(n,h);
title('IMPULSE RESPONSE');
xlabel('TIME INDEX');
ylabel('h(n)');

4
%To plot step RESPONSE
b=[1];
a=[1,-1,0.9];
x=stepinput(0,-20,100);
n=[-20:100];
h=filter(b,a,x);
stem(n,h);
title('STEP RESPONSE');
xlabel('TIME INDEX');
ylabel('s(n)');

To generate unit step input


function[x,n]=stepinput(n0,n1,n2);%n0-start of pulse position;
n=[n1:n2]; %n1,n2=lower & upper limits resply
x=[(n-n0)>=0]; %if (n-n0)>=0,returns 1 else 0
stem(n,x); % Descrete sequence plot to visualise
title('STEP INPUT');
xlabel('TIME INDEX');
% saving the file as stepinput.m

5
%
test

linearity
L=input('length sequence');
alpha=input('input linear coefft:');
beta=input('input linear coefft:');
x=randn(1,L); %input to filter
z=randn(1,L); %input
b=[1];
a=[1,-1,0.9];
y1=filter(b,a,x);
y2=filter(b,a,z);
alphax=alpha*x;
betaz=beta*z;
newinput=alphax+betaz;
y=filter(b,a,newinput);
p=alpha*y1+beta*y2;
g=y-p
if(g<1.0e-10);
display('linear');
else
display('not linear');
end;

To find stability

function[s]=input(n1,n2);
n0=0;
n=[n1:n2];
x=[(n-n0)==0]; ;
b=[1];
a=[1,-1,0.9];
h=filter(b,a,x);
s=sum(abs(h))
if(s<9999)
6
display('stable')
else display('not stable')
end

Experiment no: 02 Discrete Fourier Transform (DFT) Date:

7
Aim:
To compute convolution and deconvolution of two sequences and to compute and plot DFT and
IDFFT of a given sequence .

Tools and functions:

Matlab, signal processing tool, conv, fft deconv, idfft

Theory:

Fourier analysis is a family of mathematical techniques, all based on decomposing signals intosinusoids. The
discrete Fourier transform (DFT) is the family member used with digitized signals.

A signal can be either continuous or discrete, and it can be either periodic or aperiodic. The combination of these two
features generates the four categories, described below and illustrated in Figure.
Aperiodic-Continuous
This includes, for example, decaying exponentials and the Gaussian curve. These signals extend to both positive and
negative infinity without repeating in a periodic pattern. The Fourier Transform for this type of signal is simply called the
Fourier Transform.
Periodic-Continuous
Here the examples include: sine waves, square waves, and any waveform that repeats itself in a regular pattern from
negative to positive infinity. This version of the Fourier transform is called the Fourier Series.
Aperiodic-Discrete
These signals are only defined at discrete points between positive and negative infinity, and do not repeat themselves in a
periodic fashion. This type of Fourier transform is called the Discrete Time Fourier Transform.
Periodic-Discrete
These are discrete signals that repeat themselves in a periodic fashion from negative to positive infinity. This class of
Fourier Transform is sometimes called the Discrete Fourier Series, but is most often called the Discrete Fourier
Transform.

8
DFT is a sequence, with samples equally spaced in frequency, of the fourier transform of the signal.
To derive and interpret the DFT
1. Utilize the relationship between periodic sequences and finite length sequences.
2. For that we can apply the fourier series results of periodic sequences to the representation of finite
length sequences.
Let us consider a finite length sequence (1)

To each finite length sequence of length N we can always associate a periodic sequence

(2)

Since x[n ] is assumed to have finite length N, there is no overlap between the terms x[n+rN] for
different values of r.
Equation (2) can be alternatievely written as
= x[(n modulo N)] = x[((n))N]  (3)
Equation (3) is equivalent to eqn.(2) only when x[n] has length less than or equal to N
To visualize eqn.(3), ie. representation of a periodic sequence by a finite length sequence corresponds to
wrapping the finite_duration sequence x[n ] around a cylinder with a circumference equal to the sequence
length. As we repeatedly traverse the circumference of the cylinder we see the finite-length sequence
periodically repeated.
The finite duration sequence x[k] corresponding to one period of the discrete fourier series coefficient ~
can be referred to as the DFT.
Thus, the DFT, X[k],is related to the DFS coefficient by,

 (4)

x[k]=x[((k))N] (5)
But
(6)

9
e (7)

(6)and (7) can be written as

DFT analysis equation

 DFT synthesis equation

(Inverse DFT equation)

Circular Convolution
If x1[n] and x2[n] are two finite duration sequences both of length N, with DFT’s x1[k] and x2[k].If we want
to find out a new sequence x3[n] whose DFT is x3[k] =x1[k] x3[k].
To get the sequence x3[n] we can use circular convolution

Computation of DFT

Computation of the N-point DFT corresponds to the computation of N samples of the fourier transform of N
equally spaced frequencies wk=2πk/N,that is N points on the unit circle in the z-plane. The various
algorithms used for the digital computation of the N-point DFT are called fast fourier transform(FFT).

FAST FOURIER TRANSFORM

DFT equation is

Let us define ,then,

FFT reduces the number of complex multiplications from N2 toN/2log2N by utilizing the two basic properties of the twiddle
factor, they are

Symmetry property:

Periodicity property:

10
In FFT computation the N samples are decomposed into N/2 or N/4 or N/8 …..etc samples utilizing the
above properties of twiddle factor to reduce the number of multiplication and addition.

% Illustration of Convolution
%
a = input('Type in the first sequence = ');
b = input('Type in the second sequence = ');
c = conv(a, b);
M = length(c)-1;
n = 0:1:M;
disp('output sequence =');disp(c)
stem(n,c)
xlabel('Time index n'); ylabel('Amplitude');

Result:

Type in the first sequence = [1,2,3,4,5]


Type in the second sequence = [3,4,5,6]
output sequence =
3 10 22 40 58 58 49 30

% Illustration of DFT Computation


%
% Read in the length N of sequence and the desired
% length M of the DFT
N = input('Type in the length of the sequence = ');
M = input('Type in the length of the DFT = ');
% Generate the length-N time-domain sequence
u = [ones(1,N)];
% Compute its M-point DFT
U = fft(u,M);
% Plot the time-domain sequence and its DFT
t = 0:1:N-1;
stem(t,u)
title('Original time-domain sequence')
xlabel('Time index n'); ylabel('Amplitude')
pause
subplot(2,1,1)
k = 0:1:M-1;
stem(k,abs(U))
title('Magnitude of the DFT samples')
xlabel('Frequency index k'); ylabel('Magnitude')
subplot(2,1,2)
stem(k,angle(U))
title('Phase of the DFT samples')
xlabel('Frequency index k'); ylabel('Phase')

11
% Numerical Computation of Fourier transform Using DFT
k = 0:15; w = 0:511;
x = cos(2*pi*k*3/16);% Generate the length-16 sinusoidal sequence
X = fft(x); % Compute its 16-point DFT
XE = fft(x,512); % Compute its 512-point DFT
% Plot the frequency response and the 16-point DFT samples
plot(k/16,abs(X),'o', w/512,abs(XE))
xlabel('\omega/\pi'); ylabel('Magnitude')

% Linear Convolution Via the DFT


%
% Read in the two sequences
x = input('Type in the first sequence = ');
h = input('Type in the second sequence = ');
% Determine the length of the result of convolution
L = length(x)+length(h)-1;
% Compute the DFTs by zero-padding
XE = fft(x,L); HE = fft(h,L);
% Determine the IDFT of the product
y1 = ifft(XE.*HE);
% Plot the sequence generated by DFT-based convolution and
% the error from direct linear convolution
n = 0:L-1;
12
subplot(2,1,1)
stem(n,y1)
xlabel('Time index n');ylabel('Amplitude');
title('Result of DFT-based linear convolution')
y2 = conv(x,h);
error = y1-y2;
subplot(2,1,2)
stem(n,error)
xlabel('Time index n');ylabel('Amplitude')
title('Error sequence')

Deconvolution examples:

Deconvolution
Deconvolution, or polynomial division, is the inverse operation of convolution. Deconvolution is useful in
recovering the input to a known filter, given the filtered output. This method is very sensitive to noise in the
coefficients, however, so use caution in applying it.

The syntax for deconv is


[q,r] = deconv(b,a)

b = [4 5 6];
c = conv(a,b)
c=
4 13 28 27 18
Now use deconv to deconvolve b from c
[q,r] = deconv(c,a)
q=
456
r=
00000

%Example ii
% Illustration of Deconvolution
%
Y = input('Type in the convolved sequence = ');
H = input('Type in the convolving sequence = ');
[X,R] = deconv(Y,H);
disp('Sequence x[n]');disp(X);
disp('Remainder Sequence r[n]');disp(R);

RESULT

Type in the convolved sequence = [3 10 22 40 58 58 49 30]


Type in the convolving sequence = [3 4 5 6]
Sequence x[n]
1.0000 2.0000 3.0000 4.0000 5.0000

% Illustration of IDFT Computation


%
% Read in the length K of the DFT and the desired
% length N of the IDFT
K = input('Type in the length of the DFT = ');
N = input('Type in the length of the IDFT = ');
% Generate the length-K DFT sequence
13
k = 0:K-1;
V = k/K;
% Compute its N-point IDFT
v = ifft(V,N);
% Plot the DFT and its IDFT
stem(k,V)
xlabel('Frequency index k'); ylabel('Amplitude')
title('Original DFT samples')
pause
subplot(2,1,1)
n = 0:N-1;
stem(n,real(v))
title('Real part of the time-domain samples')
xlabel('Time index n'); ylabel('Amplitude')
subplot(2,1,2)
stem(n,imag(v))
title('Imaginary part of the time-domain samples')
xlabel('Time index n'); ylabel('Amplitude')

14
Experiment no:3 Analog filter design Date:

Aim:
To design analog filters from filter specification using matlab analog prototyping functions..

Tools and functions:

Matlab, signal processing tool, filter functions

Theory:

The matlab toolbox provides a number of functions to create lowpass analog prototype
filters with cutoff frequency of 1, the first step in the classical approach to IIR filter design.
Butterworth [z,p,k] = buttap(n)
Chebyshev type I [z,p,k] = cheb1ap(n,Rp)
Chebyshev type II [z,p,k] = cheb2ap(n,Rs)
Elliptic [z,p,k] = ellipap(n,Rp,Rs)
The second step in the analog prototyping design technique is the frequency transformation of a lowpass
prototype.
Butterworth Filter
The Butterworth filter provides the best Taylor Series approximation to the ideal lowpass filter response at
= 0 and=; for any orderN, maximally flat response.

Chebyshev Type I Filter


The Chebyshev type I filter minimizes the absolute difference between the ideal and actual frequency
response over the entire passband by incorporating an equal ripple of Rp dB in the passband. Stopband
response is maximally flat.

Chebyshev Type II Filter


15
The Chebyshev type II filter minimizes the absolute difference between the ideal and actual frequency
response over the entire stopband, by incorporating an equal ripple of Rs dB in the stopband. Passband
response is maximally flat. Magnitude

Elliptic Filter
Elliptic filters are equiripple in both the passband and stopband. They generally meet filter requirements
with the lowest order of any supported filter type.

% 4-th Order Analog Butterworth Lowpass Filter Design


%
format long
% Determine zeros and poles
[z,p,k] = buttap(4);
disp('Poles are at');disp(p);
% Determine transfer function coefficients
[pz, pp] = zp2tf(z, p, k);
% Print coefficients in descending powers of s
disp('Numerator polynomial'); disp(pz)
disp('Denominator polynomial'); disp(real(pp))
omega = [0: 0.01: 5];
% Compute and plot frequency response
h = freqs(pz,pp,omega);
plot (omega,20*log10(abs(h)));grid
xlabel('Normalized frequency'); ylabel('Gain, dB');

RESULT

Poles are at
-0.38268343236509 + 0.92387953251129i
-0.38268343236509 - 0.92387953251129i

16
-0.92387953251129 + 0.38268343236509i
-0.92387953251129 - 0.38268343236509i

Numerator polynomial
0 0 0 0 1

Denominator polynomial
Columns 1 through 4

1.00000000000000 2.61312592975275 3.41421356237309 2.61312592975275

Column 5

1.00000000000000

% Program to
Design Butterworth Lowpass Filter
%
% Type in the filter order and passband edge frequency
N = input('Type in filter order = ');
Wn = input('3-dB cutoff angular frequency = ');
% Determine the transfer function
[num,den] = butter(N,Wn,'s');
% Compute and plot the frequency response
omega = [0: 200: 12000*pi];
h = freqs(num,den,omega);
plot (omega/(2*pi),20*log10(abs(h)));
xlabel('Frequency, Hz'); ylabel('Gain, dB');

RESULT
Type in filter order = 6
3-dB cutoff angular frequency = 1000

% Program to
Design Type 1
Chebyshev
Lowpass
Filter
%

17
% Read in the filter order, passband edge frequency
% and passband ripple in dB
N = input('Order = ');
Fp = input('Passband edge frequency in Hz = ');
Rp = input('Passband ripple in dB = ');
% Determine the coefficients of the transfer function
[num,den] = cheby1(N,Rp,2*pi*Fp,'s');
% Compute and plot the frequency response
omega = [0: 200: 12000*pi];
h = freqs(num,den,omega);
plot (omega/(2*pi),20*log10(abs(h)));
xlabel('Frequency, Hz'); ylabel('Gain, dB');

RESULT
rder = 6
Passband edge frequency in Hz = 3000
Passband ripple in dB = 5

% Program to Design Elliptic Lowpass Filter


%
% Read in the filter order, passband edge frequency,
% passband ripple in dB and minimum stopband
% attenuation in dB
N = input('Order = ');
Fp = input('Passband edge frequency in Hz = ');
Rp = input('Passband ripple in dB = ');
Rs = input('Minimum stopband attenuation in dB = ');
% Determine the coefficients of the transfer function
[num,den] = ellip(N,Rp,Rs,2*pi*Fp,'s');
% Compute and plot the frequency response
omega = [0: 200: 12000*pi];
h = freqs(num,den,omega);
plot (omega/(2*pi),20*log10(abs(h)));
xlabel('Frequency, Hz'); ylabel('Gain, dB');
.

18
RESULT

Order = 4
Passband edge frequency in Hz = 3000
Passband ripple in dB = 3
Minimum stopband attenuation in dB = 40

High pass, band pass, and band stop filter design.

# Design an analog Butterworth high pass filter with the following specifications.
Pass band edge= 4000Hz
Stop band edge=1000Hz
Pass band ripple=0.1 dB

% Determine the coefficients of the transfer function


[N,wn]=buttord(8000*pi, 2000*pi, .1, 40, 's' );
[num,den] = butter(N,wn, 'high', 's');
% Compute and plot the frequency response
omega = [0: 200: 12000*pi];
h = freqs(num,den,omega);
plot (omega/(2*pi),20*log10(abs(h)));
xlabel('Frequency, Hz'); ylabel('Gain, dB');

19
Band pass filter.
# Design an analog elliptic band pass filter with the following specifications.
Pass band edge= 4000Hz and 7000Hz
Stop band edge=3000Hz and 8000Hz
Pass band ripple=1 dB
Stopband attenuation=22dB

%matlab program
wp=[4000 7000]*2*pi ; ws=[3000 8000]*2*pi;

[N,wn]=ellipord(wp, ws,1, 50, 's' );


[num,den] = ellip(N,1,22,wn, 's');
% Compute and plot the frequency response
omega = [0: 200: 16000*pi];
h = freqs(num,den,omega);
plot (omega/(2*pi),20*log10(abs(h)));
xlabel('Frequency, Hz'); ylabel('Gain, dB');

Band stop filter


# Design an analog elliptic band stop filter with the following specifications.
stop band edge= 4000Hz and 5000Hz
pass band edge=3000Hz and 8000Hz
Pass band ripple=1 dB
20
Stopband attenuation=60dB

%matlab program
ws=[4000 5000]*2*pi ; wp=[3000 8000]*2*pi;

[N,wn]=ellipord(wp, ws,1, 60, 's' );


[num,den] = ellip(N,1,22,wn, 'stop', 's');
% Compute and plot the frequency response
omega = [0: 200: 16000*pi];
h = freqs(num,den,omega);
plot (omega/(2*pi),20*log10(abs(h)));
xlabel('Frequency, Hz'); ylabel('Gain, dB');

QUESTIONS
# Find out the analog frequency response for all different types of filters
Low pass
High pass
Band pass
Band stop
For the following filter approximations.
Butterworth
Chbyshev type-I
Chebyshev type-II
Elliptic

21
Experiment. No 4. IIR filter design Date:

Aim : To design an IIR filter using various methods.

1. IIR Filter Mapping method


2. Impulse invariant method
3. Bilinear Transformation method

1. Mapping method.
One of the simplest methods of digitizing an analog filter into digital filter is to approximate the
differential equation by an equivalent difference equation. This analog to digital transformation technique
does map a stable analog filter into a stable digital filter.
Matlab Functions:
Buttord, Butter, freqz, subplot , plotdr

Example 1.
% Butterworth Low Pass Filter
% Sampling Frequency = 16 KHz
% Fp=1800 Hz Pass band Frequency
% Fs=4000Hz Stop band frequency
% Rp= 0.01 dB Pass band attenuation
% Rs= 50 dB Stop band attenuation
[N,Wn]=buttord(1800/8000,4000/8000,0.01,50);
[B,A]=butter(N,Wn); % returns denominator and numerator coefficients.
w=0:.01:pi;
H=freqz(B,A,w);
subplot(2,1,1),plot(w/pi,abs(H));
subplot(2,1,2),plot(w/pi,angle(H));

Example 2.
% Chebyshev Low Pass Filter
% Sampling Frequency = 16 KHz
% Fp=1800 Hz Pass band Frequency
22
% Fs=4000Hz Stop band frequency
% Rp= 0.01 dB Pass band attenuation
% Rs= 50 dB Stop band attenuation

[N,Wn]=cheb1ord(1800/8000,4000/8000,0.01,50);
[B,A]=cheby1(N,1,Wn);
w=0:.01:pi;
H=freqz(B,A,w);
subplot(2,1,1),plot(w/pi,abs(H));
subplot(2,1,2),plot(w/pi,angle(H));

Example 3.
% Chebyshev2 Low Pass Filter
% Sampling Frequency = 16 KHz
% Fp=1800 Hz Pass band Frequency
% Fs=4000Hz Stop band frequency
% Rp= 0.01 dB Pass band attenuation
% Rs= 50 dB Stop band attenuation

[N,Wn]=cheb2ord(1800/8000,4000/8000,0.01,50);
[B,A]=cheby2(N,10,Wn);
w=0:.01:pi;
H=freqz(B,A,w);
subplot(2,1,1),plot(w/pi,abs(H));
subplot(2,1,2),plot(w/pi,angle(H));

23
% Elliptic Low Pass Filter
% Sampling Frequency = 16 KHz
% Fp=1800 Hz Pass band Frequency
% Fs=4000Hz Stop band frequency
% Rp= 1 dB Pass band attenuation
% Rs= 30 dB Stop band attenuation
[N,Wn]=ellipord(1800/8000,4000/8000,0.01,50);
[B,A]=ellip (N,1,30,Wn);
w=0:.01:pi;
H=freqz(B,A,w);
subplot(2,1,1),plot(w/pi,abs(H));
subplot(2,1,2),plot(w/pi,angle(H));

2. Impulse invariant method


One approach to digital filter design is to try to make the digital filter response to a standard DT
excitation a sampled version of the analog filter response to the corresponding standard CT excitation. This
idea leads to the impulse-invariant design procedures. Impulse invariant design makes the response of the
DT system to a DT impulse a sampled version of the response of the CT system to a CT impulse.

24
Impulse invariant design is probably the most straightforward technique for approximating an analog
filter with a digital filter. If the transfer function of the analog filter in the Laplace domain is Hs(S), then the
impulse response is h(t). If h(t) is sampled, a discrete-time function h[n] is formed and the z transform of
h[n] can be taken to yield the desired z-domain transfer function Hz(z).

Using Impulse Invarient method determine the frequency response of a filter for the following
specification.

Function: [bz,az]=impinvar(bs,as,fs)
where bs – vector coefficient of numerator in S domain
as – vector coefficient of denominator in S domain
fs – sampling rate
bz – vector coefficient of numerator in Z domain
az – vector coefficient of denominator in Z domain

Example.
n=5; %filter order
rp=0.5; %pass band ripple
rs=40; %stop band attenuation.
wn=0.4; % normalized cut off frequency.
[bs,as]=ellip(n,rp,rs,wn); %filter coefficients in S domain
[bz,az]=impinvar(bs,as,1); % filter coefficients in Z domain
[h,w]=freqz(bz,az,256); % frequency response in Z domain
subplot(2,1,1),plot(w/pi,abs(h)); %frequency response plot
subplot(2,1,2),plot(w/pi,angle(h)); %phase response plot

3. Bilinear Transformation

The impulse-invariant design techniques try to make the digital filter’s DT-domain response match
the corresponding analog filter’s CT-domain response to a corresponding standard excitation. Another way
to approach digital filter design is to try to make the frequency response of the digital filter match the
frequency response of the analog filter. But, just as a DT-domain response can never exactly match a CT-
domain response, the frequency response of a digital filter cannot exactly match the frequency response of
an analog filter. One reason, mentioned earlier, for this is that the frequency response of a DT system is
inherently periodic. When a sinusoidal CT signal is sampled to create a sinusoidal DT excitation, if the
frequency of the CT signal is changed by an integral multiple of the sampling rate, the DT signal does not
change at all. Another popular method of filter design is using the bilinear transformation given by

25
2 z-1 2 + sTs
s = -- ----- or z = --------
Ts z+1 2 - sTs

Transformation function
[bz,az]=bilinear(bs,as,fs);
where bz – vector of Z domain zero location
az– vector of Z domain pole location
bs – vector of S domain zero location
as – vector of S domain pole location

Example.
n=5; %filter order
rp=0.5; %pass band ripple
rs=40; %stop band attenuation.
wn=0.4; % normalized cut off frequency.
[bs,as]=ellip(n,rp,rs,wn); %filter coefficients in S domain
[bz,az]=bilinear(bs,as,1); % filter coefficients in Z domain
[h,w]=freqz(bz,az,256); % frequency response in Z domain
subplot(2,2,1),plot(w/pi,abs(h)); %frequency response plot
subplot(2,2,2),plot(w/pi,angle(h)); %phase response plot

26
Experiment no: 05 Date:

FIR filter design using window techniques

Aim:
To design FIR filters using windowing techniques.

Tools and functions:


Matlab, signal processing tools, windowing functions.

Theory:

WINDOW DESIGN TECHNIQUES


The basic idea behind the window design is to choose a proper ideal frequency-selective filter(which always
has a noncausal,infinite-duration impulse response) and the truncate (or window) its impulse response to
obtain a linear-phase and causal FIR filter.
To obtain an FIR filter from ,one has to truncate on both sides.To obtain a causal and
linear-phase FIR of length M,we must have

This operation is called “windowing”.In general, can be thought of as being formed by the product of
and a window function as follows:
= (6)
Where

Depending on how we define above, we obtain different window designs.

which is the rectangular window defined earlier.


Basic Window Design Idea: For the given filter specifications choose the filter length M and a
window function for the narrowest main lobe width and the smallest side lobe attenuation possible.
RECTANGULAR WINDOW
This is the simplest window function but provides the worst performance from the viewpoint of stopband
attenuation. It was defined earlier by

Its frequency response function is

which is the amplitude response.

27
Figure : Rectangular window, M = 45

From the observation of plots in Fig we can make several observations.


1. The amplitude response has the first zero at ,where

Hence the width of the main lobe is .Therefore the approximate transition bandwidth is
.
2. The magnitude of the first side lobe (which is also the peak side lobe magnitude) is approximately at
and is given by

Comparing this with the main lobe amplitude, which is equal to M, the peak side lobe magnitude is

of the main lobe amplitude.


3. The accumulated amplitude response has the first side lobe magnitude at 21 dB. This results in the
minimum stop band attenuation of 21dB irrespective of the window length M.
4. Using the minimum stopband attenuation, the transition band width can be accurately computed. It is
shown in the accumulated amplitude response plot in Figure .This computed exact transition
bandwidth is

which is about half the approximate bandwidth of .


Clearly, this is a simple window operation in the time domain and an easy
function to analyze in the frequency domain. However, there are two main problems. First, the minimum
28
stop band attenuation of 21 dB is insufficient in practical applications. Second, the rectangular windowing
being a direct truncation of the infinite length ,it suffers from the Gibbs phenomenon. If we increase
M, the width of each side lobe will decrease, but the area under each lobe will remain constant.
Therefore the relative amplitudes of side lobes will remain constant, and the minimum stopband attenuation
will remain at 21 dB. This implies that all ripples will bunch up near the band edges, It is shown in Figure .

Figure : Gibbs phenomenon

Since the rectangular window is impractical in many applications, we consider


other window functions, many of which bear the names of the people who first proposed them. Although
these window functions can also be analyzed similar to the rectangular window, we present only their
results.

BARTLETT WINDOW
Since the Gibbs phenomenon results from the fact that the rectangular window has a sudden transition from
0 to 1 (or 1 to 0),Bartlett suggested a more gradual transition in the form of a triangular window, which is
given by

(10)
This window and its frequency-domain responses are shown in Figure below

Figure :Bartlett (triangular) window, M=4

HANNING WINDOW
This is a raised cosine window function given by

29
(11)

This window and its frequency-domain responses are shown in Figure below

Figure : Hanning window ,M= 4

HAMMING WINDOW
This window is similar to the Hanning window except that it has a small amount of discontinuity and is
given by

(12)

This window and its frequency-domain responses are shown in Figure below

Figure : Hamming window, M=45

BLACKMAN WINDOW
This window is also similar to the previous two but contains a second harmonic term and is given by

30
(13)

This window and its frequency-domain responses are shown in Figure .

Figure : Blackman window , M = 45

In table 1 we provide a summary of window function characteristics in terms of their transition widths (as a
function of M ) and their minimum stopband attenuation in dB. Both the approximate as well as the exact
transition bandwidths are given. Note that the transition widths and the stop band attenuations increase as we
go down the table. The Hamming window appears to be the best choice for many applications.

TABLE 1: Summary of commonly used window function characteristics


Window Name Transition Width ∆ω Min. Stopband Attenuation
Approximate Exact value
Rectangular 21 dB

Bartlett 25 dB

Hanning 44 dB

Hamming 53 dB

Blackman 74 dB

KAISER WINDOW
This is one of the most useful and optimum windows. It is optimum in the sense of providing a large main
lobe width for the given stop band attenuation, which implies the sharpest transition width. The window
function is due to J.K. Kaiser and is given by

Where is the modified zero-order Bessel function , and is a parameter that depends on M and that
can be chosen to yield various transition widths and near-optimum stopband attenuation. This window can
provide different transition widths for the same M, which is something other windows lack. For example,
 if = 5.658 , then the transition width is equal to , and the minimum stopband
attenuation is equal to 60 dB. This is shown in Figure

31
Figure : Kaiser window , M = 45 , = 5.658

 if = 4.538 , then the transition width is equal to , and the minimum stopband
attenuation is equal to 50 dB.
Hence the performance of this window is comparable to that of the Hamming window. DESIGN
EQUATIONS
Given
Norm. transition width

Filter order

MATLAB IMPLEMENTATION
MATLAB provides routines to implement window functions and brief description of these routines is given
below.
 w = boxcar(M) returns the M-point rectangular window function in array w
 w = triang(M)returns the M-point Bartlett (triangular) window function in array w
 w = hanning(M) returns the M-point Hanning window function in array w
 w = hamming(M) returns the M-point Hamming window function in array w
 w = blackman(M) returns the M-point Blackman window function in array w
 w = kaiser(M,beta) returns the beta-valued M-point rectangular window function in array w.
Using these routines , we can use MATLAB to design FIR filters based on the window technique, which
also requires an ideal lowpass impulse response .
Matlab Examples.
low pass filter
Design a low pass filter with cut of frequency wc=.5*pi , with N=25 and stop band attenuation >50 db.
%since stop band attenuation >50 db, we may select Blackman or hamming window.

wc=.5*pi; % cut of frequency.


N=25; % Order of the filter.
b=fir1(N,wc/pi,hamming(N+1)); %FIR type 1 matlab function generates filter
%coefficients
w=.1:.01:pi;
H= freqz(b,1,w); %filter frequency response
Subplot(2,2,1), plot(w/pi, abs(H));
Title('Frequency response');
Xlabel('Frequency'); ylabel('Magnitude');
Subplot(2,2,2), plot(w/pi, angle(H));
32
Title('Phase response');
Xlabel('Frequency'); ylabel('Phase');
Hold on %hold figure variables.
b=fir1(N,wc/pi,blackman(N+1)) % Blackman window, FIR type1 matlab call
W=.1:.01:pi;
H= freqz(b,1,w); %frequency response
Subplot(2,2,1), plot(w/pi,'r',abs(H));
Subplot(2,2,2), plot(w/pi,'r',angle(H));

%example for stop bad attenuation >70 dB


Design a low pass filter with cut of frequency wc=.5*pi , with N=25 and stop band attenuation >50 db.
%since stop band attenuation >70 db, we may select Kaiser window.
Wc=.5*pi; % cut of frequency.
N=25; % Order of the filter.
b=fir1(N,wc/pi,kaiser (N+1,0.5)); %FIR type 1 matlab function generates filter %coefficients for
kaiser window with β 0.5
w=.1:.01:pi;
H= freqz(b,1,w); %filter frequency response
Subplot(2,2,1), plot(w/pi, abs(H),’r’);
Title(‘Frequency response’);
Xlabel(‘Frequency’); ylabel(‘Magnitude’);
Subplot(2,2,2), plot(w/pi, angle(H),’r’);
Title(‘Phase response’);
Xlabel(‘Frequency’); ylabel(‘Phase’);
Hold on %hold figure variables.
b=fir1(N,wc/pi,kaiser (N+1,3.5)) % Kaiser window, FIR type1 matlab call, with β 3.5
W=.1:.01:pi;
H= freqz(b,1,w); %frequency response
Subplot(2,2,1), plot(w/pi, ‘r’abs(H),’b’);
Subplot(2,2,2), plot(w/pi,’r’ angle(H);

33
%multiband filter design using fir2 matlab function.
% Design of Multiband FIR Filter Using Hamming Window
%
fpts = [0 0.28 0.3 0.5 0.52 1];
mval = [0.3 0.3 1.0 1.0 0.7 0.7];
b = fir2(100,fpts,mval);
[h,omega] = freqz(b,1,512);
plot(omega/pi,abs(h));grid;
xlabel('\omega/\pi'); ylabel('Magnitude');

34
35
Experiment no: 06 Control System Date:

Aim:
To plot the Bode diagram of the given system and to determine the gain crossover frequency, phase
crossover frequency, gain margin and phase margin from the given transfer function.

The transfer function of the given system is ( 20(s+1))/(s(s+5)(s2+2s+10))

Theory:

A typical closed loop control system is represented as shown.

R(s) E(s) C(s)


G(s)

B(s)
H(s)

Closed loop transfer function of the system C(s)/R(s)=G(s)/(1+G(s)H(s))

Any linear time invariant system is described by its transfer function. Transfer function of a system
is defined as a ratio of Laplace transform of the output to the Laplace transform of the input with zero initial
conditions. Frequency response of a system is the response of the system for sinusoidal input signal of
various frequencies. The frequency response can be obtained by different methods. One such method is
Bode plot. Bode plot consists of two graphs. One is a plot of the magnitude in decibels versus frequency in
log scale and the second one is the plot of phase angle versus frequency in log scale.

Bode plot helps in finding the system stability. Stability can be found by evaluating gain
margin and phase margin. Gain margin is defined as the factor by which the gain of the system is allowed to
increase before the system reaches instability. Phase margin is the amount of additional phase lag required to
bring the system to the point of instability.

To find the gain and phase margin, two important frequencies are required. They are gain and
phase crossover frequencies. Phase crossover is a point on the phase plot at which the angle is + or – 180
degrees. The frequency at phase crossover is phase crossover frequency. The negative of the gain at phase
crossover is gain margin. The gain crossover is a point on the gain plot at which the magnitude is equal to 1
or 0dB. The frequency at gain crossover is gain crossover frequency. Phase margin is 180 degrees plus angle
at gain crossover frequency.

36
Program :

num = [0,0,0,20,20]; %numerator coefficients of transfer function


den = conv([1,5,0],[1,2,10]); % denominator coefficients of transfer function
sys = tf(num,den); %transfer function.
w = logspace(-1,2,100);
bode(sys,w); % generates bode pplot.
[gm,pm,wpc,wgc]=margin(sys) % determines margin, cross over parameters.

Matlab functions used :

tf : Creation of transfer functions or conversion to transfer function.


SYS = TF(NUM,DEN) creates a continuous-time transfer function SYS with
numerator(s) NUM and denominator(s) DEN.

bode : Bode frequency response of LTI models.

BODE(SYS) draws the Bode plot of the LTI model SYS (created with
either TF, ZPK, SS, or FRD). The frequency range and number of
points are chosen automatically.

BODE(SYS,{WMIN,WMAX}) draws the Bode plot for frequencies


between WMIN and WMAX (in radians/second).

BODE(SYS,W) uses the user-supplied vector W of frequencies, in


radian/second, at which the Bode response is to be evaluated.
See LOGSPACE to generate logarithmically spaced frequency vectors.

MARGIN Gain and phase margins and crossover frequencies.

[Gm,Pm,Wcg,Wcp] = MARGIN(SYS) computes the gain margin Gm, the


phase margin Pm, and the associated frequencies Wcg and Wcp,
for the SISO open-loop model SYS (continuous or discrete).
The gain margin Gm is defined as 1/G where G is the gain at

37
the -180 phase crossing. The phase margin Pm is in degrees.

Result:

Gain margin - gm = 3.1369


Phase margin - pm =103.6573
Phase crossover frequency - wpc = 4.0132
Gain crossover frequency - wgc = 0.4426

38
Experiment No: 07 PLDs Date:

AIM:
To familiarize the PLDs like PLA, PAL and GAL. Realize basic gates using the above devices.

SOFTWARE TOOLS

WARP GALXY
WARP NOVA

THEORY:
PLDs were the first chips that could be used to implement a flexible digital logic design in hardware. In other words, a
couple of the 7400-series TTL parts (ANDs, ORs, and NOTs) could be removed from the circuit board and replace them with a
single PLD. The classification of PLDs include Programmable Logic Array (PLA), Programmable Array Logic (PAL), and
Generic Array Logic (GAL).

PLDs are often used for address decoding, where they have several clear advantages over the 7400-series TTL parts that
they replaced. First, of course, is that one chip requires less board area, power, and wiring than several do. Another advantage is
that the design inside the chip is flexible, so a change in the logic doesn't require any rewiring of the board. Rather, the decoding
logic can be altered by simply replacing that one PLD with another part that has been programmed with the new design.
Inside each PLD is a set of fully connected macrocells. These macrocells are typically comprised of some amount of
combinatorial logic (AND and OR gates, for example) and a flip-flop. In other words, a small Boolean logic equation can be built
within each macrocell. This equation will combine the state of some number of binary inputs into a binary output and, if
necessary, store that output in the flip-flop until the next clock edge.

PAL16V8

Active pull-up on data input

CMOS flash technology for

User programmable macrocell


Polarity control
Registered or combinational operation selection

16 inputs and 8 outputs

39
40
PROGRAM

Program to realize AND gate using PALCE16V8.


Program is written for WARP GALAXY and the output is observed using the tool WARP NOVA.

entity simple is port(


a, b : in bit;
x: buffer bit);
end simple;
architecture break_out of simple is
begin
x <= a and b;
end break_out;

RESULT

AND inputs : a, b
AND output : x
Experiment No: 08 CPLDs Date:

AIM:

To familiarize the CPLDs like FLASH370. Realize basic gates using the above devices.

SOFTWARE TOOLS

WARP GALXY
WARP NOVA

THEORY:

As chip densities increased, it was natural for the PLD manufacturers to evolve their
products into larger (logically, but not necessarily physically) parts called Complex
Programmable Logic Devices (CPLDs). For most practical purposes, CPLDs can be thought
of as multiple PLDs (plus some programmable interconnect) in a single chip. The larger size
of a CPLD allows you to implement either more logic equations or a more complicated
design. In fact, these chips are large enough to replace dozens 7400-series parts.

Figure contains a block diagram of a hypothetical CPLD. Each of the four logic blocks
shown there is the equivalent of one PLD. However, in an actual CPLD there may be more
(or less) than four logic blocks. Note also that these logic blocks are themselves comprised of
macrocells and interconnect wiring, just like an ordinary PLD.

Unlike the programmable interconnect within a PLD, the switch matrix within a
CPLD may or may not be fully connected. In other words, some of the theoretically possible
connections between logic block outputs and inputs may not actually be supported within a
given CPLD. The effect of this is most often to make 100% utilization of the macrocells very
difficult to achieve. Some hardware designs simply won't fit within a given CPLD, even
though there are sufficient logic gates and flip-flops available.
Because CPLDs can hold larger designs than PLDs, their potential uses are more
varied. They are still sometimes used for simple applications like address decoding, but more
often contain high-performance control-logic or complex finite state machines. At the high-
end (in terms of numbers of gates), there is also a lot of overlap in potential applications with
FPGAs. Traditionally, CPLDs have been chosen over FPGAs whenever high-performance
logic is required. Because of its less flexible internal architecture, the delay through a CPLD
(measured in nanoseconds) is more predictable and usually shorter.

FLASH370 Ultralogic High-density Flash CPLD

Flash erasable CMOS CPLDs


Intelligent product term allocator
Simple timing model
Flexible clocking

BLOCK DIAGRAM OF CY7C374

PROGRAM
Program to realize AND gate using CY7C371.
Program is written for WARP GALAXY and the output is observed using the tool WARP NOVA.

entity simple is port(


a, b : in bit;
x: buffer bit);
end simple;
architecture break_out of simple is
begin
x <= a and b;
end break_out;

RESULT
AND inputs : a, b
AND output : x
Experiment No: 09 FPGAs Date:

AIM:
To familiarize the FPGSs like FLASH370. Design basic gates using CY380005P208-1NC

THEORY:

Field Programmable Gate Arrays (FPGAs) can be used to implement just about any hardware design.
The development of the FPGA was distinct from the PLD/CPLD evolution just described. Figure illustrates a
typical FPGA architecture. There are three key parts of its structure: logic blocks, interconnect, and I/O blocks.
The I/O blocks form a ring around the outer edge of the part. Each of these provides individually selectable
input, output, or bi-directional access to one of the general-purpose I/O pins on the exterior of the FPGA
package. Inside the ring of I/O blocks lies a rectangular array of logic blocks. And connecting logic blocks to
logic blocks and I/O blocks to logic blocks is the programmable
interconnect wiring.

The logic blocks within an FPGA can be as small and


simple as the macrocells in a PLD or larger and more complex.
However, they are never as large as an entire PLD, as the logic
blocks of a CPLD are. Remember that the logic blocks of a
CPLD contain multiple macrocells. But the logic blocks in an
FPGA are generally nothing more than a couple of logic gates
or a look-up table and a flip-flop.
Because of all the extra flip-flops, the architecture of
an FPGA is much more flexible than that of a CPLD. This makes FPGAs better in register-heavy and pipelined
applications. They are also often used in place of a processor-plus-software solution, particularly where the
processing of input data streams must be performed at a very fast pace. In addition, FPGAs are usually denser
(more gates in a given area) and cost less than their CPLD cousins, so they are the de facto choice for larger
logic designs.

Ultra 380005 Ultra Logic very High speed 5K gate CMOS FPGA

Very High speed


Unparalleled FPGA performance
Flexible logic cell architecture
148 I/O pins
4 dedicated input
SOFTWARE TOOLS

WARP GALXY
WARP NOVA

PROGRAM
Program to realize AND gate using CY7C371.
Program is written for WARP GALAXY and the output is observed using the tool WARP NOVA.

entity simple is port(


a, b : in bit;
x: buffer bit);
end simple;
architecture break_out of simple is
begin
x <= a and b;
end break_out;
RESULT

You might also like