You are on page 1of 70

SREE VIDYANIKETHAN ENGINEERING

COLLEGE
(AUTONOMOUS)
Sree Sainath Nagar, A. Rangampet, Tirupathi - 517102.

Department of Electronics and Communication


Engineering

IV B. Tech.(ECE) I Sem.

Digital Signal Processing Lab (14BT70421)

Lab Record

Name:

Roll No.:

1
Name of the Lab (Course Code): Digital Signal Processing Lab (14BT70421)
Class: IV B. Tech (ECE) I Sem.
TABLE OF CONTENTS
EXP.NO DATE NAME OF THE EXPERIMENT PAGE.NO. SIGNATURE
1.

2.

3.

4.

5.

6.

7.

8.

9.

10.

11.

12.

13.

2
DATE: EXPERIMENT No.:

FREQUENCY RESPONSE OF ANALOG BUTTERWORTH


FILTERS (LP/HP/BP/BR)
Aim:- To determine the frequency response of analog butterworth Low Pass,
High Pass, Band Pass & Band reject filters using MATLAB functions.
Tools required: PC loaded with MATLAB r2008a software.
Theory:
The frequency response of the Butterworth filter is maximally flat (i.e. has
no ripples) in the pass band and rolls off towards zero in the stop band. When
viewed on a logarithmic Bode plot, the response slopes off linearly towards
negative infinity. A first-order filter's response rolls off at 6 dB per octave (20
dB per decade) (all first-order low pass filters have the same normalized
frequency response). A second-order filter decreases at 12 dB per octave, a
third-order at 18 dB and so on. Butterworth filters have a monotonically
changing magnitude function with , unlike other filter types that have non-
monotonic ripple in the pass band and/or the stop band.
Compared with a Chebyshev Type I/Type II filter or an elliptic filter, the
Butterworth filter has a slower roll-off, and thus will require a higher order to
implement a particular stop band specification, but Butterworth filters have a
more linear phase response in the pass-band than Chebyshev Type I/Type II and
elliptic filters can achieve.

Source code:
clc;
clear all;
A=input('Enter (1-4) 1.Low pass 2.High pass 3.Band pass 4.Band stop ');
switch (A)
case 1
rp=input('pass band ripples ');
rs=input('stop band ripples ');
fp=input('pass band freq ');
fs=input('stop band freq ');
f=input('Sampling freq ');
wp=fp/f;
ws=fs/f;
[n,wn]=buttord(wp,ws,rp,rs,'s');
[b,a]=butter(n,wn,'s');

3
case 2
rp=input('pass band ripples');
rs=input('stop band ripples');
fp=input('pass band freq');
fs=input('stop band freq');
f=input('Sampling freq');
wp=fp/f;
ws=fs/f;
[n,wn]=buttord(wp,ws,rp,rs,'s');
[b,a]=butter(n,wn,'high','s');
case 3
rp=input('pass band ripples');
rs=input('stop band ripples');
fs1=input('stop band freq-1');
fp1=input('pass band freq-1');
fp2=input('pass band freq-2');
fs2=input('stop band freq-2');
f=input('Sampling freq');
wp1=fp1/f;
ws1=fs1/f;
wp2=fp2/f;
ws2=fs2/f;
wp=[wp1 wp2];
ws=[ws1 ws2];
[n,wn]=buttord(wp,ws,rp,rs,'s');
[b,a]=butter(n,wn,'bandpass','s');
case 4
rp=input('pass band ripples');
rs=input('stop band ripples');
fp1=input('pass band freq-1');
fs1=input('stop band freq-1');
fs2=input('stop band freq-2');
fp2=input('pass band freq-2');
f=input('Sampling freq');
wp1=fp1/f;
ws1=fs1/f;
wp2=fp2/f;
ws2=fs2/f;
wp=[wp1 wp2];
ws=[ws1 ws2];
[n,wn]=buttord(wp,ws,rp,rs,'s');
[b,a]=butter(n,wn,'stop','s');
end

4
w=0:0.01:pi;
[h,wm]=freqs(b,a,w);
m=20*log10(abs(h));
a=angle(h);
subplot(2,1,1);
plot(wm/pi,m);
ylabel('Gain in dB');
xlabel('Norm.freq');
title('MAGNITUDE RESPONSE');
grid on;
subplot(2,1,2);
plot(wm/pi,a);
ylabel('Phase in radians');
xlabel('Norm.freq');
title('PHASE RESPONSE');
grid on;

Command window:
Enter (1-4) 1.Low pass 2.High pass 3.Band pass 4.Band stop 1
pass band ripples 3
stop band ripples 15
pass band freq 1200
stop band freq 1800
Sampling freq 4000

5
Butterworth filter:
Low pass: High pass:

Band stop: Band pass:

6
Result:
Analog Butterworth Filters were modelled using MATLAB functions and their
frequency response for defined specifications was plotted.

7
DATE: EXPERIMENT No.:

FREQUENCY RESPONSE OF ANALOG CHEBYSHEV


FILTERS (LP/HP/BP/BR)
Aim:- To determine the frequency response of analog chebyshev (type-1)
Low Pass, High Pass, Band Pass & Band reject filters using MATLAB
functions.
Tools required: PC loaded with MATLAB r2008a software.
Theory:
Chebyshev filters are analog or digital filters having a steeper roll-off and
more pass band ripple (type I) or stop band ripple (type II) than Butterworth
filters. Chebyshev filters have the property that they minimize the error between
the idealized and the actual filter characteristic over the range of the filter but with
ripples in the pass band. This type of filter is named after Pafnuty
Chebyshev because its mathematical characteristics are derived from Chebyshev
polynomials.
Because of the pass band ripple inherent in Chebyshev filters, the ones that have
a smoother response in the pass band but a more irregular response in the stop
band are preferred for some applications.
Chebyshev filters are analog or digital filters having a steeper roll-off and more
passband ripple (type I) or stopband ripple (type II) than Butterworth filters.
Chebyshev filters have the property that they minimize the error between the
idealized and the actual filter characteristic over the range of the filter, [citation
needed] but with ripples in the passband. This type of filter is named after Pafnuty
Chebyshev because its mathematical characteristics are derived from Chebyshev
polynomials.

Using Chebyshev filter design, there are two subgroups,

1. Type-1 Chebyshev filter: These filters are all pole filters. In the passband, these
filters show equi-ripple behaviour and they have monotonic characteristics in
the stopband.
2. Type-2 Chebyshev filter: This Filter Contains zeros as well as poles.

8
Source code:
clc;
clear all;
A=input('Enter (1-4) 1.Low pass 2.High pass 3.Band pass 4.Band stop ');
switch (A)
case 1
rp=input('pass band ripples ');
rs=input('stop band ripples ');
fp=input('pass band freq ');
fs=input('stop band freq ');
f=input('Sampling freq ');
wp=fp/f;
ws=fs/f;
[n,wn]=cheb1ord(wp,ws,rp,rs,'s');
[b,a]=cheby1(n,rp,wn,'s');
case 2
rp=input('pass band ripples');
rs=input('stop band ripples');
fp=input('pass band freq');
fs=input('stop band freq');
f=input('Sampling freq');
wp=fp/f;
ws=fs/f;
[n,wn]=cheb1ord(wp,ws,rp,rs,'s');
[b,a]=cheby1(n,rp,wn,'high','s');
case 3
rp=input('pass band ripples');
rs=input('stop band ripples');
fs1=input('stop band freq-1');
fp1=input('pass band freq-1');
fp2=input('pass band freq-2');
fs2=input('stop band freq-2');
f=input('Sampling freq');
wp1=fp1/f;
ws1=fs1/f;
wp2=fp2/f;
ws2=fs2/f;
wp=[wp1 wp2];
ws=[ws1 ws2];
[n,wn]=cheb1ord(wp,ws,rp,rs,'s');
[b,a]=cheby1(n,rp,wn,'bandpass','s');
case 4
rp=input('pass band ripples');
9
rs=input('stop band ripples');
fp1=input('pass band freq-1');
fs1=input('stop band freq-1');
fs2=input('stop band freq-2');
fp2=input('pass band freq-2');
f=input('Sampling freq');
wp1=fp1/f;
ws1=fs1/f;
wp2=fp2/f;
ws2=fs2/f;
wp=[wp1 wp2];
ws=[ws1 ws2];
[n,wn]=cheb1ord(wp,ws,rp,rs,'s');
[b,a]=cheby1(n,rp,wn,'stop','s');
end
w=0:0.01:pi;
[h,wm]=freqs(b,a,w);
m=20*log10(abs(h));
a=angle(h);
subplot(2,1,1);
plot(wm/pi,m);
ylabel('Gain in dB');
xlabel('Norm.freq');
title('MAGNITUDE RESPONSE');
grid on;
subplot(2,1,2);
plot(wm/pi,a);
ylabel('Phase in radians');
xlabel('Norm.freq');
title('PHASE RESPONSE');
grid on;

Command Window:
Enter (1-4) 1.Low pass 2.High pass 3.Band pass 4.Band stop 2
pass band ripples 3
stop band ripples 15
pass band freq 1800
stop band freq 1200
Sampling freq 4000

10
Chebyshev filter:
Low pass: High pass:

Band pass: Band stop:

11
Result:
Analog Chebyshev (Type-1) Filters were modelled using MATLAB functions
and their frequency response for defined specifications was plotted.

12
DATE: EXPERIMENT No.:

DESIGN OF FIR FILTERS (LP/HP/BP/BR) USING


FREQUENCY SAMPLING METHOD
Aim:- To design the FIR Low Pass, High Pass, Band Pass & Band reject
filters by frequency sampling method using MATLAB functions.
Tools required: PC loaded with MATLAB r2008a software.
Theory:
The frequency-sampling method for FIR filter design is perhaps the simplest and
most direct technique imaginable when a desired frequency response has been
specified. It consists simply of uniformly sampling the desired frequency
response, and performing an inverse DFT to obtain the corresponding
(finite) impulse response. The results are not optimal, however, because the
response generally deviates from what is desired between the samples. When the
desired frequency-response is under sampled, which is typical, the
resulting impulse response will be time aliased to some extent. It is important to
evaluate the final impulse response via a simulated DTFT (FFT with lots of zero
padding), comparing to the originally desired frequency response.

The frequency-sampling method for FIR filter design is illustrated in the context
of the window method for FIR filter design, to which we now turn.

Source code:
clc;
clear all;
fs=10000;
ts=1/fs;
ns=512;
t=[0:ts:ts*(ns-1)];
f1=1000;
f2=1500;
f3=2500;
f4=4000;
f5=4500
x1=sin(2*pi*f1*t);
x2=sin(2*pi*f2*t);
x3=sin(2*pi*f3*t);
x4=sin(2*pi*f4*t);
x5=sin(2*pi*f5*t);

13
x=x1+x2+x3+x4+x5;
N=16;
w=[0.4 0.6];
w1=0.4;
c=input('Enter choice 1.LPF 2.HPF 3.BPF 4.BSF-');
if(c==1)
w=0.4;
B=fir1(N,w);
end
if(c==2)
w=0.4;
B=fir1(N,w,'high');
end
if(c==3)
w=[0.4 0.6];
B=fir1(N,w,'DC-0');
end
if(c==4)
w=[0.4 0.6];
B=fir1(N,w,'DC-1');
end
disp(B)
A=1;
freqz(B,A);
figure;
subplot(2,1,1);
Npts=200;
plot(t(1:Npts),x(1:Npts));
title('Input signal');
xlabel('time');
ylabel('Amplitude');
y=filter(B,A,x);
subplot(2,1,2);
plot(t(1:Npts),y(1:Npts));
title('Filtered signal');
xlabel('time');
ylabel('Amplitude');
figure;
subplot(2,1,1);
xfftmag=abs(fft(x,ns));
xfftmagh=xfftmag(1:length(xfftmag)/2);
f=[1:1:length(xfftmagh)]*fs/ns;
plot(f,xfftmagh);

14
title('Input spectrum');
xlabel('frequency');
ylabel('Amplitude');
subplot(2,1,2);
yfftmag=abs(fft(y,ns));
yfftmagh=yfftmag(1:length(yfftmag)/2);
f=[1:1:length(yfftmagh)]*fs/ns;
plot(f,yfftmagh);
title('Filtered spectrum');
xlabel('frequency');
ylabel('Amplitude');

15
Low pass:

16
High pass:

17
Band pass:

18
Band stop:

19
Result:
FIR Filters were modelled using MATLAB functions and their frequency
response, Input and output spectrum for defined specifications were plotted.

20
DATE: EXPERIMENT No.:

FIR FILTER DESIGN USING WINDOWING TECHNIQUES


Aim:- To design FIR filter (LP/HP/BP/BR) using following windowing
techniques using MATLAB functions.
a) Rectangular window d) Hanning window
b) Triangular window e) Blackmann window
c) Hamming window f) Kaiser window
Tools required: PC loaded with MATLAB r2008a software.
Theory:
A Finite Impulse Response (FIR) filter is a discrete linear time-invariant
system whose output is based on the weighted summation of a finite number
of past inputs. An FIR transversal filter structure can be obtained directly from
the equation for discrete-time convolution.
N 1

y(n) x(k)h(n k) 0 n N 1
k 0

In this equation, x(k) and y(n) represent the input to and output from the filter
at time n. h(n-k) is the transversal filter coefficients at time n. These
coefficients are generated by using FDS (Filter Design Software or Digital
filter design package).

FIR filter is a finite impulse response filter. Order of the filter should be
specified. Infinite response is truncated to get finite impulse response. Placing
a window of finite length does this. Types of windows available are
Rectangular, Bartlett, Hamming, Hanning, Blackmann window etc., This FIR
filter is an all zero filter.
Source code:
clc;
close all;
clear all;
fp=input('Enter the pass band frequency-');
fs=input('Enter the stop band frequency-');
rp=input('Enter the pass band attenuation-');

21
rs=input('Enter the stop band attenuation-');
f=input('Enter the sampling frequency-');
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n=abs(ceil(num/dem));
wp=fp/f;
ws=fs/f;
if(rem(n,2)==0)
m=n+1;
else
m=n;
n=n-1;
end
c=input('Enter req. window 1.Rectangular 2.Triangular 3.Hamming 4.Hanning
5.Blackmann 6.Kaiser');
if(c==1)
w=rectwin(m);
end
if(c==2)
w=triang(m);
end
if(c==3)
w=hamming(m);
end
if(c==4)
w=hann(m);
end
if(c==5)
w=blackman(m);
end
if(c==6)
b=input('Enter beta value');
w=kaiser(m,b);
end
fil=input('Enter req filter 1.LPF 2.HPF 3.BPF 4.BSF-');
if(fil==1)
B=fir1(n,wp,'low',w);
[h,o]=freqz(B,1,256);
end
if(fil==2)
B=fir1(n,wp,'high',w);
[h,o]=freqz(B,1,256);
end

22
if(fil==3)
wn=[wp ws];
B=fir1(n,wn,'band',w);
[h,o]=freqz(B,1,256);
end
if(fil==4)
wn=[wp ws];
B=fir1(n,wn,'stop',w);
[h,o]=freqz(B,1,256);
end
mag=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(o/pi,mag);
title('Magnitude response');
xlabel('Normalized frequency');
ylabel('Gain in dB');
subplot(2,1,2);
plot(o/pi,an);
title('Phase response');
xlabel('Normalized frequency');
ylabel('Gain in dB');
grid on;

COMMAND WINDOW:
Enter the pass band frequency-2000
Enter the stop band frequency-4000
Enter the pass band attenuation-3
Enter the stop band attenuation-15
Enter the sampling frequency-8000
Enter req. window 1.Rectangular 2.Triangular 3.Hamming 4.Hanning
5.Blackmann 6.Kaiser6
Enter beta value 0.5
Enter req filter 1.LPF 2.HPF 3.BPF 4.BSF-2

23
Rectangular window:
Low pass: High pass:

Band pass: Band stop:

24
Triangular window
Low pass: High pass:

Band pass: Band stop:

25
Hamming window:
Low pass: High pass:

Band pass: Band stop:

26
Hanning window:
Low pass: High pass:

Band pass: Band stop:

27
Blackmann window
Low pass: High pass:

Band pass: Band stop:

28
Kaiser window:
Low pass: High pass:

Band pass: Band stop:

29
Result:
FIR Filters were modelled using windowing techniques and their frequency
response for defined specifications were plotted.

30
DATE: EXPERIMENT No.:

IMPLEMENTATION OF IIR DIGITAL FILTER FROM


ANALOG BUTTERWORTH FILTERS (LP/HP/BP/BR) USING
TRANSFORMATION TECHNIQUES
Aim:- To determine the frequency response of IIR butterworth Low Pass,
High Pass, Band Pass & Band reject filters using MATLAB functions.
Tools required: PC loaded with MATLAB r2008a software.
Theory:
The bilinear transformation is a mathematical mapping of variables. In digital
filtering, it is a standard method of mapping the s or analog plane into the z or
digital plane. It transforms analog filters, designed using classical filter design
techniques, into their discrete equivalents.
The bilinear transformation maps the s-plane into the z-plane by
H(z)=H(s)s=2fsz1z+1.

This transformation maps the j axis (from = to +) repeatedly around the


unit circle (ejw, from = to ) by
=2tan1(2fs)
bilinear can accept an optional parameter Fp that specifies prewarping. fp, in
hertz, indicates a match frequency, that is, a frequency for which the frequency
responses before and after mapping match exactly. In prewarped mode, the
bilinear transformation maps the s-plane into the z-plane with the prewarping
option, bilinear maps the j axis (from = to +) repeatedly around the unit
circle (ej, from = to ) by the appropriate formulae.
In prewarped mode, bilinear matches the frequency 2fp (in radians per second)
in the s-plane to the normalized frequency 2fp/fs (in radians per second) in the z-
plane.
The bilinear function works with three different linear system representations:
zero-pole-gain, transfer function, and state-space form.
Source code:
clc;
clear all;
close all;A=input('Enter (1-4) 1.Low pass 2.High pass 3.Band pass 4.Band stop
');
switch (A)
31
case 1
rp=input('pass band ripples ');
rs=input('stop band ripples ');
fp=input('pass band freq ');
fs=input('stop band freq ');
f=input('Sampling freq ');
wp1=fp/f;
ws1=fs/f;
wp=2*f*tan(wp1/2);
ws=2*f*tan(ws1/2);
[n,wn]=buttord(wp,ws,rp,rs,'s');
[num,den]=butter(n,wn,'low','s');
case 2
rp=input('pass band ripples');
rs=input('stop band ripples');
fp=input('pass band freq');
fs=input('stop band freq');
f=input('Sampling freq');
wp1=fp/f;
ws1=fs/f;
wp=2*f*tan(wp1/2);
ws=2*f*tan(ws1/2);
[n,wn]=buttord(wp,ws,rp,rs,'s');
[num,den]=butter(n,wn,'high','s');

case 3
rp=input('pass band ripples');
rs=input('stop band ripples');
fs1=input('stop band freq-1');
fp1=input('pass band freq-1');
fp2=input('pass band freq-2');
fs2=input('stop band freq-2');
f=input('Sampling freq');
wp1=fp1/f;
ws1=fs1/f;
wp2=fp2/f;
ws2=fs2/f;
wp3=[wp1 wp2];
ws3=[ws1 ws2];
wp=2*f*tan(wp3/2);
ws=2*f*tan(ws3/2);
[n,wn]=buttord(wp,ws,rp,rs,'s');
[num,den]=butter(n,wn,'bandpass','s');

32
case 4
rp=input('pass band ripples');
rs=input('stop band ripples');
fp1=input('pass band freq-1');
fs1=input('stop band freq-1');
fs2=input('stop band freq-2');
fp2=input('pass band freq-2');
f=input('Sampling freq');
wp1=fp1/f;
ws1=fs1/f;
wp2=fp2/f;
ws2=fs2/f;
wp3=[wp1 wp2];
ws3=[ws1 ws2];
wp=2*f*tan(wp3/2);
ws=2*f*tan(ws3/2);
[n,wn]=buttord(wp,ws,rp,rs,'s');
[num,den]=butter(n,wn,'stop','s');
end
[b,a]=bilinear(num,den,f);
w=0:0.01:pi;
[h,wm]=freqz(b,a,w);
m=20*log(abs(h));
an=angle(h);
subplot(2,1,1);
plot(wm/pi,m);
grid on;
xlabel('Norm freq');
ylabel('Gain in db');
title('Magnitude response');
subplot(2,1,2);
plot(wm/pi,an);
grid on;
ylabel('Phase in radians');
xlabel('Norm freq');
title('Phase response');

33
Command window:
Enter (1-4) 1.Low pass 2.High pass 3.Band pass 4.Band stop 3
pass band ripples 3
stop band ripples 15
stop band freq-1 500
pass band freq-1 1000
pass band freq-2 2000
stop band freq-2 2500 Sampling freq 6000

Low pass: High pass:

34
Band pass: Band stop:

RESULT:
IIR filters were modelled from Analog Butterworth filters using Bilinear
Transformation and its frequency response were plotted for pre-wrapped
specifications.

35
DATE: EXPERIMENT No.:

IMPLEMENTATION OF IIR DIGITAL FILTER FROM


ANALOG CHEBYSHEV FILTERS (LP/HP/BP/BR) USING
TRANSFORMATION TECHNIQUES
Aim:- To determine the frequency response of IIR chebyshev (type-1) Low
Pass, High Pass, Band Pass & Band reject filters using MATLAB functions.
Tools required: PC loaded with MATLAB r2008a software.
Theory:
Chebyshev filters are analog or digital filters having a steeper roll-off and more
passband ripple (type I) or stopband ripple (type II) than Butterworth filters.
Chebyshev filters have the property that they minimize the error between the
idealized and the actual filter characteristic over the range of the filter,[citation needed]
but with ripples in the passband. This type of filter is named after Pafnuty
Chebyshev because its mathematical characteristics are derived from Chebyshev
polynomials.
The bilinear transform (also known as Tustin's method or Mobius
Transformation) is used in digital signal processing and discrete-time control
theory to transform continuous-time system representations to discrete-time and
vice versa.
The bilinear transform is a special case of a conformal mapping (namely, the
Mbius transformation), often used to convert a transfer function of a linear,
time-invariant (LTI) filter in the continuous-time domain (often called an analog
filter) to a transfer function of a linear, shift-invariant filter in the discrete-
time domain (often called a digital filter although there are analog filters
constructed with switched capacitors that are discrete-time filters). It maps
positions on the axis, , in the s-plane to the unit circle, , in the z-
plane. Other bilinear transforms can be used to warp the frequency response of
any discrete-time linear system (for example to approximate the non-linear
frequency resolution of the human auditory system) and are implementable in the
discrete domain by replacing a system's unit delayswith first order all-pass filters.
The transform preserves stability and maps every point of the frequency response
of the continuous-time filter, to a corresponding point in the frequency response
of the discrete-time filter, although to a somewhat different frequency, as shown
in the Frequency warping section below. This means that for every feature that
one sees in the frequency response of the analog filter, there is a corresponding

36
feature, with identical gain and phase shift, in the frequency response of the
digital filter.
Source code:
clc;
clear all;
close all;A=input('Enter (1-4) 1.Low pass 2.High pass 3.Band pass 4.Band stop
');
switch (A)
case 1
rp=input('pass band ripples ');
rs=input('stop band ripples ');
fp=input('pass band freq ');
fs=input('stop band freq ');
f=input('Sampling freq ');
wp1=fp/f;
ws1=fs/f;
wp=2*f*tan(wp1/2);
ws=2*f*tan(ws1/2);
[n,wn]=cheb1ord(wp,ws,rp,rs,'s');
[num,den]=cheby1(n,rp,wn,'s');
case 2
rp=input('pass band ripples');
rs=input('stop band ripples');
fp=input('pass band freq');
fs=input('stop band freq');
f=input('Sampling freq');
wp1=fp/f;
ws1=fs/f;
wp=2*f*tan(wp1/2);
ws=2*f*tan(ws1/2);
[n,wn]=cheb1ord(wp,ws,rp,rs,'s');
[num,den]=cheby1(n,rp,wn,'high','s');
case 3
rp=input('pass band ripples');
rs=input('stop band ripples');
fs1=input('stop band freq-1');
fp1=input('pass band freq-1');
fp2=input('pass band freq-2');
fs2=input('stop band freq-2');
f=input('Sampling freq');
wp1=fp1/f;
ws1=fs1/f;

37
wp2=fp2/f;
ws2=fs2/f;
wp3=[wp1 wp2];
ws3=[ws1 ws2];
wp=2*f*tan(wp3/2);
ws=2*f*tan(ws3/2);
[n,wn]=cheb1ord(wp,ws,rp,rs,'s');
[num,den]=cheby1(n,rp,wn,'bandpass','s');
case 4
rp=input('pass band ripples');
rs=input('stop band ripples');
fp1=input('pass band freq-1');
fs1=input('stop band freq-1');
fs2=input('stop band freq-2');
fp2=input('pass band freq-2');
f=input('Sampling freq');
wp1=fp1/f;
ws1=fs1/f;
wp2=fp2/f;
ws2=fs2/f;
wp3=[wp1 wp2];
ws3=[ws1 ws2];
wp=2*f*tan(wp3/2);
ws=2*f*tan(ws3/2);
[n,wn]=cheb1ord(wp,ws,rp,rs,'s');
[num,den]=cheby1(n,rp,wn,'stop','s');
end
[b,a]=bilinear(num,den,f);
w=0:0.01:pi;
[h,wm]=freqz(b,a,w);
m=20*log(abs(h));
an=angle(h);
subplot(2,1,1);
plot(wm/pi,m);
grid on;
xlabel('Norm freq');
ylabel('Gain in db');
title('Magnitude response');
subplot(2,1,2);
plot(wm/pi,an);
grid on;
ylabel('Phase in radians');
xlabel('Norm freq');

38
title('Phase response');

Command window:
Enter (1-4) 1.Low pass 2.High pass 3.Band pass 4.Band stop 2
pass band ripples 3
stop band ripples 15
pass band freq1 800
stop band freq1 200
Sampling freq 4000

Low pass: High pass:

39
Band pass: Band stop:

RESULT:
IIR filters were modelled from Analog Chebyshev Type-1 filters using Bilinear
Transformation and its frequency response were plotted for prewrapped
specifications.

40
FAMILIARIZATION WITH CODE COMPOSER STUDIO

General Procedure to work on Code Composer Studio V4 :


Configuring your target:
Below is the procedure to Configure C6748 Experimentor board.

Step T1:
Launch the CCS v4 icon from the Desktop or goto All Programs ->Texas Instruments ->CCSv4

Step T2:
Choose the location for the workspace, where your project will be saved.

Step T3:
Click the CCS icon from the welcome page to go the workbench, it is marked in the below picture.

Step T4:
From the Target menu select New target Configuration
Target -> New target Configuration.

41
It will open a window like given below.

Specify any arbitrary target name. For Eg., 6748config.ccxml (Extension should be .ccxml).
Location will set one default folder in current user account. Its also allowed to change the location.
Click Finish it will open a configuration window for the created target.

Step T5:
Select the Connection: Texas instruments XDS100v1 USB Emulator
Select the Device: TMS320C6748.

*To make the search easy type 6748 in the space provided.

Check the box TMS320C6748 and finally Click Save.

42
Next goto Advanced tab give the suitable gel file path as shown below.

Step T6:
Go to view option and select the Target Configuration:
View->Target Configuration.
A wizard will open in the workspace expand the User Defined folder and you can find your target,
Right click on 6748config.ccxml and select the Launch Selected Configuration.

Step T7:
Connect the target
Target -> Connect Target

Now our target is successfully configured and connected.

In future we no need to repeat these steps. If we are working with the same hardware we can just open
the already configured target and launch the selected configuration and connect it.

43
Procedure to create New Project

Program 1:
Procedure to create a simple non-real time project Hello world
Step P1:
Change the Perspective Debug to C/C++ from the right corner of the CCS

Step P2:
Go to File New CCS Project.

Step P3:
Specify the name of the project in the space provided
Eg., Project Name: Hello World
Click Next

44
Select the project type

Project Type: C6000

Click Next

*However our target is based on C6000 family, Based on the family we need to select the Project
Type.

Select the C/C++ indexers


Full C/C++ Indexer (Slow but accurate)
Click Next

Set the project settings window as shown below.

45
.

Click finish

Step P4: To write the program take one file.

Go to File New Source File.

Specify the arbitrary source file name. It should be in the source folder(current project name.).

Note:

Extension of the source file must be the


language what we preferred to write the
code.
Eg:
For c-> .c
C++ -> .cpp
Assembly -> .asm 46
Type your C Code

Step P5:

Build the program to check your code


have any errors and warnings.

Go to

Project Build active project.

If your code doesnt have any errors and warnings, a message will be printed in the console window
that

Build Complete for the project

Problems window display errors or warnings, if any.

47
Step P6:
After successful Build, Debug your code in to the hardware by selecting the option

Target Debug Active project.

During debug ccs will display following error message.

48
Now press reset button in 6748 hardware then click on retry.

Once you click on retry ccs eill load program on to processor and then ccs will guide us to debug
mode, if it is not done automatically.
Change the Perspective C/C++ to Debug from the right corner of the CCS.

Step P7:
Now you can run the code, by selecting the option run from the dialog box else you can
Go to Target Run

49
Once you run the program the output will be printed in the Console Window.

50
DATE: EXPERIMENT No.:

VERIFICATION OF LINEAR CONVOLUTION


Aim:- To develop source code for Linear Convolution and verify using CCS
v4.0 on OMAPL138 Experimenter Kit.
Tools required:
1. PC loaded with Code Composer Studio v4.0 software
2. OMAPL138 Experimenter Kit ( configured as TMS320C674X)

Theory:
Convolution is a formal mathematical operation, just as multiplication, addition,
and integration. Addition takes two numbers and produces a third number, while
convolution takes two signals and produces a third signal. Convolution is used in
the mathematics of many fields, such as probability and statistics. In linear
systems, convolution is used to describe the relationship between three signals of
interest: the input signal, the impulse response, and the output signal.

Mathematical formulae:

The linear convolution of two continuous time signals x(t) and h(t) is defined by

For discrete time signals x(n) and h(n), is defined by

Where x(n) is the input signal and h(n) is the impulse response of the system.

51
Source code:
#include<stdio.h>
int x[15],y[15],h[15];
void main()
{
int i,j,m,n;
printf("Enter the values for m= \n");
scanf("%d",&m);
printf("Enter value of n= \n");
scanf("%d",&n);
printf("Enter values of input x[m]\n");
for(i=0;i<m;i++)
{
scanf("%d",&x[i]);
}
printf("Enter values for h[n]\n");
for(i=0;i<n;i++)
{
scanf("%d",&h[i]);
}
for(i=0;i<m+n-1;i++)
{
y[i]=0;
for(j=0;j<=i;j++)
{
y[i]=y[i]+(x[j]*h[i-j]);
}
}
for(i=0;i<m+n-1;i++)
printf("output is y[%d]=%d\n",i,y[i]);
}

52
OBSERVATIONS FROM CONSOLE:
Enter the values for m= 4
Enter the values for n= 4
Enter values of input x[m]
1234
Enter values of input h[n]
5678
Output is
Y[0]=5
Y[1]=16
Y[2]=34
Y[3]=60
Y[4]=61
Y[5]=52
Y[6]=32

53
Graph:

54
Result:
Convolution of two finite sequences was demonstrated using CCS v4.0 IDE and
the results were verified with theoretical calculations.

55
DATE: EXPERIMENT No.:

VERIFICATION OF CIRCULAR CONVOLUTION


Aim:- To develop source code for Circular Convolution and verify using
CCS v4.0 on OMAPL138 Experimenter Kit.
Tools required:
1. PC loaded with Code Composer Studio v4.0 software
2. OMAPL138 Experimenter Kit ( configured as TMS320C674X)
Theory:
Circular convolution is another way of finding the convolution sum of two input
signals. It resembles the linear convolution, except that the sample values of one
of the input signals is folded and right shifted before the convolution sum is
found. Also note that circular convolution could also be found by taking the DFT
of the two input signals and finding the product of the two frequency domain
signals. The Inverse DFT of the product would give the output of the signal in the
time domain which is the circular convolution output. The two input signals could
have been of varying sample lengths. But we take the DFT of higher point, which
ever signals levels to. For example, If one of the signal is of length 256 and the
other spans 51 samples, then we could only take 256 point DFT. So the output of
IDFT would be containing 256 samples instead of 306 samples, which follows
N1+N2 1 where N1 & N2 are the lengths 256 and 51 respectively of the two
inputs. Thus the output which should have been 306 samples long is fitted into
256 samples. The256 points end up being a distorted version of the correct signal.
This process is called circular convolution.
Source code:
#include<stdio.h>
int m,n,x[30],h[30],y[30],i,j,k,x2[30],a[30];
void main()
{
printf(" enter the length of the first sequence\n");
scanf("%d",&m);
printf(" enter the length of the second sequence\n");
scanf("%d",&n);
printf(" enter the first sequence\n");
56
for(i=0;i<m;i++)
scanf("%d",&x[i]);
printf(" enter the second sequence\n");
for(j=0;j<n;j++)
scanf("%d",&h[j]);
if((m-n)!=0)
{
if(m>n)
{
for(i=n;i<m;i++)
h[i]=0;
n=m;
}
for(i=m;i<n;i++)
x[i]=0;
m=n;
}
y[0]=0;
a[0]=h[0];
for(j=1;j<n;j++)
a[j]=h[n-j];
for(i=0;i<n;i++)
y[0]+=x[i]*a[i];
for(k=1;k<n;k++)
{
y[k]=0;
for(j=1;j<n;j++)
x2[j]=a[j-1];
x2[0]=a[n-1];

57
for(i=0;i<n;i++)
{
a[i]=x2[i];
y[k]+=x[i]*x2[i];
}
}
printf(" Convolved output is\n");
for(i=0;i<n;i++)
printf("%d \t",y[i]);
}

OBSERVATIONS FROM CONSOLE:


enter the length of the first sequence
4
enter the length of the second sequence
4
enter the first sequence
1654
enter the second sequence
2 -1 3 4
Convolved output is
37 43 23 25

58
Graph:

59
Result:
Convolution of two periodic sequences were demonstrated using CCS v4.0 IDE
and the results were verified with theoretical calculations.

60
DATE: EXPERIMENT No.:

VERIFICATION OF DISCRETE FOURIER TRANSFORM and


INVERSE DISCRETE FOURIER TRANSFORM
Aim:- To develop source code for N-Point Discrete Fourier Transform &
Inverse Discrete Fourier Transform and verify using CCS v4.0 IDE on
OMAPL138 Experimenter Kit.
Tools required:
1. PC loaded with Code Composer Studio v4.0 software
2. OMAPL138 Experimenter Kit ( configured as TMS320C674X)
Theory:
In mathematics, the discrete Fourier transform (DFT) converts a finite sequence
of equally-spaced samples of a function into a same-length sequence of equally-
spaced samples of the discrete-time Fourier transform (DTFT), which is a
complex-valued function of frequency. The interval at which the DTFT is
sampled is the reciprocal of the duration of the input sequence. An inverse DFT
is a Fourier series, using the DTFT samples as coefficients of complex sinusoids
at the corresponding DTFT frequencies. It has the same sample-values as the
original input sequence. The DFT is therefore said to be a frequency domain
representation of the original input sequence. If the original sequence spans all
the non-zero values of a function, its DTFT is continuous (and periodic), and
the DFT provides discrete samples of one cycle. If the original sequence is one
cycle of a periodic function, the DFT provides all the non-zero values of one
DTFT cycle. The DFT is the most important discrete transform, used to perform
Fourier analysis in many practical applications. In digital signal processing, the
function is any quantity or signal that varies over time, such as the pressure of a
sound wave, a radio signal, or daily temperature readings, sampled over a finite
time interval (often defined by a window function). In image processing, the
samples can be the values of pixels along a row or column of a raster image.
The DFT is also used to efficiently solve partial differential equations, and to
perform other operations such as convolutions or multiplying large integers.

Source code:
#include<stdio.h>

61
#include<math.h>
#define pi 3.14
main()
{
int n,k,N;
float x[100],xreal[100],ximg[100],X[100];
printf("Enter length of sequnece:");
scanf("%d",&N);
printf("\nEnter the sequence\n");
for(n=0;n<N;n++)
{
scanf("%f",&x[n]);
}
for(k=0;k<N;k++)
{
xreal[k]=ximg[k]=0.0;
for(n=0;n<N;n++)
{
xreal[k]=xreal[k]+x[n]*cos((2*pi*k*n)/N);
ximg[k]=ximg[k]+x[n]*sin((2*pi*k*n)/N);
}
ximg[k]=ximg[k]*(-1.0);
}
printf("\n%d-Point DFT of given seq. is\n",N);
printf("\nReal x[k]\tImaginary x[k]");
for(k=0;k<N;k++)
{
printf("\nX[%d]=%f\t+i%f",k,xreal[k],ximg[k]);
}

62
for(n=0;n<N;n++)
{
x[n]=0;
for(k=0;k<N;k++)
{
x[n]=x[n]+xreal[k]*cos((2*pi*k*n)/N)-
ximg[k]*sin((2*pi*k*n)/N);
}
x[n]=x[n]/N;
}
printf("\nThe %d-point IDFT is :",N);
for(n=0;n<N;n++)
{
printf("\nx[%d]=%f",n,x[n]);
}
}
OBSERVATIONS FROM CONSOLE:
Enter length of sequnece:4
Enter the sequence
4 3 2 1
4-Point DFT of given seq. is
Real x[k] Imaginary x[k]
X[0]=10.000000 +i-0.000000
X[1]=2.000003 +i-2.003187
X[2]=2.000005 +i-0.003185
X[3]=2.000023 +i1.990461
The 4-point IDFT is :
x[0]=4.000008
x[1]=2.997615

63
x[2]=1.998416
x[3]=1.003999

Result:
N-Point DFT and IDFT of a finite sequences were demonstrated using CCS
v4.0 IDE and the results were verified with theoretical calculations.

64
DATE: EXPERIMENT No.:

VERIFICATION OF FAST FOURIER TRANSFORM


ALGORITHM
Aim:- To develop source code for N-Point Fast Fourier Transform and verify
using CCS v4.0 IDE on OMAPL138 Experimenter Kit.
Tools required:
1. PC loaded with Code Composer Studio v4.0 software
2. OMAPL138 Experimenter Kit ( configured as TMS320C674X)
Theory:
An FFT computes the DFT and produces exactly the same result as evaluating
the DFT definition directly; the most important difference is that an FFT is much
faster. (In the presence of round-off error, many FFT algorithms are also much
more accurate than evaluating the DFT definition directly, as discussed below.)
Let x0, ...., xN1 be complex numbers. Evaluating this definition directly requires
O(N2) operations: there are N outputs Xk, and each output requires a sum of N
terms. An FFT is any method to compute the same results in O(N log N)
operations. All known FFT algorithms require (N log N) operations, although
there is no known proof that a lower complexity score is impossible. To illustrate
the savings of an FFT, consider the count of complex multiplications and
additions. Evaluating the DFT's sums directly involves N2 complex
multiplications and N(N1) complex additions, of which O(N) operations can be
saved by eliminating trivial operations such as multiplications by 1. The radix-2
CooleyTukey algorithm, for N a power of 2, can compute the same result with
only (N/2)log2(N) complex multiplications (again, ignoring simplifications of
multiplications by 1 and similar) and N log2(N) complex additions. In practice,
actual performance on modern computers is usually dominated by factors other
than the speed of arithmetic operations and the analysis is a complicated subject,
but the overall improvement from O(N2) to O(N log N) remains.

Source code:
#include<stdio.h>
#include<math.h>
int i,j,k,n,m,n1,n2;

65
double x[20],y[20],a,s,e,c,t1,t2;
float q[20]={0,0},p[20]={0,0};
void main()
{
n=8;
m=3;
printf("enter the real values\n");
for(i=0;i<n;i++)
scanf("%f",&x[i]);
printf("enter the imaginary values\n");
for(i=0;i<n;i++)
scanf("%f",&y[i]);
j=0;
n2=n/2;
for(i=1;i<n-1;i++)
{
n1=n2;
while(j>=n1)
{
j=j-n1;
n1=n1/2;
}
j=j+n1;
if (i<j)
{
t1=x[i];

66
x[i]=x[j];
x[i]=t1;
t1=y[i];
y[i]=y[j];
y[j]=t1;
}
}
n1=0;
n2=1;
for(i=0;j<n1;i++)
{
n1=n2;
n2=n2+n2;
e=-6.28316/n2;
a=0;
for(j=0;j<n1;j++)
{
c=cos(a);
s=sin(a);
a=a+e;
for(k=j;k<n;k)
{
t1=c*x[k+n1]-s*y[k+n1];
t2=s*x[k+n1]+c*y[k+n1];
x[k+n1]=x[k]-t1;
y[k+n1]=y[k]-t2;

67
x[k]=x[k]+t1;
y[k]=y[k]+t2;
}
}
}
for(i=0;i<n;i++)
{
printf("\n fft sequence is %f+j%f",x[i],y[i]);
p[i]=sqrt(x[i]*x[i]+y[i]*y[i]);
printf("\n magnitude is %f \n ",p[i]);
q[i]=atan(y[i]/x[i]);
printf("\n phase is %f \n ",q[i]);
}
}

68
RESULT:
N-Point FFT of a finite sequence was demonstrated using CCS v4.0 IDE and
the results were verified with theoretical calculations.

69
70

You might also like