Vous êtes sur la page 1sur 91

EXPERIMENT NO: 1

Generation Of Signals DATE:

AIM:
I. To generate the following signals a) Unit Impulse signal b) Unit Step Signal c)
Ramp signal d) Exponential signal e) Sinusoidal signal f) Cosine signal g) Square signal
h) Triangular signal.
II. To generate the following probability distribution functions a) Uniform
distribution b) Normal distribution c) Rayleigh distribution d) Random distribution

THEORY:

1. Real Exponential

x ( t )= A e at , a R

2. Unit step function

u ( t ) =1,t >0
0, t<0
undefined at t=0

3. Dirac Delta function

( t )= , t=0
0, t 0

( t ) dt=1

4. Unit Ramp Function

r ( t ) =t , t> 0

0, t<0

1
PROGRAM:

% Generate unit impulse signal


x=[-2:1:2]
y=[zeros(1,2) ones(1,1) zeros(1,2)]
subplot(4,2,1)
stem(x,y)
xlabel('time')
ylabel('amplitude')
title('unit impulse')

% Generate unit step signal


x=[1:1:10]
y=ones(1,10)
subplot(4,2,2)
stem(x,y)
xlabel('time')
ylabel('amplitude')
title('unit step signal')

% Generate ramp signal


n=input('Enter the value of n')
t=[0:n]
subplot(4,2,3)
stem(t,t)
xlabel('time')
ylabel('amplitude')
title('ramp signal')

% Generate exponential signal


x=[0:1:5]
y=exp(x)

2
subplot(4,2,4)
stem(x,y)
xlabel('time')
ylabel('amplitude')
title('exponential signal')
% Generate sinusoidal signal
x=[-pi:0.01:pi]
y=sin(x)
subplot(4,2,5)
plot(x,y)
xlabel('time')
ylabel('amplitude')
title('sinusoidal signal')

% Generate cosine signal


x=[-pi:0.01:2*pi]
y=cos(x)
subplot(4,2,6)
plot(x,y)
xlabel('time')
ylabel('amplitude')
title('cosine signal')

% Generate square signal


t=[0:1:5]
x=square(t)
subplot(4,2,7)
stem(t,x)
xlabel('time')
ylabel('amplitude')
title('square signal')

3
% Generate triangular signal
n1= input('Enter the value of n1')
s=[-(n+2):(n+2)]
z=1-(abs(s)/(n+2))
subplot(4,2,8)
stem(s,z)
xlabel('time')
ylabel('amplitude')
title('triangular signal')

% uniform distriburion
pdfuniform=rand(1,10000)
figure(2)
subplot(2,2,1)
hist(pdfuniform)
title('uniform disrtibution,histogram')

% Nornal distribution function


pdfNormal=rand(1,10000)
figure(2)
subplot(2,2,2)
hist(pdfNormal)
title('Normal disrtibution,histogram')

% rayleigh distribution function


x=0:0.1:3
p=raylpdf(x,1)
figure(2)
subplot(2,2,3)
plot(x,p,'r')

4
title('Rayleigh distribution')

% Random distriburion
b= input('Enter the value of b=')
a= input('Enter the value of a=')
r = a + (b-a).*rand(100,1);
figure(2)
subplot(2,2,4)
plot(r,'g')
title('random distribution')

RESULT: Generated and plotted the basic signals and the probability density functions.

5
EXPERIMENT NO: 2

DATE:
LINEAR CONVOLUTION

AIM: To generate linear convolution of two sequences using inbuilt function and without
using inbuilt function in Matlab

THEORY:
Convolution is an integral concatenation of two signals. It has many applications in
numerous area of signal processing.The most popular application is the determination of
the output signal of a linear time-invariant system by convolving the input signal with the
impulse response of the system.
Linear Convolution
The linear convolution of two continuous time signals x(n) & h(n) is defined by

Graphical Interpretation:
Reflection of h(k) resulting in h(-k)
Shifting of h(-k) resulting in h(n-k)
Element wise multiplication of the sequences x(k) and h(n-k)
Summation of the product sequence x(k)h(n-k) resulting in the convolution value
for y(n)

PROGRAM:

% using inbuilt function


x=input('Enter the first sequence=')
y=input('Enter the second sequence=')
p=length(x)
q=length(y)

6
h=conv(x,y)
subplot(3,1,1)
stem(x,'r')
title('first sequence')
subplot(3,1,2)
stem(y,'g')
title('second sequence')
subplot(3,1,3)
stem(h,'m')
title('convolved sequence')

% Without using inbuilt function


x=input('Enter the first sequence=')
y=input('Enter the second sequence=')
p=length(x)
q=length(y)
subplot(3,1,1)
stem(x)
title('first sequence')
ylabel('x(n)')
xlabel('n')
subplot(3,1,2)
stem(y)
title('second sequence')
ylabel('y(n)')
xlabel('n')
N=p+q-1
x=[x zeros(1,N-p)]
y=[y zeros(1,N-q)]
h=zeros(1,N)
for i=1:N
h(i)=0
for j=1:i
h(i)=h(i)+[x(j)*y(i-j+1)]
subplot(3,1,3)
stem(h)
title('Convolved sequence')
ylabel('h(n)')

7
xlabel('N')
end
end

RESULT: Linear convolution using inbuilt and without using inbuilt function were
EXPERIMENT NO: 3
implemented.
DATE:
CIRCULAR CONVOLUTION

AIM: To generate circular convolution of two sequences using inbuilt function and
without using inbuilt function in Matlab

THEORY:
Convolution is an integral concatenation of two signals. It has many applications in
numerous area of signal processing. The most popular application is the determination of
the output signal of a linear time-invariant system by convolving the input signal with the
impulse response of the system.
Circular convolution of two finite duration sequences of same length N is given by

Circular convolution differs from linear convolution in two respects:


Length of both sequences must be same and result is also of size N
Operations of folding and shifting are performed in circular fashion than linear.
If the two sequences are of length N1,N2 respectively, then size of circular
convolution would be N=max(N1,N2) with the sequence of lesser length padded with
zeros.

PROGRAM:
% Using inbuilt function
x=input('Enter the first sequence=')
y=input('Enter the second sequence=')
p=length(x)
q=length(y)
n=max(p,q)

8
h=cconv(x,y,n)
figure(1)
subplot(3,1,1)
stem(x,'r')
title('first sequence')
figure(1)
subplot(3,1,2)
stem(y,'g')
title('second sequence')
figure(1)
subplot(3,1,3)
stem(h,'m')
title('convolved sequence')

% Without Using inbuilt function


x=input('enter the first sequence=')
figure(2)
subplot(3,1,1)
stem(x)
title('First Sequence')
ylabel('x(n)')
xlabel('n')
h=input('enter the second sequence=')
figure(2)
subplot(3,1,2)
stem(h)
title('Second Sequence')
ylabel('h(n)')
xlabel('n')
N1=length(x)
N2=length(h)
N= max(N1,N2)
x=[x zeros(1,N-N1)]
h=[h zeros(1,N-N2)]
for n=0:N-1
y(n+1)=0

9
for i=0:N-1
j=mod(n-i,N)
y(n+1)=y(n+1) + x(i+1)*h(j+1)
end
end
disp(y)
figure(2)
subplot(3,1,3)
stem(y)
title('Output Sequence')
ylabel('y(n)')
xlabel('N')

RESULT: Circular convolution of two sequences were executed in Matlab with and
without using inbuilt function.

10
EXPERIMENT NO: 4

DATE:

LINEAR CONVOLUTION USING CIRCULAR CONVOLUTION

AIM: To generate circular convolution of two sequences using inbuilt function and
without using inbuilt function in Matlab

THEORY:
Convolution is an integral concatenation of two signals. It has many applications in
numerous area of signal processing. The most popular application is the determination of
the output signal of a linear time-invariant system by convolving the input signal with the
impulse response of the system.
To compute linear convolution of two sequences x(n) and h(n) of lengths N1,N2
respectively the following procedure is used.
Increase the length of x(n) and h(n) to (N1+N2-1) by padding (N2-1) zeros to x(n)
and (N1-1) zeros to h(n)
Find (N1+N2-1) point circular convolution of padded sequences which is
identical to linear convolution of x(n) & h(n).

PROGRAM:
x=input('Enter the first sequence')
h=input('Enter the second sequence')
N=length(x)+length(h)-1
if size(x,2)>1
x=x'
end
if size(h,2)>1
h=h'
end

11
if N>length(x)
x=[x;zeros(N-length(x),1)]
end
if N>length(h)
h=[h;zeros(N-length(h),1)]
end

y=x*h'
y1=fliplr(y)
disp('output sequence')
c=zeros(1,N)
c(N)=sum(diag(y1,0))
for x1=1:N
c(x1)=sum(diag(y1,N-x1))+sum(diag(y1,-x1))
disp(c(x1))
end
subplot(3,1,1)
stem(x)
title('first sequence')
ylabel('X[n]')
xlabel('n')
subplot(3,1,2)
stem(h)
title('second sequence')
ylabel('h[n]')
xlabel('n')
n=0:1:N-1
subplot(3,1,3)
stem(n,c)
title('convolved sequence')
ylabel('c[x]')
xlabel('n')

RESULT: Linear convolution using circular convolution was implemented in Matlab.

12
EXPERIMENT NO: 5

DATE:

DISCRETE FOURIER TRANSFORM

AIM: To generate DFT of a given sequence using inbuilt function and without using
inbuilt function in Matlab.

THEORY:
The spectrum of an aperiodic discrete time signal is continuous and periodic with
period 2, which can be computed using Discrete Time Fourier Transform. The frequency
analysis of Discrete time signals are usually performed on a DSP processor which can be
either a general purpose computer or specially designed digital hardware. Since DTFT is
continuous, it is not a convenient frequency domain representation for processing by a
DSP processor. Therefore the DFT is sampled at N discrete frequencies say

w=2k /N , where k =0, 1, 2N-1. DFT of x (n) is the fundamental period of

the DTFS of its periodic extension. The N point DFT of an N-point sequence is given by
N1
X ( K )= x (n) e
jk 2 n / N
k =0 ,1 , 2 , . N 1
n=0

PROGRAM:
% Using inbuilt function
clc;
clear all;
close all;
x=input('ENTER THE INPUT SEQUENCE');
N=input ('ENTER THE LENGTH OF DFT');
n=length(x);

13
X=fft(x,N);
t=[0:1:n-1]
figure(1)
subplot(221);
stem(t,x);
xlabel('TIME');
ylabel('AMPLITUDE');
title('ORIGINAL INPUT SEQUENCE');
K=[0:1:N-1]
figure(1)
subplot(222);
stem(K,X);
xlabel('FREQUENCY');
ylabel('AMPLITUDE');
title('DFT RESPONSE');
figure(1)
subplot(223);
stem(K,abs(X));
xlabel('FREQUENCY');
ylabel('MAGNITUDE');
title('MAGNITUDE RESPONSE');
figure(1)
subplot(224);
stem(K,angle(X));
xlabel('FREQUENCY');
ylabel('PHASE');
title('PHASE RESPONSE');

%Without using inbuilt function


x=input('ENTER THE INPUT SEQUENCE');
N=input ('ENTER THE LENGTH OF DFT');
for k=1:N
y(k)=0
for i=1:N
y(k)=y(k)+x(i)*exp(-j*2*pi*(k-1)*(i-1)/N)
end
end
k=[0:1:N-1]

14
mag=abs(y)
ang=angle(y)
subplot(221);
stem(k,x);
xlabel('TIME');
ylabel('AMPLITUDE');
title('ORIGINAL INPUT SEQUENCE');
figure(2)
subplot(222);
stem(k,y);
xlabel('FREQUENCY');
ylabel('AMPLITUDE');
title('DFT RESPONSE');
figure(2)
subplot(223);
stem(k,mag);
xlabel('FREQUENCY');
ylabel('MAGNITUDE');
title('MAGNITUDE RESPONSE');
figure(2)
subplot(224);
stem(k,ang);
xlabel('FREQUENCY');
ylabel('PHASE');
title('PHASE RESPONSE');

%DFT unfolding spectrum


%Plot of rec signal
N=input('Enter the length of the sequence')
m=floor(N/8)
rect=[ones(1,m) zeros(1,N-m)]
%subplot(1,2,1)
stem(rect)
figure
%find DFT and plot its mag ,phase
w=exp(-j*2*pi/N)
n=[0:1:(N-1)]
k=[0:1:(N-1)]

15
nk=n'*k
W=w.^nk
X=rect*W
figure(3)
subplot(2,2,1)
stem(k,abs(X))
title('Magnitude plot')
xlabel('Discrete Frequency')
ylabel('Amplitude')
figure(3)
subplot(2,2,2)
stem(k,angle(X))
title('Phase plot')
xlabel('Discrete Frequency')
ylabel('Phase Angle')
% unfolding spectrum
y=X(floor(N/2)+1:N)
Y=[y X(1:floor(N/2))]
figure(3)
subplot(2,2,3)
stem(k,abs(Y))
title('Magnitude plot of unfolded spectrum')
xlabel('Discrete Frequency')
ylabel('Amplitude')
figure(3)
subplot(2,2,4)
stem(k,angle(Y))
title('Phase plot of unfolded spectrum')
xlabel('Discrete Frequency')
ylabel('Phase Angle')

RESULT: DFT implementation of the sequence was carried using inbuilt function and
without using inbuilt function in Matlab and also unfolding of the spectrum was
implemented.

16
EXPERIMENT NO: 6

DATE:

INVERSE DISCRETE FOURIER TRANSFORM

AIM: To generate IDFT of a given sequence using inbuilt function and without using
inbuilt function in Matlab.

THEORY:
The spectrum of an aperiodic discrete time signal is continuous and periodic with
period 2,which can be computed using Discrete Time Fourier Transform.The frequency
analysis of Discrete time signals are usually performed on a DSP processor which can be
either a general purpose computer or specially designed digital hardware.Since DTFT is
continuous ,it is not a convenient frequency domain representation for processing by a
DSP processor.Therefore the DFT is sampled at N discrete frequencies say w= 2*
*k/N,where k=0,1,2N-1.
The N point IDFT of the N point sequence is given by

PROGRAM:
% using inbuilt function
clc;
clear all;
close all;
x=input('ENTER THE INPUT SEQUENCE');
N=input ('ENTER THE LENGTH OF DFT');
n=length(x);

17
X=ifft(x,N);
t=[0:1:n-1]
figure(1)
subplot(221);
stem(t,x);
xlabel('TIME');
ylabel('AMPLITUDE');
title('ORIGINAL INPUT SEQUENCE');
K=[0:1:N-1]
figure(1)
subplot(222);
stem(K,X);
xlabel('FREQUENCY');
ylabel('AMPLITUDE');
title('IDFT RESPONSE');
figure(1)
subplot(223);
stem(K,abs(X));
xlabel('FREQUENCY');
ylabel('MAGNITUDE');
title('MAGNITUDE RESPONSE');
figure(1)
subplot(224);
stem(K,angle(X));
xlabel('FREQUENCY');
ylabel('PHASE');
title('PHASE RESPONSE');

% Without using inbuilt function

x=input('ENTER THE INPUT SEQUENCE');


N=input ('ENTER THE LENGTH OF DFT');
for k=1:N
y(k)=0
for i=1:N
y(k)=y(k)+[x(i)*exp(j*2*pi*(k-1)*(i-1)/N)/N]

18
end
end
k=[0:1:N-1]
mag=abs(y)
ang=angle(y)
figure(2)
subplot(221);
stem(k,x);
xlabel('TIME');
ylabel('AMPLITUDE');
title('ORIGINAL INPUT SEQUENCE');
figure(2)
subplot(222);
stem(k,y);
xlabel('FREQUENCY');
ylabel('AMPLITUDE');
title('DFT RESPONSE');
figure(2)
subplot(223);
stem(k,mag);
xlabel('FREQUENCY');
ylabel('MAGNITUDE');
title('MAGNITUDE RESPONSE');
figure(2)
subplot(224);
stem(k,ang);
xlabel('FREQUENCY');
ylabel('PHASE');
title('PHASE RESPONSE');

RESULT: IDFT implementation of the sequence was carried out using inbuilt function
and without using inbuilt function in Matlab.

19
EXPERIMENT NO: 7

DATE:
LINEAR CONVOLUTION USING DFT

AIM: To implement linear convolution using DFT.

THEORY:

Let x (n) be of length N, h( n) of length M.Let y (n) be the linear convolution

of x (n ) and h( n) . Append M 1 zeros to x (n) and N1 zeros to

h( n) to make their lengths equal. Now Y ( k )= X ( k ) H (k ) , where Y ( k ) , H (k ) ,

and H (k ) are the DFTs of y ( n ) , x (n) and h(n) respectively.

PROGRAM:

%Linear Convolution using DFT


x1=input('Enter the first sequence')
x2=input('Enter the second sequence')
N1=length(x1)
N2=length(x2)
N=N1+N2-1
X1=fft(x1,N)
X2=fft(x2,N)
Y=X1.*X2
y=ifft(Y,N)
stem(y);
xlabel('Amplitude')
ylabel('Time index')

20
RESULT: The Program is executed and plotted the output of linear convolution using
DFT.

EXPERIMENT NO: 9

DATE:
IIR BUTTERWORTH FILTERS

AIM: To write Matlab Program for implementing following Butterworth filters and plot
their magnitude and phase response.
i)Butterworth Low pass filter ii) Butterworth High pass filter
iii)Butterworth Bandpass filter iv) Butterworth Bandstop filter

THEORY:
IIR filters have infinite duration impulse response.Hence they are analogous to
analog filters which generally have long impulse response.The basic technique of IIR
filter design involves transforming analog filters into digitial filters using complex
mappings.The butterworth filter is characterized by the property that its magnitude
response is flat in both passband and stopband. The magnitude squared response of an
Nth order low pass filter is given by
2 1
Ha ( j) =
2N
1+
c

Where N is the order of the filter and c is the cut-off frequency in rad/sec.

PROGRAM:
% Butterworth Low Pass Filter
clc
close all

21
clear all
wp=input('Enter the passband frequency=')
ws=input('Enter the stopband frequency=')
rp=input('Enter the passband ripple=')
rs=input('Enter the stopband ripple=')
fs=input('Enter the sampling frequency=')
w1=2*wp/fs
w2=2*ws/fs
[N,wn]= buttord(w1,w2,rp,rs)
[b,a]=butter(N,wn)
w=0:0.01:pi
[h,omega]=freqz(b,a,w)
gain= 20*log10(abs(h))
subplot(2,1,1)
plot(omega/pi,gain)
grid
xlabel('\omega/pi,gain')
ylabel('Gain in dB')
title('IIR Butterworth LPF:Gain')
an=angle(h)
subplot(2,1,2)
plot(omega/pi,an)
grid
xlabel('\omega/pi,gain')
ylabel('Phase in radians')
title('IIR Butterworth LPF:Phase')
disp('Order of the filter is:');N

% Butterworth High Pass Filter


clc
close all
clear all
wp=input('Enter the passband frequency=')
ws=input('Enter the stopband frequency=')
rp=input('Enter the passband ripple=')
rs=input('Enter the stopband ripple=')
fs=input('Enter the sampling frequency=')
w1=2*wp/fs

22
w2=2*ws/fs
[N,wn]= buttord(w1,w2,rp,rs)
[b,a]=butter(N,wn,'high')
w=0:0.01:pi
[h,omega]=freqz(b,a,w)
gain= 20*log10(abs(h))
subplot(2,1,1)
plot(omega/pi,gain)
grid
xlabel('\omega/pi,gain')
ylabel('Gain in dB')
title('IIR Butterworth HPF:Gain')
an=angle(h)
subplot(2,1,2)
plot(omega/pi,an)
grid
xlabel('\omega/pi,gain')
ylabel('Phase in radians')
title('IIR Butterworth HPF:Phase')
disp('Order of the filter is:');N

% Butterworth Band Pass Filter


clc
close all
clear all
wp=input('Enter the passband frequency=')
ws=input('Enter the stopband frequency=')
rp=input('Enter the passband ripple=')
rs=input('Enter the stopband ripple=')
fs=input('Enter the sampling frequency=')
w1=2*wp/fs
w2=2*ws/fs
[N,wn]= buttord(w1,w2,rp,rs)
[b,a]=butter(N,wn)
w=0:0.01:pi
[h,omega]=freqz(b,a,w)
gain= 20*log10(abs(h))
subplot(2,1,1)

23
plot(omega/pi,gain)
grid
xlabel('\omega/pi,gain')
ylabel('Gain in dB')
title('IIR Butterworth BPF:Gain')
an=angle(h)
subplot(2,1,2)
plot(omega/pi,an)
grid
xlabel('\omega/pi,gain')
ylabel('Phase in radians')
title('IIR Butterworth BPF:Phase')
disp('Order of the filter is:');N

% Butterworth Band Stop Filter


clc
close all
clear all
wp=input('Enter the passband frequency=')
ws=input('Enter the stopband frequency=')
rp=input('Enter the passband ripple=')
rs=input('Enter the stopband ripple=')
fs=input('Enter the sampling frequency=')
w1=2*wp/fs
w2=2*ws/fs
[N,wn]= buttord(w1,w2,rp,rs)
[b,a]=butter(N,wn,'stop')
w=0:0.01:pi
[h,omega]=freqz(b,a,w)
gain= 20*log10(abs(h))
subplot(2,1,1)
plot(omega/pi,gain)
grid
xlabel('\omega/pi,gain')
ylabel('Gain in dB')
title('IIR Butterworth BSF:Gain')
an=angle(h)
subplot(2,1,2)

24
plot(omega/pi,an)
grid
xlabel('\omega/pi,gain')
ylabel('Phase in radians')
title('IIR Butterworth BSF:Phase')
disp('Order of the filter is:');N

RESULT: Executed the Low pass, High pass, Band pass, Band reject Butterworth filters
and plotted their magnitude and phase response. EXPERIMENT NO:
10

IIR CHEBYSHEV FILTERS


AIM: To write Matlab Program for implementing following chebyshev filters and plot
their magnitude and phase response.
i) Chebyshev Low pass filter ii) Chebyshev High pass filter
iii) Chebyshev Bandpass filter iv) Chebyshev Bandstop filter

THEORY:
IIR filters have infinite duration impulse response. Hence they are analogous to
analog filters which generally have long impulse response. The basic technique of IIR
filter design involves transforming analog filters into digital filters using complex
mappings. The Butterworth filter is characterized by the property that its magnitude
response is flat in both pass band and stop band. There are two types of chebyshev filters.
The chebyshev I filters have equiripple response in the passband,while the chebyshev
II filters have equiripple response in the stopband.The magnitude squared response of
Chebyshev-I filter is given by
2 1
Ha ( j) =
2 2
1+ T (N )
c

Where N is the order of the filter, is the passband ripple factor, which is

related to Rp and TN(x) is the Nth order chebyshev polynomial given by

TN(x) =cos(N cos-1 (x) ) 0 x 1

25
Cosh (cos-1 (x) ) 1 x

PROGRAM:
%Chebyshev Type I L.P.F filter
clc
close all
clear all
wp=input('Enter the passband frequency=')
ws=input('Enter the stopband frequency=')
rp=input('Enter the passband ripple=')
rs=input('Enter the stopband ripple=')
fs=input('Enter the sampling frequency=')
w1=2*wp/fs
w2=2*ws/fs
[N,wn]= cheb1ord(w1,w2,rp,rs)
[b,a]=cheby1(N,rp,wn)
w=0:0.01:pi
[h,omega]=freqz(b,a,w)
gain= 20*log10(abs(h))
subplot(2,1,1)
plot(omega/pi,gain)
grid
xlabel('\omega/pi,gain')
ylabel('Gain in dB')
title('IIR Chebyshev-I LPF:Gain')
an=angle(h)
subplot(2,1,2)
plot(omega/pi,an)
grid
xlabel('\omega/pi,gain')
ylabel('Phase in radian')
title('IIR Chebyshev-I LPF:Phase')
disp('Order of the filter is:');N

% Chebyshev Type II low pass filter


clc

26
close all
clear all
wp=input('Enter the passband frequency=')
ws=input('Enter the stopband frequency=')
rp=input('Enter the passband ripple=')
rs=input('Enter the stopband ripple=')
fs=input('Enter the sampling frequency=')
w1=2*wp/fs
w2=2*ws/fs
[N,wn]= cheb2ord(w1,w2,rp,rs)
[b,a]=cheby2(N,rp,wn)
w=0:0.01:pi
[h,omega]=freqz(b,a,w)
gain= 20*log10(abs(h))
subplot(2,1,1)
plot(omega/pi,gain)
grid
xlabel('\omega/pi,gain')
ylabel('Gain in dB')
title('IIR Chebyshev-I LPF:Gain')
an=angle(h)
subplot(2,1,2)
plot(omega/pi,an)
grid
xlabel('\omega/pi,gain')
ylabel('Phase in radian')
title('IIR Chebyshev-I LPF:Phase')
disp('Order of the filter is:');N

% Chebyshev Type I High pass filter


clc
close all
clear all
wp=input('Enter the passband frequency=')
ws=input('Enter the stopband frequency=')
rp=input('Enter the passband ripple=')
rs=input('Enter the stopband ripple=')

27
fs=input('Enter the sampling frequency=')
w1=2*wp/fs
w2=2*ws/fs
[N,wn]= cheb1ord(w1,w2,rp,rs)
[b,a]=cheby1(N,rp,wn,'high')
w=0:0.01:pi
[h,omega]=freqz(b,a,w)
gain= 20*log10(abs(h))
subplot(2,1,1)
plot(omega/pi,gain)
grid
xlabel('\omega/pi,gain')
ylabel('Gain in dB')
title('IIR Chebyshev-I HPF:Gain')
an=angle(h)
subplot(2,1,2)
plot(omega/pi,an)
grid
xlabel('\omega/pi,gain')
ylabel('Phase in radian')
title('IIR Chebyshev-I HPF:Phase')
disp('Order of the filter is:');N

% Chebyshev Type II High pass filter


clc
close all
clear all
wp=input('Enter the passband frequency=')
ws=input('Enter the stopband frequency=')
rp=input('Enter the passband ripple=')
rs=input('Enter the stopband ripple=')
fs=input('Enter the sampling frequency=')
w1=2*wp/fs
w2=2*ws/fs
[N,wn]= cheb2ord(w1,w2,rp,rs)
[b,a]=cheby2(N,rp,wn,'high')
w=0:0.01:pi
[h,omega]=freqz(b,a,w)

28
gain= 20*log10(abs(h))
subplot(2,1,1)
plot(omega/pi,gain)
grid
xlabel('\omega/pi,gain')
ylabel('Gain in dB')
title('IIR Chebyshev-I HPF:Gain')
an=angle(h)
subplot(2,1,2)
plot(omega/pi,an)
grid
xlabel('\omega/pi,gain')
ylabel('Phase in radian')
title('IIR Chebyshev-I HPF:Phase')
disp('Order of the filter is:');N

% Chebyshev Type I Band pass filter


clc
close all
clear all
wp=input('Enter the passband frequency=')
ws=input('Enter the stopband frequency=')
rp=input('Enter the passband ripple=')
rs=input('Enter the stopband ripple=')
fs=input('Enter the sampling frequency=')
w1=2*wp/fs
w2=2*ws/fs
[N]= cheb1ord(w1,w2,rp,rs)
[wn]=[w1,w2]
[b,a]=cheby1(N,rp,wn)
w=0:0.01:pi
[h,omega]=freqz(b,a,w)
gain= 20*log10(abs(h))
subplot(2,1,1)
plot(omega/pi,gain)
grid
xlabel('\omega/pi,gain')
ylabel('Gain in dB')

29
title('IIR Chebyshev-I BPF:Gain')
an=angle(h)
subplot(2,1,2)
plot(omega/pi,an)
grid
xlabel('\omega/pi,gain')
ylabel('Phase in radian')
title('IIR Chebyshev-I BPF:Phase')
disp('Order of the filter is:');N

% Chebyshev Type II Band pass filter

clc
close all
clear all
wp=input('Enter the passband frequency=')
ws=input('Enter the stopband frequency=')
rp=input('Enter the passband ripple=')
rs=input('Enter the stopband ripple=')
fs=input('Enter the sampling frequency=')
w1=2*wp/fs
w2=2*ws/fs
[N]= cheb2ord(w1,w2,rp,rs)
[wn]=[w1,w2]
[b,a]=cheby2(N,rp,wn)
w=0:0.01:pi
[h,omega]=freqz(b,a,w)
gain= 20*log10(abs(h))
subplot(2,1,1)
plot(omega/pi,gain)
grid
xlabel('\omega/pi,gain')
ylabel('Gain in dB')
title('IIR Chebyshev-I BPF:Gain')
an=angle(h)
subplot(2,1,2)

30
plot(omega/pi,an)
grid
xlabel('\omega/pi,gain')
ylabel('Phase in radian')
title('IIR Chebyshev-I BPF:Phase')
disp('Order of the filter is:');N

% Chebyshev Type I Band Stop filter

clc
close all
clear all
wp=input('Enter the passband frequency=')
ws=input('Enter the stopband frequency=')
rp=input('Enter the passband ripple=')
rs=input('Enter the stopband ripple=')
fs=input('Enter the sampling frequency=')
w1=2*wp/fs
w2=2*ws/fs
[N]= cheb1ord(w1,w2,rp,rs)
[wn]=[w1,w2]
[b,a]=cheby1(N,rp,wn,'stop')
w=0:0.01:pi
[h,omega]=freqz(b,a,w)
gain= 20*log10(abs(h))
subplot(2,1,1)
plot(omega/pi,gain)
grid
xlabel('\omega/pi,gain')
ylabel('Gain in dB')
title('IIR Chebyshev-I BSF:Gain')
an=angle(h)

31
subplot(2,1,2)
plot(omega/pi,an)
grid
xlabel('\omega/pi,gain')
ylabel('Phase in radian')
title('IIR Chebyshev-I BSF:Phase')
disp('Order of the filter is:');N

% Chebyshev Type II Band Stop filter


clc
close all
clear all
wp=input('Enter the passband frequency=')
ws=input('Enter the stopband frequency=')
rp=input('Enter the passband ripple=')
rs=input('Enter the stopband ripple=')
fs=input('Enter the sampling frequency=')
w1=2*wp/fs
w2=2*ws/fs
[N]= cheb2ord(w1,w2,rp,rs)
[wn]=[w1,w2]
[b,a]=cheby2(N,rp,wn,'stop')
w=0:0.01:pi
[h,omega]=freqz(b,a,w)
gain= 20*log10(abs(h))
subplot(2,1,1)
plot(omega/pi,gain)
grid
xlabel('\omega/pi,gain')
ylabel('Gain in dB')
title('IIR Chebyshev-I BSF:Gain')
an=angle(h)
subplot(2,1,2)

32
plot(omega/pi,an)
grid
xlabel('\omega/pi,gain')
ylabel('Phase in radian')
title('IIR Chebyshev-I BSF:Phase')
disp('Order of the filter is:');N

RESULT: Executed the Low pass, High pass, Band pass, Band reject Chebyshev type I
and type II filters and plotted their magnitude and phase response.

EXPERIMENT NO:
12

FIR FILTER USING WINDOW METHOD

AIM: To implement FIR filter using window technique

THEORY: In digital signal processing there are mainly two types of systems. The
first type of system performs filtering in the time domain and is called digital filters. The
second type of system provides signal representation in frequency domain and is called
spectrum analyzers. The design of a digital filter is carried out in three steps.
Specifications
We need specifications for designing the filter. The specifications vary with
applications.

Approximations
Once the specifications are available, we make use of mathematical tools to come
up with a filter that approximates the given set of specifications.

Implementation
The previous step yields a filter response of the form h(n), H(Z) etc. We need to
implement this filter in hardware or through software.

33
A linear phase FIR filter is characterized by the impulse response,

Accordingly depending on whether N is odd or even we have four types of FIR filters.

The tranfer function a FIR causal filter is given by,

Where h(n) is the impulse response of the filter.


The main advantages of the FIR filter are:
_ FIR Filters are always stable
_ FIR filters with linear phase can be designed
_ It can be realized both in recursive and non recursive realizations
_ Excellent design methods are readily available for FIR filters
The major disadvantages of FIR filters are:
_ Implementation of narrow transition band FIR filters are very costly

34
_ Memory requirement and execution time are very high

Design methods for FIR filters are based on the direct approximation of the required
digital specification such as magnitude and phase response.
It is found that the impulse response of ideal filters is non causal, doubly infinite in length
and not absolutely summable. Since impulse response begins at -, no finite delay can
make the impulse response causal. So ideal filters are not realizable in real and non- real
time.
One way of possibly making the impulse response causal is to truncate the ideal impulse
response at n= - (N-1)/2 & n= (N-1)/2 , and resulting truncated impulse response is
delayed by (N-1)/2 , to obtain a causal impulse response. This can be achieved by
multiplying the impulse response by a window function. The truncation can lead to
undesired oscillations and overshoots produced in the pass band and stop band. The
undesired overshoots and oscillations can be minimized by using a set of time domain
functions named windows. Windowing introduces
transition band, and ripples in pass band and stop band. The spectral characteristics of
commonly used window functions are given below:
Window Transition Width minimum band attenuation

1. Select a window function, w(n) that meets the required stop band Attenuation.
2. Find the value of N, order of the filter using relation between filter order and transition
width of selected window.
3. Find the ideal impulse response, hd(n) of the filter using parameters like wc, group
delay etc
4. Find impulse response of actual filter, h(n) as hd(n)*w(n)
5. Realize the filter using appropriate structure.

35
PROGRAM:
%FIR FILTER BLACKMAN WINDOW (LPF)
Clear all
close all
rp=input('Enter the passband ripple =')
rs=input('Enter the stopband ripple=')
fp=input('Enter the passband frequency=')
fs=input('Enter the stopbandfrequency=')
f=input('Enter the sampling frequency=')
wp=2*fp/f
ws=2*fs/f
neu=-20*log10(sqrt(rp*rs))-13
den=14.6*(fs-fp)/f
n=ceil(neu/den)
n1=n+1
if(rem(n,2)~=0)
n1=n
n=n-1
end
disp('the order is');n
y=blackman(n1)
b=fir1(n,wp,y)
[h,om]=freqz(b,1,256)
m=20*log10(abs(h))
subplot(2,1,1)
plot(om/pi,m)
ylabel('Gain in dB')
xlabel('Frequency in rad/sec')
title('Blackman Window-LPF:Gain')
an=angle(h)
subplot(2,1,2)
plot(om/pi,an)
ylabel('Phase in radians')
xlabel('\omega/pi,gain')
title('Bartlett Window-LPF:Phase')

36
%FIR FILTER BLACKMAN WINDOW(HPF)
clc
clear all
close all
rp=input('Enter the passband ripple =')
rs=input('Enter the stopband ripple=')
fp=input('Enter the passband frequency=')
fs=input('Enter the stopbandfrequency=')
f=input('Enter the sampling frequency=')
wp=2*fp/f
ws=2*fs/f
neu=-20*log10(sqrt(rp*rs))-13
den=14.6*(fs-fp)/f
n=ceil(neu/den)
n1=n+1
if(rem(n,2)~=0)
n1=n
n=n-1
end
disp('the order is');n
y=blackman(n1)
b=fir1(n,wp,'high',y)
[h,om]=freqz(b,1,256)
m=20*log10(abs(h))
subplot(2,1,1)
plot(om/pi,m)
ylabel('Gain in dB')
xlabel('Frequency in rad/sec')
title('Blackman Window-HPF:Gain')
an=angle(h)
subplot(2,1,2)
plot(om/pi,an)
ylabel('Phase in radians')
xlabel('\omega/pi,gain')
title('Bartlett Window-HPF:Phase')

37
%FIR FILTER BLACKMAN WINDOW(BPF)
clc
clear all
close all
rp=input('Enter the passband ripple =')
rs=input('Enter the stopband ripple=')
fp=input('Enter the passband frequency=')
fs=input('Enter the stopbandfrequency=')
f=input('Enter the sampling frequency=')
wp=2*fp/f
ws=2*fs/f
neu=-20*log10(sqrt(rp*rs))-13
den=14.6*(fs-fp)/f
n=ceil(neu/den)
n1=n+1
if(rem(n,2)~=0)
n1=n
n=n-1
end
disp('the order is');n
y=blackman(n1)
wn=[wp ws]
b=fir1(n,wn,y)
[h,om]=freqz(b,1,256)
m=20*log10(abs(h))
subplot(2,1,1)
plot(om/pi,m)
ylabel('Gain in dB')
xlabel('Frequency in rad/sec')
title('Blackman Window-BPF:Gain')
an=angle(h)
subplot(2,1,2)
plot(om/pi,an)
ylabel('Phase in radians')
xlabel('\omega/pi,gain')

38
title('Bartlett Window-BPF:Phase')

%FIR FILTER BLACKMAN WINDOW(BSF)


clc
clear all
close all
rp=input('Enter the passband ripple =')
rs=input('Enter the stopband ripple=')
fp=input('Enter the passband frequency=')
fs=input('Enter the stopbandfrequency=')
f=input('Enter the sampling frequency=')
wp=2*fp/f
ws=2*fs/f
neu=-20*log10(sqrt(rp*rs))-13
den=14.6*(fs-fp)/f
n=ceil(neu/den)
n1=n+1
if(rem(n,2)~=0)
n1=n
n=n-1
end
disp('the order is');n
y=blackman(n1)
wn=[wp ws]
b=fir1(n,wn,'stop',y)
[h,om]=freqz(b,1,256)
m=20*log10(abs(h))
subplot(2,1,1)
plot(om/pi,m)
ylabel('Gain in dB')
xlabel('Frequency in rad/sec')
title('Blackman Window-BSF:Gain')
an=angle(h)
subplot(2,1,2)
plot(om/pi,an)
ylabel('Phase in radians')
xlabel('\omega/pi,gain')

39
title('Blacknam Window-BSF:Phase')

%FIR FILTER BARTLETT WINDOW(LPF)


clc
clear all
close all
rp=input('Enter the passband ripple =')
rs=input('Enter the stopband ripple=')
fp=input('Enter the passband frequency=')
fs=input('Enter the stopbandfrequency=')
f=input('Enter the sampling frequency=')
wp=2*fp/f
ws=2*fs/f
neu=-20*log10(sqrt(rp*rs))-13
den=14.6*(fs-fp)/f
n=ceil(neu/den)
n1=n+1
if(rem(n,2)~=0)
n1=n
n=n-1
end
disp('the order is');n
y=bartlett(n1)
b=fir1(n,wp,y)
[h,om]=freqz(b,1,256)
m=20*log10(abs(h))
subplot(2,1,1)
plot(om/pi,m)
ylabel('Gain in dB')
xlabel('Frequency in rad/sec')
title('Bartlett Window-LPF:Gain')
an=angle(h)
subplot(2,1,2)
plot(om/pi,an)
ylabel('Phase in radians')
xlabel('\omega/pi,gain')
title('Bartlett Window-LPF:Phase')

40
%FIR FILTER BARTLETT WINDOW(HPF)

clc
clear all
close all
rp=input('Enter the passband ripple =')
rs=input('Enter the stopband ripple=')
fp=input('Enter the passband frequency=')
fs=input('Enter the stopbandfrequency=')
f=input('Enter the sampling frequency=')
wp=2*fp/f
ws=2*fs/f
neu=-20*log10(sqrt(rp*rs))-13
den=14.6*(fs-fp)/f
n=ceil(neu/den)
n1=n+1
if(rem(n,2)~=0)
n1=n
n=n-1
end
disp('the order is');n
y=bartlett(n1)
b=fir1(n,wp,highy)
[h,om]=freqz(b,1,256)
m=20*log10(abs(h))
subplot(2,1,1)
plot(om/pi,m)
ylabel('Gain in dB')
xlabel('Frequency in rad/sec')
title('Bartlett Window-HPF:Gain')
an=angle(h)
subplot(2,1,2)
plot(om/pi,an)
ylabel('Phase in radians')
xlabel('\omega/pi,gain')
title('Bartlett Window-HPF:Phase')

41
%FIR FILTER BARTLETT WINDOW(BPF)

clc
clear all
close all
rp=input('Enter the passband ripple =')
rs=input('Enter the stopband ripple=')
fp=input('Enter the passband frequency=')
fs=input('Enter the stopbandfrequency=')
f=input('Enter the sampling frequency=')
wp=2*fp/f
ws=2*fs/f
neu=-20*log10(sqrt(rp*rs))-13
den=14.6*(fs-fp)/f
n=ceil(neu/den)
n1=n+1
if(rem(n,2)~=0)
n1=n
n=n-1
end
disp('the order is');n
y=bartlett(n1)
wn=[wp ws]
b=fir1(n,wn,y)
[h,om]=freqz(b,1,256)
m=20*log10(abs(h))
subplot(2,1,1)
plot(om/pi,m)
ylabel('Gain in dB')
xlabel('Frequency in rad/sec')
title('Bartlett Window-BPF:Gain')
an=angle(h)
subplot(2,1,2)
plot(om/pi,an)
ylabel('Phase in radians')
xlabel('\omega/pi,gain')

42
title('Bartlett Window-BPF:Phase')

%FIR FILTER BARTLETT WINDOW(BSF)

clc
clear all
close all
rp=input('Enter the passband ripple =')
rs=input('Enter the stopband ripple=')
fp=input('Enter the passband frequency=')
fs=input('Enter the stopbandfrequency=')
f=input('Enter the sampling frequency=')
wp=2*fp/f
ws=2*fs/f
neu=-20*log10(sqrt(rp*rs))-13
den=14.6*(fs-fp)/f
n=ceil(neu/den)
n1=n+1
if(rem(n,2)~=0)
n1=n
n=n-1
end
disp('the order is');n
y=bartlett(n1)
wn=[wp ws]
b=fir1(n,wn,'stop',y)
[h,om]=freqz(b,1,256)
m=20*log10(abs(h))
subplot(2,1,1)
plot(om/pi,m)
ylabel('Gain in dB')
xlabel('Frequency in rad/sec')
title('Bartlett Window-BSF:Gain')
an=angle(h)
subplot(2,1,2)
plot(om/pi,an)
ylabel('Phase in radians')
xlabel('\omega/pi,gain')

43
title('Bartlett Window-BSF:Phase')
%FIR FILTER HAMMING WINDOW(LPF)
clc
clear all
close all
rp=input('Enter the passband ripple =')
rs=input('Enter the stopband ripple=')
fp=input('Enter the passband frequency=')
fs=input('Enter the stopbandfrequency=')
f=input('Enter the sampling frequency=')
wp=2*fp/f
ws=2*fs/f
neu=-20*log10(sqrt(rp*rs))-13
den=14.6*(fs-fp)/f
n=ceil(neu/den)
n1=n+1
if(rem(n,2)~=0)
n1=n
n=n-1
end
disp('the order is');n
y=hamming(n1)
b=fir1(n,wp,y)
[h,om]=freqz(b,1,256)
m=20*log10(abs(h))
subplot(2,1,1)
plot(om/pi,m)
ylabel('Gain in dB')
xlabel('Frequency in rad/sec')
title('Hamming Window-LPF:Gain')
an=angle(h)
subplot(2,1,2)
plot(om/pi,an)
ylabel('Phase in radians')
xlabel('\omega/pi,gain')
title('Hamming Window-LPF:Phase')

44
%FIR FILTER HAMMING WINDOW(HPF)

clc
clear all
close all
rp=input('Enter the passband ripple =')
rs=input('Enter the stopband ripple=')
fp=input('Enter the passband frequency=')
fs=input('Enter the stopbandfrequency=')
f=input('Enter the sampling frequency=')
wp=2*fp/f
ws=2*fs/f
neu=-20*log10(sqrt(rp*rs))-13
den=14.6*(fs-fp)/f
n=ceil(neu/den)
n1=n+1
if(rem(n,2)~=0)
n1=n
n=n-1
end
disp('the order is');n
y= hamming (n1)
b=fir1(n,wp,highy)
[h,om]=freqz(b,1,256)
m=20*log10(abs(h))
subplot(2,1,1)
plot(om/pi,m)
ylabel('Gain in dB')
xlabel('Frequency in rad/sec')
title('Hamming Window-HPF:Gain')
an=angle(h)
subplot(2,1,2)
plot(om/pi,an)
ylabel('Phase in radians')
xlabel('\omega/pi,gain')
title('Hamming Window-HPF:Phase')

45
%FIR FILTER HAMMING WINDOW(BPF)

clc
clear all
close all
rp=input('Enter the passband ripple =')
rs=input('Enter the stopband ripple=')
fp=input('Enter the passband frequency=')
fs=input('Enter the stopbandfrequency=')
f=input('Enter the sampling frequency=')
wp=2*fp/f
ws=2*fs/f
neu=-20*log10(sqrt(rp*rs))-13
den=14.6*(fs-fp)/f
n=ceil(neu/den)
n1=n+1
if(rem(n,2)~=0)
n1=n
n=n-1
end
disp('the order is');n
y= hamming (n1)
wn=[wp ws]
b=fir1(n,wn,y)
[h,om]=freqz(b,1,256)
m=20*log10(abs(h))
subplot(2,1,1)
plot(om/pi,m)
ylabel('Gain in dB')
xlabel('Frequency in rad/sec')
title('Hamming Window-BPF:Gain')
an=angle(h)
subplot(2,1,2)
plot(om/pi,an)
ylabel('Phase in radians')
xlabel('\omega/pi,gain')
title('Hamming Window-BPF:Phase')

46
%FIR FILTER HAMMING WINDOW(BSF)

clc
clear all
close all
rp=input('Enter the passband ripple =')
rs=input('Enter the stopband ripple=')
fp=input('Enter the passband frequency=')
fs=input('Enter the stopbandfrequency=')
f=input('Enter the sampling frequency=')
wp=2*fp/f
ws=2*fs/f
neu=-20*log10(sqrt(rp*rs))-13
den=14.6*(fs-fp)/f
n=ceil(neu/den)
n1=n+1
if(rem(n,2)~=0)
n1=n
n=n-1
end
disp('the order is');n
y= hamming (n1)
wn=[wp ws]
b=fir1(n,wn,'stop',y)
[h,om]=freqz(b,1,256)
m=20*log10(abs(h))
subplot(2,1,1)
plot(om/pi,m)
ylabel('Gain in dB')
xlabel('Frequency in rad/sec')
title(' Hamming Window-BSF:Gain')
an=angle(h)
subplot(2,1,2)
plot(om/pi,an)
ylabel('Phase in radians')
xlabel('\omega/pi,gain')
title('Hamming Window-BSF:Phase')

47
clc
% FIR FILTER KAISER WINDOW(LPF)
clear all
close all
rp=input('Enter the passband ripple =')
rs=input('Enter the stopband ripple=')
fp=input('Enter the passband frequency=')
fs=input('Enter the stopbandfrequency=')
f=input('Enter the sampling frequency=')
wp=2*fp/f
ws=2*fs/f
neu=-20*log10(sqrt(rp*rs))-13
den=14.6*(fs-fp)/f
n=ceil(neu/den)
n1=n+1
if(rem(n,2)~=0)
n1=n
n=n-1
end
disp('the order is');n
y=kaiser(n1)
b=fir1(n,wp,y)
[h,om]=freqz(b,1,256)
m=20*log10(abs(h))
subplot(2,1,1)
plot(om/pi,m)
ylabel('Gain in dB')
xlabel('Frequency in rad/sec')
title('kaiser Window-LPF:Gain')
an=angle(h)
subplot(2,1,2)
plot(om/pi,an)
ylabel('Phase in radians')
xlabel('\omega/pi,gain')
title('kaiser Window-LPF:Phase')

48
%FIR FILTER KAISER WINDOW(HPF)

clc
clear all
close all
rp=input('Enter the passband ripple =')
rs=input('Enter the stopband ripple=')
fp=input('Enter the passband frequency=')
fs=input('Enter the stopbandfrequency=')
f=input('Enter the sampling frequency=')
wp=2*fp/f
ws=2*fs/f
neu=-20*log10(sqrt(rp*rs))-13
den=14.6*(fs-fp)/f
n=ceil(neu/den)
n1=n+1
if(rem(n,2)~=0)
n1=n
n=n-1
end
disp('the order is');n
y= kaiser(n1)
b=fir1(n,wp,highy)
[h,om]=freqz(b,1,256)
m=20*log10(abs(h))
subplot(2,1,1)
plot(om/pi,m)
ylabel('Gain in dB')
xlabel('Frequency in rad/sec')
title('Kaiser Window-HPF:Gain')
an=angle(h)
subplot(2,1,2)
plot(om/pi,an)
ylabel('Phase in radians')
xlabel('\omega/pi,gain')
title('Kaiser Window-HPF:Phase')

49
%FIR FILTER KAISER WINDOW(BPF)
clc
clear all
close all
rp=input('Enter the passband ripple =')
rs=input('Enter the stopband ripple=')
fp=input('Enter the passband frequency=')
fs=input('Enter the stopbandfrequency=')
f=input('Enter the sampling frequency=')
wp=2*fp/f
ws=2*fs/f
neu=-20*log10(sqrt(rp*rs))-13
den=14.6*(fs-fp)/f
n=ceil(neu/den)
n1=n+1
if(rem(n,2)~=0)
n1=n
n=n-1
end
disp('the order is');n
y= kaiser(n1)
wn=[wp ws]
b=fir1(n,wn,y)
[h,om]=freqz(b,1,256)
m=20*log10(abs(h))
subplot(2,1,1)
plot(om/pi,m)
ylabel('Gain in dB')
xlabel('Frequency in rad/sec')
title('kaiser Window-BPF:Gain')
an=angle(h)
subplot(2,1,2)
plot(om/pi,an)
ylabel('Phase in radians')
xlabel('\omega/pi,gain')
title('kaiser Window-BPF:Phase')

50
%FIR FILTER KAISER WINDOW(BSF)
clc
clear all
close all
rp=input('Enter the passband ripple =')
rs=input('Enter the stopband ripple=')
fp=input('Enter the passband frequency=')
fs=input('Enter the stopbandfrequency=')
f=input('Enter the sampling frequency=')
wp=2*fp/f
ws=2*fs/f
neu=-20*log10(sqrt(rp*rs))-13
den=14.6*(fs-fp)/f
n=ceil(neu/den)
n1=n+1
if(rem(n,2)~=0)
n1=n
n=n-1
end
disp('the order is');n
y= kaiser(n1)
wn=[wp ws]
b=fir1(n,wn,'stop',y)
[h,om]=freqz(b,1,256)
m=20*log10(abs(h))
subplot(2,1,1)
plot(om/pi,m)
ylabel('Gain in dB')
xlabel('Frequency in rad/sec')
title(' Kaiser Window-BSF:Gain')
an=angle(h)
subplot(2,1,2)
plot(om/pi,an)
ylabel('Phase in radians')
xlabel('\omega/pi,gain')
title('Kaiser Window-BSF:Phase')

51
EXPERIMENT NO:
RESULT: Implemented FIR filter using window method and plotted the responses.
13

FIR FILTER USING FREQUENCY SAMPLING METHOD

AIM: To implement FIR filter using Frequency sampling method.

THEORY:
A linear phase FIR filter is characterized by the impulse response,

Design methods for FIR filters are based on the direct approximation of the required
digital specification such as magnitude and phase response.
It is found that the impulse response of ideal filters is non causal, doubly infinite in length
and not absolutely summable. Since impulse response begins at -, no finite delay can
make the impulse response causal. So ideal filters are not realizable in real and non- real
time.
fir2 designs frequency sampling-based digital FIR filters with arbitrarily shaped
frequency response. b = fir2(n,f,m) returns row vector b containing the n+1 coefficients
of an order n FIR filter. The frequency-magnitude characteristics of this filter match those
given by vectors f and m:

f is a vector of frequency points in the range from 0 to 1, where 1 corresponds to


the Nyquist frequency. The first point of f must be 0 and the last point 1. The
frequency points must be in increasing order.

m is a vector containing the desired magnitude response at the points specified in


f.

f and m must be the same length.

Duplicate frequency points are allowed, corresponding to steps in the frequency


response.

52
b = fir2(n,f,m,window) uses the window specified in the column vector window.
The vector window must be n+1 elements long. If no window is specified, fir2
uses a Hamming window of length n+1.

PROGRAM:

clc
clear all
close all
n=15
m=[ 1 1 1 0.557 1 0.0841 0 0]
f=[0 1/7 2/7 3/7 4/7 5/7 6/7 1]
window=[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]
b=fir2(n,f,m,window)
disp('The coefficients are=')
disp(b)
[h,w]=freqz(b,1,128)
plot(f,m,w/pi,abs(h))
title('Desired and actual response')

RESULT: FIR filter design using frequency sampling method was implemented.

53
EXPERIMENT NO:
14

OPTIMAL EQUIRIPPLE DESIGN OF FIR FILTER

AIM: To execute the matlab program of an optimal equiripple design of FIR filter

THEORY:

The Parks-McClellan algorithm uses the Remez exchange algorithm and


Chebyshev approximation theory to design filters with an optimal fit between the desired
and actual frequency responses. The filters are optimal in the sense that the maximum
error between the desired frequency response and the actual frequency response is
minimized. Filters designed this way exhibit an equiripple behavior in their frequency
responses and are sometimes called equiripple filters. firpm exhibits discontinuities at
the head and tail of its impulse response due to this equiripple nature.

[n,fo,ao,w] = firpmord(f,a,dev) finds the approximate order, normalized


frequency band edges, frequency band amplitudes, and weights that meet input
specifications f, a, and dev.

b = firpm(n,f,a) returns row vector b containing the n+1 coefficients of the order n
FIR filter whose frequency-amplitude characteristics match those given by vectors f and
a.

PROGRAM:

clc
clear all
close all
edgepoints=input('Enter edge frequency of each band=')
Fs=input('Sampling frequency in Hz=')
bandmag=input('Enter magnitude values for each passband and stopband=')

54
dev=input('Enter desired ripple in each band=')
wt=input('Type in values for relative weights in each band=')
[N,fpoints,magpoints,wt]=firpmord(edgepoints,bandmag,dev,Fs)
disp('order of FIR filter is=')
disp(N)
b=firpm(N,fpoints,magpoints,wt)
[h,w]=freqz(b,1,256)
H=abs(h)
Hdb=20*log10(H)
plot(w/pi,Hdb)
grid
title('Magnitude response of equiripple,linear phase filter')
xlabel('Normalized frequency')
ylabel('Magnitude in db')

RESULT:Executed and plotted the equiripple design of an FIR filter.

55
EXPERIMENT NO:
15

GENERATION OF AM, FM AND PWM SIGNAL

AIM: To generate an Amplitude Modulated (AM) signal, Frequency Modulated (FM)


signal and Pulse Width Modulated (PWM) signal

THEORY:

Amplitude Modulation

In an amplitude modulation (AM),the instantaneous amplitude of a carrier signal


having high frequency is varied by the instantaneous amplitude of a modulating voltage


having low frequency.Let the modulating frequency be e ( t )=E t
m m sin m .

Then the modulated signal e (t) is expressed as

E
+E t
e ( t )= c m sin m t sin c .

E
E t ,where
c c +msin m t sin c

Em
m=
Ec is known as modulating index.

Emax and Emin are the maximum and minimum amplitudes of a AM signal in the positive
side.

Frequency Modulation

56
In the Frequency Modulation(FM),the frequency of a carrier signal having high
frequency is varied by the instantaneous amplitude of a modulating voltage having low


frequency. Let the modulating frequency be e ( t )=E t Then the
m m sin m .

modulated signal e (t) is expressed as

E
+E t
e ( t )= c m sin m t sin c .

E
E t ,where
c c +msin m t sin c

Em
m=
Ec is known as modulating index.

Emax and Emin are the maximum and minimum amplitudes of a AM signal in the positive
side.

Pulse Width Modulation

PWM does the modulation of the duty cycle of the pulse.In addition of use in
communication systems, PWM is also used in voltage regulators such as Switched Mode
Power Supplies(SMPS) to control the power delivered to load.PWM can be generated
using a comparator to which the modulating signal and a reference ramp(sawtooth)
waveform are fed.

PROGRAM

%generation of AM and FM signal


clc;
clear all;
close all;
t=(0:0.005:1);

57
Fm=input('ENTER FREQUENCY OF MODULATING SIGNAL');
fc=input('ENTER FREQUENCY OF CARRIER SIGNAL FOR AM');
m1=input('ENTER MODULATION INDEX OF AM');
Fc2=input('ENTER FREQUENCY OF CARRIER SIGNAL FOR FM');
m2=input('ENTER MODULATION INDEX OF FM');
x=sin(2*pi*fc*t);
subplot(2,2,1);
plot(x);
title('CARRIER WAVE');
ylabel('AMPLITUDE');
xlabel('TIME');
y=sin(2*pi*Fm*t);
subplot(2,2,2);
plot(y);
title('MODULATING WAVE');
ylabel('AMPLITUDE');
xlabel('TIME');
z=(1+m1*y).*x;
subplot(2,2,3);
plot(z);
title('AM SIGNAL');
ylabel('AMPLITUDE');
xlabel('TIME');
Z=cos((2*pi*Fc2*t)+(m2.*y));
subplot(2,2,4);
plot(Z);
title('FM SIGNAL');
ylabel('AMPLITUDE');
xlabel('TIME');

%PWM wave Generation


clc;
clear all;
close all;
t=0:0.001:1;
s=sawtooth(2*pi*10*t+pi)
m=0.75*sin(2*pi*1*t)
n=length(s)

58
for i=1:n
if(m(i)>=s(i))
pwm(i)=1
elseif (m(i)<=s(i))
pwm(i)=0
end
end
plot(t,pwm,'k',t,m,'--r',t,s,'--b')
title('PWM wave')
axis([0 1 -1.5 1.5])

RESULT: Generated and plotted the AM signal, FM signal and PWM signal

EXPERIMENT NO:
15
STUDY OF SAMPLING

AIM: To sample a given signal at three different frequencies.

THEORY:

Sampling theorem: When a band-limited signal with bandwidth W is sampled


using sampling frequency 2W,it is possible to reconstruct signal from signal
samples.The sampling rate 2W is called Nyquist rate.The sampling frequency selected is
denotes as fs.The nyquist frequency will be fs/2.

PROGRAM:

%Original signal for sampling


t=0:0.001:0.1;
Fm=input('Enter the signal frequency');
y=cos(2*pi*Fm*t);
subplot(2,2,1);
plot(t,y);

59
xlabel('Time');
ylabel('Amplitude');
title('Original Signal');
%when Fs<2Fm
fs1=input('Enter the frequency for fs<2fm');
ts1=1/fs1;
tx1=0:ts1:0.1;
y1=cos(2*pi*Fm*tx1);
subplot(2,2,2);
stem(tx1,y1);
xlabel('Time');
ylabel('amplitude');
title('Fs<2Fm');
%When Fs=2Fm
fs2=input('Enter the frequency for fs=2fm');
ts2=1/fs2;
tx2=0:ts2:0.1;
y2=cos(2*pi*Fm*tx2);
subplot(2,2,3);
stem(tx2,y2);
xlabel('Time');
ylabel('amplitude');
title('Fs=2Fm');
%When Fs>2Fm
fs3=input('Enter the frequency for fs>2fm');
ts3=1/fs3;
tx3=0:ts3:0.1;
y3=cos(2*pi*Fm*tx3);
subplot(2,2,4);
stem(tx3,y3);
xlabel('Time');
ylabel('amplitude');
title('Fs>2Fm');

RESULT: Sampling of a given signal at three different frequencies were executed and
plotted.

60
EXPERIMENT NO:
16
Z-TRANSFORM

AIM: To plot the poles and zeros for a given transfer function

THEORY:

The Z transform is used for characterization of discrete time system by analysing


its transfer function in the Z domain. The poles and zeros of the transfer function are
further used for stability analysis of the discrete time systems.The Z transform provide a
mathematical framework for designing digital filters based on the theory of analog filters
using mapping technique.

zplane(z,p) plots the zeros specified in column vector z and the poles specified in
column vector p in the current figure window. The symbol 'o' represents a zero and the
symbol 'x' represents a pole. The plot includes the unit circle for reference. If z and p are
arrays, zplane plots the poles and zeros in the columns of z and p in different colors.

PROGRAM:

61
clc
clear all
close all
num=input('Enter the numerator coefficients')
den=input('Enter the denominator coefficients')
N=input('Enter the length of the sequence')
[b,a]=freqz(num,den,N)
zplane(b,a)

RESULT:Program is executed and plotted the poles and zeros of a given transfer
function

62
INTRODUCTION TO TMS320C 6713 DSK

A DSP processor is a specialized kind of microprocessor. Digital signal processing


is one of the core technologies, in rapidly growing application areas,
such as wireless communications, audio and video processing and
industrial control. The number and variety of products that include
some form of digital signal processing has grown
dramatically over the last few years. DSP has become a key
component, in many of the
consumer, communications, medical and industrial products which
implement the signal
processing using microprocessors, Field Programmable Gate Arrays
(FPGAs), Custom ICs etc.
Due to increasing popularity of the above mentioned applications, the
variety of the DSP-capable processors has expanded greatly. DSPs are
processors or microcomputers whose hardware, software, and
instruction sets are optimized for high-speed numeric processing
applications, an essential for processing digital data, representing
analog signals in real time. The DSP processors have gained increased
popularity because of the various advantages like reprogram ability in
the field, cost-effectiveness, speed, energy efficiency etc. The general
purpose microprocessor architecture is not suitable for real time signal processing owing
to repetitive arithmetic operations and heavy data output within the CPU. So the
hardware architecture and instruction set must be optimized in DSP processors. This is
achieved in the following ways:
Harvard Architecture
Pipelining
replication
On-chip memory or cache
Extended Parallelism
Fast,dedicated hardware multiplier/accumulator
Special Instructions dedicated to DSP

63
DSP processors can be broadly classified into general purpose and special purpose DSP
processors. There are two types of special purpose hardware:
Algortihm Specific Digital signal processor, which is used for execution of
efficient DSP algorithms.
Application Specific Digital Signal Processor, which is used for
specific applications like telecommunications, control etc.

Difference between DSPs and Other Microprocessors

Over the past few years it is seen that general purpose computers are capable of
performing two major tasks.
(1) Data Manipulation, and
(2) Mathematical Calculations
All the microprocessors are capable of doing these tasks but it is difficult to make a
device which can perform both the functions optimally, because of the involved technical
trade offs like the size of the instruction set, how interrupts are handled etc. As a broad
generalization these factors have made traditional microprocessors such as Pentium
Series, primarily directed at data manipulation. Similarly DSPs are designed to perform
the mathematical calculations needed in Digital Signal Processing, Data manipulation
involves storing and sorting of information. For instance, a word processing program
does a basic task of storing, organizing and retrieving of the information. This is
achieved by moving data from one location to another and testing for inequalities (A=B,
A<B etc.). While mathematics is occasionally used in this type of application, it is
infrequent and does not significantly affect the overall execution speed. In comparison to
this, the execution speed of most of the DSP algorithms is limited almost completely by
the number of multiplications and additions required.
In addition to performing mathematical calculations very rapidly, DSPs must also have a
predictable execution time.Most DSPs are used in applications where the processing is
continuous, not having a defined start or end. The cost, power consumption, design
difficulty etc increase along with the execution speed, which makes an accurate
knowledge of the execution time, critical for selecting proper device, as well as

64
algorithms that can be applied. DSPs can also perform the tasks in parallel instead of
serial in case of traditional microprocessors.

DSP processors can include fixed point devices as well as floating point devices. DSP's
are concerned with Real time signal processing. The signal input is usually analog in
nature. While analog devices based on discrete components are sensitive to temperature
etc. DSP prosessor based systems are less susceptible to environmental condiions. They
are easy to use, flexible and economical.

C6713 DSK board

The Texas Instruments TMS320C6713 Digital Signal Processing Starter Kit (DSK) is a
low cost development platform for real - time digital signal processing applications. The
TMS320C6x are the first processors to use velociTI architecture, having implemented the
VLIW architecture. The TMS320C62x is a 16-bit fixed point processor and the 67x is a
floating point processor, with 32-bit integer support.

65
Block diagram of TMS320C 6713 DSK

Board diagram of TMS320C 6713 DSK

Features:

The DSK comes with a full compliment of on-board devices that suit a wide variety of
application environments. Key features include:
A Texas Instruments TMS320C6713 DSP operating at 225 MHz.
An AIC23 stereo codec
16 Mbytes of synchronous DRAM
512 Kbytes of non-volatile Flash memory (256 Kbytes usable in default
configuration)
4 user accessible LEDs and DIP switches
Software board configuration through registers implemented in CPLD
Configurable boot options
Standard expansion connectors for daughter card use

66
JTAG emulation through on-board JTAG emulator with USB host
interface or external emulator
Single voltage power supply (+5V)
Functional Overview

The DSP on the 6713 DSK interfaces to on-board peripherals through a


32-bit wide EMIF (External Memory InterFace). The SDRAM, Flash and
CPLD are all connected to the bus. EMIF signals are also connected
daughter card expansion connectors which are used for third party
add-in boards. The DSP interfaces to analog audio signals through an
on-board AIC23 codec and four 3.5 mm audio jacks (microphone input,
line input, line output, and headphone output). The codec can select
the microphone or the line input as the active input. The analog output
is driven to both the line out (fixed gain) and headphone (adjustable
gain) connectors. McBSP0 is used to send commands to the codec
control interface while McBSP1 is used for digital audio data. McBSP0
and McBSP1 can be re-routed to the expansion connectors in software.
A programmable logic device called a CPLD is used to implement glue
logic that ties the board components together. The CPLD has a register
based user interface that lets the user configure the board by reading
and writing to its registers.The DSK includes 4 LEDs and a 4 position
DIP switch as a simple way to provide the user with interactive
feedback. Both are accessed by reading and writing to the CPLD
registers.
An included 5V external power supply is used to power the board. On-
board switching voltage regulators provide the +1.26V DSP core
voltage and +3.3V I/O supplies. The board is held in reset until these
supplies are within operating specifications.
Code Composer communicates with the DSK through an embedded
JTAG emulator

67
with a USB host interface. The DSK can also be used with an external
emulator

Code Composer Studio

Introduction

Simplified Code Composer Studio IDE Development Flow


Power On Self Test (POST)

Power up DSK and watch LEDs


Power On Self Test (POST) program stored in FLASH memory
automatically executes
POST takes 10-15 seconds to complete.
All DSK subsystems are automatically tested.
During POST, a 1kHz sinusoid is output from the AIC23 codec for 1
second
Listen with headphones or watch on oscilloscope
If POST is successful, all four LEDs blink 3 times and then remain on

68
Use DSK diagnostic utility to test DSK functionality

CCS provides an IDE to incorporate the software tools. CCS includes


tools for code generation, such as a C compiler, an assembler, and a
linker. It has graphical capabilities and supports realtime debugging. It
provides an easy-to-use software tool to build and debug programs.The
C compiler compiles a C source program with extension .c to produce
an assembly source file with extension.asm.The assembler assembles
an.asm source file to produce a machine language object file with
extension.obj. The linker combines object files and object libraries as
input to produce an executable file with extension.out. This executable
file represents a linked common object file format (COFF), popular in
Unix-based systems and adopted by several makers of digital signal
processors .This executable file can be loaded and run directly on the
C6713 processor. A linear optimizer optimizes this source file to create
an assembly file with extension .asm (similar to the task of the C
compiler). To create an application project, one can add the

69
appropriate files to the project. Compiler/linker options can readily be
specified. A number of debugging features are available, including
setting breakpoints and watching variables; viewing memory, registers,
and mixed C and assembly code; graphing results; and monitoring
execution time. One can step through a program in different ways
(step into, over, or out). Real-time analysis can be performed using
real-time data exchange (RTDX). RTDX allows for data exchange
between the host PC and the target DSK, as well as analysis in real
time without stopping the target. Key statistics and performance can
be monitored in real time. Through the joint team action group (JTAG),
communication with on-chip emulation support occurs to control and
monitor program execution. The C6713 DSK board includes a JTAG
interface through the USB port.

Creating a New Project:


1. Select Project New
2. Give the name, location, select project type as Executable(.out), target as
TMS320C67XX
3. On the left side of the window project folder opens
4. Use File New source file to create the .c file
.5. Save it to the project.

70
Right click 'source' and select 'Add files to project'
Add "c6713dskinit.c"
Similarly add "vectors intr.asm" or "vectors poll.asm" depending whether data
samples are taken on interrupt basis or using polling method
Also add "C6713dsk.cmd"

Right click 'Libraries' and select 'Add files to project'


Add "rts6700.lib" from 'C:\CCStudio v 3.1\ C6000\ cgtools\ lib'
Add "dsk6713.lib" from 'C:\CCStudio v 3.1\C6000 \dsk6713 \ lib'
Add "csl6713.lib" from 'C: \CCStudio v 3.1 \C6000 \ csl \ lib'

Select Project Build options Compiler


In category 'Basic', give target version as C671x(-mv6710)
In category 'Advanced', give endianness as 'Little Endian', memory models as 'far'
In category 'Preprocessor', give Pre-define symbol as 'CHIP 6713'

71
Select Project Build options Linker

Output file name should be default to \ Debug\ sine8 LED.out and Autoinit Model
should default to Run - Time Autoinitialization. Set Library Search Path to c:
n\CCStudio v3.1 n C6000 \ dsk6713 \ lib and set Include Libraries to rts6700.lib;
dsk6713bsl.lib;csl6713.lib .

Compile, build and rebuild the project


This creates an executable _le sine8 LED.out that can be loaded into the C6713
processor and run. Note that the commands for compiling, assembling, and
linking are performed with the Build option.

Give Debug Connect to connect the target processor

Check that the symbol in the bottom left - hand corner of the CCS window
indicates connection to the DSK.

Give File Load Program


Loads the file sine8 LED.out,which should be stored in c\CCStudio v3.1\
MyProjects \ sine8 LED \ Debug .

Run the program

EXPERIMENT NO: 1

DATE:
1. SINE WAVE GENERATION

AIM: To generate sine wave.

EQUIPMENTS:

72
Operating System Windows XP
Constructor - Simulator
Software - CCStudio 3.1

THEORY:
A Sine wave can be generated using a data table, using DIP switches using LEDs etc in
TMS3206713 DSP processor. Here sinewave is generated using a sine function and a
data table sine.dat. The c program uses a probe point to collect data points and a gain
factor is added to the signal. The sinewave project is created and all the necessary files
like the source files, the data files the library files are added to the project. The project is
then buid and loaded to the processor. In the build options change the processor type from
debug to FILEIO. In the C program add probe point to data IO. In the FILEIO add the
data file and give its starting address as currentBuffer.input, click on wrap around and add
the probe point. In the add probepoint select the Point and connect it to the data point and
say replace and apply. The probe point is now added. Now go to view and select graph
and give the starting address as currentBuffer.input to the input graph. Similarly go to
view and select graph and give the address as currentBuffer.out to the output. Debug and
run the program. A sinewave graph can be seen on the CCs plot.

PROGRAM:

#include <stdio.h>
#include "sine.h"
int gain = INITIALGAIN;
BufferContents currentBuffer;

static void processing();


static void dataIO();
void main()
{
puts("SineWave example started.\n");
while(TRUE)
{
dataIO();
processing();

73
}
}
static void processing()
{
int size = BUFFSIZE;
while(size--)
{
currentBuffer.output[size] = currentBuffer.input[size] * gain;
}
}
static void dataIO()
{
return;
}

RESULT: Sinewave was generated and plotted using CCS.

74
75
EXPERIMENT NO: 2

DATE:
2. DISCRETE FOURIER TRANSFORM

AIM: To generate Discrete Fourier transform of a sequence of real numbers.

EQUIPMENTS:
Operating System Windows XP
Constructor - Simulator
Software - CCStudio 3.1

THEORY:

In mathematics the discrete Fourier transform (DFT) is a specific kind ofdiscrete


transform used in Fourier analysis.It transforms one function into another, which is called
the frequency domain representation, or simply the DFT, of the original function . But the
DFT requires an input function that is discrete and whose non-zero values have a limited
(finite) duration. Such inputs are often created by sampling a continuous function, like a
person's voice. Unlike the DTFT it only evaluates enough frequency components to
reconstruct the finite segment that was analyzed. Using the DFT implies that the finite
segment that is analyzed is one period of an infinitely extended periodic signal; if this is
not actually true, a window finctionhas to be used to reduce the artifacts in the spectrum.
For the same reason, the inverse DFT cannot reproduce the entire time domain, unless the
input happens to be periodic (forever). Therefore it is often said that the DFT is a
transform for Fourier analysis of finite-domain discrete-time functions. The sinusoidal
basis functions of the decomposition have the same properties.

The input to the DFT is a finite sequence of real or complex numbers making the DFT
ideal for processing information stored in computers.In particular, the DFT is widely
employed in signal processing and related fields to analyze the frequencies contained in a
sampled signal, to solve partial differential equations and to perform other operations
such as convolutions or multiplying large integers. A key enabling factor for these
applications is the fact that the DFT can be computed efficiently in practice using a fast
fourier transform (FFT) algorithm.

76
Create the project DFT and add all the necessary files. Build the project and then load it
into the processor. Debug and run the project. In the view options select graph and give
the address as samples and change the data plot style to bar. Also select the FFT
magnitude and phase plot. Debug and run the program. The DFT of a sequence of real
numbers with the output in CCS Graphical Display is plotted.

PROGRAM:

#include <stdio.h>

#include <math.h>

#define PI 3.14159265358979

#define N 100

#define TESTFREQ 800.0

#define SAMPLING_FREQ 8000.0

typedef struct

float real;

float imag;

} COMPLEX;

COMPLEX samples[N];

void dft(COMPLEX *x)

77
COMPLEX result[N];

int k,n;

for (k=0 ; k<N ; k++)

result[k].real=0.0;

result[k].imag = 0.0;

for (n=0 ; n<N ; n++)

result[k].real += x[n].real*cos(2*PI*k*n/N) + x[n].imag*sin(2*PI*k*n/N);

result[k].imag += x[n].imag*cos(2*PI*k*n/N) - x[n].real*sin(2*PI*k*n/N);

for (k=0 ; k<N ; k++)

x[k] = result[k];

void main()

78
int n;

for(n=0 ; n<N ; n++)

samples[n].real = cos(2*PI*TESTFREQ*n/SAMPLING_FREQ);

samples[n].imag = 0.0;

printf("real input data stored in array samples[]\n");

printf("\n"); // place breakpoint here

dft(samples); //call DFT function

printf("done!\n");

RESULT: N point DFT of a sequence of real numbers read from a look up table is
generated and plotted.

79
80
EXPERIMENT NO: 3

DATE:
3 .FINITE IMPULSE RESPONSE FILTERS

AIM: To verify FIR filters.

EQUIPMENTS:
Operating System Windows XP
Constructor - Simulator
Software - CCStudio 3.1

THEORY:
A Finite Impulse Response (FIR) filter is a discrete linear time-invariant systemwhose
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 fordiscrete-time
convolution.In this equation, x(k) and y(n) represent the input to and output from the
filter at timen. h(n-k) is the transversal filter coefficients at time n. These coefficients
aregenerated 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 offinite length
does this. Types of windows available are Rectangular, Barlett,Hamming, Hanning,
Blackmann window etc. This FIR filter is an all zero filter.
Create the project and add all the necessary files. Build and load the program in to the
processor.Debug and run the program .Enter the no.of samples as 64 and choice of the
window function as either 1 or 2.View the rectangular window by giving the starting
address as wr and buffer size as 64,similarly view the triangular window by giving the
starting address as wt.

PROGRAM:
#include<stdio.h>
#include<math.h>
#define pi 3.1415

81
intn,N,c;
floatwr[64],wt[64];
void main()
{
printf("\n enter no. of samples,N= :");
scanf("%d",&N);
printf("\n enter choice of window function\n 1.rect \n 2. triang \n c= :");
scanf("%d",&c);
printf("\n elements of window function are:");
switch(c)
{
case 1:
for(n=0;n<=N-1;n++)
{
wr[n]=1;
printf(" \n wr[%d]=%f",n,wr[n]);
}
break;
case 2:
for(n=0;n<=N-1;n++)
{
wt[n]=1-(2*(float)n/(N-1));
printf("\n wt[%d]=%f",n,wt[n]);
}
break;
}}

RESULT: FIR filter design using CCS was implemented.

82
83
84
85
EXPERIMENT NO: 4

DATE:
4. INFINITE IMPULSE RESPONSE FILTERS

AIM :To design and implement IIR (LPF/HPF)filters.

EQUIPMENTS:
Operating System Windows XP
Constructor - Simulator
Software - CCStudio 3.1

THEORY:
The IIR filter can realize both the poles and zeroes of a system because it has arational
transfer function, described by polynomials in z in both the numerator andthe
denominator:

The difference equation for such a system is described by the following:

M and N are order of the two polynomials,bk and ak are the filter coefficients. These
filter coefficients are generated using FDS (Filter Design software or Digital Filter design
package). IIR filters can be expanded as infinite impulse response filters. In designing IIR
filters, cutoff frequencies of the filters should be mentioned. The order of the filtercan be

86
estimated using butter worth polynomial. Thats why the filters are named asbutter worth
filters. Filter coefficients can be found and the response can be plotted.
The IIR project is build and all the necessary files are added. The project is build and
loaded into the processor. The view graph is selected and the starting address is given as
H, with a logarithmic scale to view the graph.

PROGRAM:
//iirfilters
#include<stdio.h>
#include<math.h>
inti,w,wc,c,N;
float H[100];
floatmul(float, int);
void main()
{
printf("\n enter order of filter ");
scanf("%d",&N);
printf("\n enter the cutoff freq ");
scanf("%d",&wc);
printf("\n enter the choice for IIR filter 1. LPF 2.HPF ");
scanf("%d",&c);
switch(c)
{
case 1:
for(w=0;w<100;w++)
{
H[w]=1/sqrt(1+mul((w/(float)wc),2*N));
printf("H[%d]=%f\n",w,H[w]);
}
break;
case 2:

87
for(w=0;w<=100;w++)
{
H[w]=1/sqrt(1+mul((float)wc/w,2*N));
printf("H[%d]=%f\n",w,H[w]);
}
break;
}}
floatmul(float a,int x)
{
for(i=0;i<x-1;i++)
a*=a;
return(a);
}

RESULT:IIR filters using CCS was implememted.

88
89
90

Vous aimerez peut-être aussi