Sie sind auf Seite 1von 39

Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI.

Progm 1
GENERATION OF BASIC SIGNALS
AIM: To write a MATLAB program to generate various type of signals.

ALGORITHM:

1. Start the program.


2. Clear the command window using ‘clc’ function.
3. Create the array of time sequence by assigning values of ‘t’.
4. Get the input value using the ‘input’ function for generating
various sequences.
5. Provide matrix values by giving zero and ones values in
‘y’.
6. Using ‘subplot’ function plot the graph and use ‘stem’ to
obtain discrete sequence.
7. Label in the X and Y axis using ‘label’ function.
8. End the program.

PROGRAM:

clc;
clear all;
close all;

%Generation of cosine sequence


t1=0:.01:pi;
y1=cos(2*pi*t1);
figure(1);
subplot(3,2,1);
plot(t1,y1);
ylabel('Amplitude---->');
xlabel('(a)n---->');

%Generation of sine sequence


y2=sin(2*pi*t1);
subplot(3,2,2);
plot(t1,y2);
ylabel('Amplitude---->');
xlabel('(b)n---->');

%Generation of exponential sequence


n2=input('Enter the length of exponential sequence: ');
t3=0:n2;
a=input('Enter the value: ');
y3=exp(a*t3);
subplot(3,2,3);

Dr.A.I.T. Medical Electronics--2010 1


Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G

stem(t3,y3);
ylabel('Amplitude---->');
xlabel('(c)n---->');

%Generation of unit impulse signal


t4=-2:1:2;
y4=[zeros(1,2),ones(1,1),zeros(1,2)];
subplot(3,2,4);
stem(t4,y4);
ylabel('Amplitude---->');
xlabel('(d)n---->');

%Generation of unit step sequence


n5=input('Enter the N value for unit step sequence: ');
t5=0:1:n5-1;
y5=ones(1,n5);
subplot(3,2,5);
stem(t5,y5);
ylabel('Amplitude---->');
xlabel('(e)n---->');

%Generation of unit ramp sequence


n6=input('Enter the length of ramp sequence: ');
t6=0:n6;
subplot(3,2,6);
stem(t6,t6);
ylabel('Amplitude---->');
xlabel('(f)n---->');

OUTPUT:
Dr.A.I.T. Medical Electronics--2010 2
Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G

Enter the length of exponential sequence: 4


Enter the value: 4
Enter the N value for unit step sequence: 6
Enter the length of ramp sequence: 5

Dr.A.I.T. Medical Electronics--2010 3


Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G

Progm 2
VERIFICATION OF SAMPLING THEOREM
AIM: To write a MATLAB program to verify sampling theorem.

ALGORITHM:

1. Start the program.


2. Clear the command window using ‘clc’ function.
3. Create the array of time sequence by assigning values of ‘t’ using frequency.
4. Using different values of frequency the signals are generated.
5. Using ‘stem’ stem discrete sequence is obtained.
6. Label in the X and Y axis using ‘label’ function.
7. End the program.

PROGRAM:

clc;
clear all;
close all;

%critical sampling
f=1400;
t=0:1/f:13/f;
x=cos(2*pi*400*t)+cos(2*pi*700*t);
Xm=abs(fft(x));
n=0:length(x)-1;
figure(1)
stem(100*n,Xm),grid,zoom;
xlabel('frequency'); ylabel('magnitude');
title('criticle sampling');

%under sampling
f=700;
t=0:1/f:6/f;
x=cos(2*pi*400*t)+cos(2*pi*700*t);
Xm=abs(fft(x));
k=0:length(x)-1;
figure(2)
stem(100*k,Xm),grid,zoom;
xlabel('frequency'); ylabel('magnitude');
title('under sampling');

%over sampling
f=2000;
t=0:1/f:27/f;
x=cos(2*pi*400*t)+cos(2*pi*700*t);
Dr.A.I.T. Medical Electronics--2010 4
Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G

Xm=abs(fft(x));
k=0:length(x)-1;
figure(3)
stem(100*k,Xm),grid,zoom;
xlabel('frequency'); ylabel('magnitude');
title('over sampling');

OUTPUT:

Dr.A.I.T. Medical Electronics--2010 5


Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G

Dr.A.I.T. Medical Electronics--2010 6


Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G

Progm 3
LINEAR CONVOLUTION OF TWO GIVEN
SEQUENCES

AIM: To write a MATLAB program to perform linear convolution.

ALGORITHM:

1. Start the program.


2. Clear the command window using ‘clc’ function.
3. Get the two signals x(n) and h(n) using ‘input’ function.
4. The signal is convolved using ‘conv’ function and is denoted as y(n), given by
the formula
y(n) = x(n) * h(n).
5. Plot them using ‘stem’ function.
6. End the program.

PROGRAM:

%linear convolution of two sequences


clc;
clear all;
close all;

x=input('Enter the first sequence : ');


h=input('Enter the second sequence : ');
y=conv(x,h);
figure;
subplot(2,2,1);
stem(x);
ylabel('Amplitude---->');
xlabel('time---->');
title('x(n)');
subplot(2,2,2);

stem(h);
ylabel('Amplitude---->');
xlabel('time---->');
title('h(n)');
subplot(2,2,3);

stem(y);
ylabel('Amplitude---->');
xlabel('time---->');
title('y(n)');
Dr.A.I.T. Medical Electronics--2010 7
Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G

disp('The resultant signal is:');y

z=deconv(y,h);
subplot(2,2,4);
stem(z);
ylabel('Amplitude---->');
xlabel('time---->');
title('z(n)');
disp('The deconvoluted signal is:');z

OUTPUT:

Enter the first sequence: [1 2 3 4 5]


Enter the second sequence: [1 1 -2]
The resultant signal is:

y=

1 3 3 3 3 -3 -10

The deconvoluted signal is:

z=

1 2 3 4 5

Dr.A.I.T. Medical Electronics--2010 8


Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G

Progm 4

CIRCULAR CONVOLUTION OF TWO GIVEN


SEQUENCES
AIM: To write a MATLAB program to perform circular convolution.

ALGORITHM:

1. Start the program.


2. Clear the command window using ‘clc’ function.
3. Get the two signals x(n) and h(n) using ‘input’ function.
4. The convoluted signal is denoted as y(n) and given by the
formula:

y(n) = x(n) N h(n)

5. Plot them using ‘stem’ function.


6. End the program.

PROGRAM:

%circular convolution of two sequences


clc;
clear all;
close all;

g=input('Enter the first sequence: ');


h=input('Enter the second sequence: ');
N1=length(g);
N2=length(h);
N=max(N1,N2);
N3=N1-N2;
%loop for generating equal length
if(N3>=0)
h=[h,zeros(1,N3)];
else
g=[g,zeros(1,-N3)];
end
%computation of circular convolution
for n=1:N
y(n)=0;
for i=1:N
j=n-i+1;
if(j<=0)
Dr.A.I.T. Medical Electronics--2010 9
Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G

j=N+j;
end

y(n)=y(n)+g(i)*h(j);
end
end
subplot(3,2,1);
stem(g);
ylabel('Amplitude---->');
xlabel('time---->');
title(‘I signal’);
subplot(3,2,2);
stem(h);
ylabel('Amplitude---->');
xlabel('time---->');
title(`II signal’);
subplot(3,2,3);
stem(y);
ylabel('Amplitude---->');
xlabel('timen---->');
title('circular conv signal');
disp('The resultant signal is; ');y

OUTPUT:

Enter the first sequence: [1 2 3 4 5]


Enter the second sequence: [5 4 3 2 1]
The resultant signal is;
y=
45 40 40 45 55

Dr.A.I.T. Medical Electronics--2010 10


Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G

Enter the first sequence: [1 2]


Enter the second sequence: [2 3 4]
The resultant signal is:
y=
10 7 10

PROGRAM:
x1=input('Enter the first seq');
x2=input('Enter the sec seq');
l1=length(x1);
l2=length(x2);
N=max(l1,l2);
a=fft(x1,N)
b=fft(x2,N)
c=a.*b
y=ifft(c,N);
disp('CIRCULAR CONVOLUTION');
y
disp([]);
pause
n=0:1:N-1;
stem(n,y);
xlabel('Time index n');
Dr.A.I.T. Medical Electronics--2010 11
Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G

ylabel('Amplitude');
title('CIRCULAR CONVOLUTION');

Progm 5

CROSS & AUTO CORRELATION


AIM: To write a MATLAB program to perform circular convolution.

ALGORITHM:

1. Start the program.


2. Clear the command window using ‘clc’ function.
3. Define the two signals x(n) and h(n).
4. The convoluted signal is denoted as y(n) and given by the
formula:

y(n) = x(n) N
h(n)

5. Plot them using ‘stem’ function.


6. End the program.

PROGRAM:

%cross correlation
x=[5,1,3];
h=[1,2,3];
b1=xcorr(x,h);
y1=abs(b1);
disp(y1)
subplot(1,2,1);
stem(y1,'r');
ylabel('Amplitude');
xlabel('Time');
title('Cross Correlation');

% auto correlation
b2=xcorr(x,x);
y2=abs(b2);
disp(y2)
subplot(1,2,2);
stem(y2);
ylabel('Amplitude');
xlabel('Time');
title('Auto Correlation');

Dr.A.I.T. Medical Electronics--2010 12


Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G

OUTPUT:

Dr.A.I.T. Medical Electronics--2010 13


Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G

Progm 6

LINEAR AND CIRCULAR CONVOLUTION USING


FFT ALGORITHM
AIM: To write a MATLAB program to perform linear and circular convolution using fft
algorithm.

ALGORITHM:

1. Start the program.


2. Clear the command window using ‘clc’ function.
3. Get the two signals x1(n) and x2(n) using ‘input’ function.
4. The linear and circular convoluted signal is denoted as ylin(n) and ycir(n)
respectively.
ylin(n) = x(n) * h(n).

ycir(n) = x(n) N h(n).

5. The linear and circular convoluted signal using fft algorithm is calculated
6. Plot them using ‘stem’ function.
7. End the program.

PROGRAM:

% convolution of two given sequences (linear, circular)


clc;
clear all;
close all;

disp(' convolution of sequences x1(n) and x2(n)');

x1=input ('enter the first sequences x1(n):');


x2=input ('enter the second sequences x2(n):');

%linear convolution using fft() and ifft()


N=length(x1)+ length(x2)-1;
X1=fft(x1,N);
X2=fft(x2,N);
Y1=X1.*X2;
ylin=ifft(Y1);

disp('the linear - convolution of x1(n) and x2(n) using fft()')


Dr.A.I.T. Medical Electronics--2010 14
Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G

disp('and ifft() yeilds the result:');


disp(ylin);

%circular convolution
P=max(length(x1),length(x2));
X1=fft(x1,P);
X2=fft(x2,P);
Yc=X1.*X2;
Ycir=ifft(Yc);
disp('the circular convolution of x1(n) and x2(n) using fft()')
disp('and ifft() yeilds the result:');
disp(Ycir);

OUTPUT:

convolution of sequences x1(n) and x2(n)

enter the first sequences x1(n):[1 2 3 4]


enter the second sequences x2(n):[ 5 6 8 3]
the linear convolution of x1(n) and x2(n) using fft()
and ifft() yeilds the result:
5.0000 16.0000 35.0000 57.0000 54.0000 41.0000 12.0000

the circular convolution of x1(n) and x2(n) using fft()


and ifft() yeilds the result:
59 57 47 57

Dr.A.I.T. Medical Electronics--2010 15


Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G

Progm 7

SHIFTING, FLODING, TIME SCALING AND


MULTIPLICATION ON SIGNALS
AIM: To write a MATLAB program to perform various operation on the signals

ALGORITHM:

1. Start the program.


2. Clear the command window using ‘clc’ function.
3. Get the two signals x1(n) and x2(n) using ‘input’ function.
4. The linear convoluted signal is denoted as ylin1(n) and given by the
formula:
y(n) = x(n) * h(n).

5. The linear and circular convoluted signal using fft algorithm is calculated and is
denoted as ylin2 and yc respectively.
6. Plot them using ‘stem’ function.
7. End the program.

PROGRAM: OUTPUT:

(a) Folding of a sequence

clc; ORIGINAL SIGNAL FOLDED SIGNAL

clear all; 8 8

close all; 7 7

6 6
%folded signal
x=[2,5,6,7,8,3]; 5 5

n=0:5; 4 4

subplot(1,2,1); 3 3
stem(n,x);
title('ORIGINAL SIGNAL'); 2 2

subplot(1,2,2); 1 1

stem(-n,x);
0 0
title('FOLDED SIGNAL'); 0 2 4 6 -6 -4 -2 0

Dr.A.I.T. Medical Electronics--2010 16


Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G

(b) Shifting of a sequence: X[n+k],X[n-k],X[-n+k], X[-n-k]

x=input('Enter the sequence');


k=input('Enter the shifting value');
n=length(x);
i=[-k:n-k-1];
subplot(2, 2,1);
stem(i,x);
title('X[n+k]');
i=[k:n+k-1];
subplot(2,2,2);
stem(i,x);
title('X[n-k]');
i=[-n-k+1:-k];
y=fliplr(x)
subplot(2,2,3);
stem(i,y);
title('X[-n+k]');
i=[-n+k+1:k];
y=fliplr(x)
subplot(2,2,4);
stem(i,y);
title('X[-n-k]');

OUTPUT:
Enter the sequence: [1,2,3,4]
Enter the shifting value: 2

X[n+k] X[n-k]
4 4

3 3

2 2

1 1

0 0
-2 -1 0 1 2 3 4 5

X[-n+k] X[-n-k]
4 4

3 3

2 2

1 1

0 0
Dr.A.I.T. -5 -4 -3 Medical
-2 Electronics-
-1 -2010
0 1 2 17
Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G

Progm 7

COMPUTATION AND VERIFICATION OF FFT

AIM: To write a matlab program to perform DFT of a given


sequence using FFT.

ALGORITHM:

1. Start the program.


2. Clear the command window using ‘clc’ function.
3. Get the two signals x(n) and length of DFT to be performed
using ‘input’ function.
4. Calculate the DFT using given formula
y=fft(x,n).
5. Plot them using ‘stem’ function.
6. End the program.

PROGRAM:

%fft of two sequences


clc;
clear all;
close all;

x=input('Enter the sequence : ');


n=input('Enter the n value : ');
y=fft(x,n);
figure;
subplot(3,2,1);
stem(x);
ylabel('Amplitude---->');
xlabel('(a)n---->');
subplot(3,2,2);
stem(real(y));
ylabel('Amplitude---->');
xlabel('(b)n---->');
subplot(3,2,3);
stem(imag(y));
ylabel('Amplitude---->');
xlabel('(c)n---->');
disp('The resultant signal is:');y
Dr.A.I.T. Medical Electronics--2010 18
Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G

OUTPUT:

Enter the sequence : [.5 0 .5 0 .5 0 .5 0]


Enter the n value : 8
The resultant signal is:
y=
2 0 0 0 2 0 0 0

Enter the sequence : [1 2 3 4 4 3 2 1]


Enter the n value : 8
The resultant signal is:
y=
Columns 1 through 6
20.0000 -5.8284 - 2.4142i 0 -0.1716 - 0.4142i 0 -0.1716 +
0.4142i
Columns 7 through 8
0 -5.8284 + 2.4142i

Dr.A.I.T. Medical Electronics--2010 19


Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G

ALGORITHM:

1. Start the program.


2. Clear the command window using ‘clc’ function.
3. Get the two signals x(n) and length of IDFT to be performed
using ‘input’ function.
4. Calculate the IDFT using given formula
y=ifft(x,n).
5. Plot them using ‘stem’ function.
6. End the program.

PROGRAM:

%ifft of two sequences


clc; clear all; close all;

x=input('Enter the sequence : ');


n=input('Enter the n value : ');
y=ifft(x,n);
figure;
subplot(3,2,1);
stem(real(x));
ylabel('Amplitude---->');
xlabel('(a)n---->');
subplot(3,2,2);
stem(imag(x));
ylabel('Amplitude---->');
xlabel('(b)n---->');
subplot(3,2,3);
stem(y);
Dr.A.I.T. Medical Electronics--2010 20
Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G

ylabel('Amplitude---->');
xlabel('(c)n---->');
disp('The resultant signal is:');y

OUTPUT:

Enter the sequence: [20 -5.8284-2.4142j 0 -.1716-.4142j 0 -.1716+.4142j 0


-5.8284+2.4142j]
Enter the n value : 8
The resultant signal is:
y=
1.0000 2.0000 3.0000 4.0000 4.0000 3.0000 2.0000 1.0000

Enter the sequence : [2 0 0 0 2 0 0 0]


Enter the n value : 8
The resultant signal is:
y=
0.5000 0 0.5000 0 0.5000 0 0.5000 0
Dr.A.I.T. Medical Electronics--2010 21
Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G

Progm 8

IMPULSE & FREQUENCY RESPONSE OF A


TRANSFER FUNCTION
AIM: To write a matlab program to obtain impulse and frequency response of a
given transfer function.

ALGORITHM:

1. Start the program.


2. Clear the command window using ‘clc’ function.
3. Get the numerator and denominator co-efficient of the given transfer function.
4. Calculate the impulse response using ‘impz’ function.
5. Calculate the frequency response using ‘freqz’ function.
6. Plot them using ‘stem’ function.
7. End the program.

PROGRAM: (A)

clc; clear all; close all;

num=[2,-3.4,1.5];
den=[1,-1.6,.8];
[h,t]=impz(num,den);
figure(1);
subplot(1,2,1);
stem(t,h);

Dr.A.I.T. Medical Electronics--2010 22


Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G

title('Impulse response');
ns=ones(1,20);
y=filter(num,den,ns);
subplot(1,2,2);
stem(y);
title('Step response');
figure(2);
freqz(num,den);
title('Frequency response');

OUTPUT:
Impulse response Step response
2 2

1.5
1.5

1
1

0.5

0.5
0
Frequency response
20
0
-0.5
Magnitude (dB)

10
-1 -0.5
0 50 100 0 5 10 15 20
0

-10
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized Frequency ( rad/sample)

100
Phase (degrees)

50

Dr.A.I.T. Medical Electronics--2010 23


-50
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized Frequency ( rad/sample)
Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G

(B) y(n)-ay(n-1)=bx(n) where a=0.9 b=0.1

a = [1 -0.9];
b = 0.1;
n = input('Enter number of points for impulse response');
w = input('Enter number of points for frequency response:');
figure(1);
[h,t] = impz(b,a,n);
stem(t,h);
title('Impulse response of given system');
figure(2);
freqz(b,a,w);
title('Frequency response of givenImpulse
system');
response of given system
0.1

0.09
OUTPUT:
0.08
Enter number of points for impulse response10
Enter
0.07 number of points for frequency response:10
0.06

0.05

0.04

0.03

0.02

0.01
Dr.A.I.T. Medical Electronics--2010 24
0
0 1 2 3 4 5 6 7 8 9
Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G

Frequency response of given system


0
Magnitude (dB)

-10

-20

-30
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized Frequency ( rad/sample)

0
Phase (degrees)

-20

-40

-60

-80
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized Frequency ( rad/sample)

Dr.A.I.T. Medical Electronics--2010 25


Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G

(C) y(n)+0.6y(n-1)=3x(n)+x(n-1);

a = [1 0.6];
b = [3 1];
n = input('Enter number of points for impulse response:');
w = input('Enter number of points for frequency response:');
figure(1);
[h,t] = impz(b,a,n,5);
stem(t,h);
title('Impulse response of given system');
figure(2);
freqz(b,a,w);
title('Frequency response of given system');

OUTPUT:

Enter number of points for impulse response:10


Enter number of points for frequency response:10

Impulse response of given system


3

2.5
Frequency response of given system
14
2
Magnitude (dB)

12
1.5

10
1

8
0.5

6
0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized Frequency ( rad/sample)
-0.5
20
-1
Phase (degrees)

15 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8

10

Dr.A.I.T.0 Medical Electronics--2010 26


0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized Frequency ( rad/sample)
Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G

Progm 7

DESIGN OF FIR FILTER USING HAMMING


WINDOW
AIM: To write a matlab program to design a FIR filter using hamming window and to
verify the output.

ALGORITHM:

1. Start the program.


2. Clear the command window using ‘clc’ function.
3. Get the pass band and stop band ripples.
4. Get the pass band and stop band frequencies.
5. Get the sampling frequency.
6. Calculate the order of filter.
7. Calculate the transfer function of the filter using the co-
efficients.
8. Plot magnitude and phase responses.
9. End the program.

PROGRAM:

Dr.A.I.T. Medical Electronics--2010 27


Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G

%hamming window computation


clc;
close all;
clear all;
rp=input('Enter the passband ripple: ');
rs=input('Enter the stopband ripple: ');
fp=input('Enter the passband frequency: ');
fs=input('Enter the stopband frequency: ');
f=input('Enter the sampling frequency: ');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n=ceil(num/dem);
n1=n+1;
if(rem(n,2)~=0)
n1=n;
n=n-1;
end
disp('The order is:');n

y=hamming(n1);

%lowpass filter
b=fir1(n,wp,y);
[h,om]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,1);
plot(om/pi,m);
ylabel('Gain in dB---->');
xlabel('Frequency in rad/sec---->');

%highpass filter
b=fir1(n,wp,'high',y);
[h,om]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,2);
plot(om/pi,m);
ylabel('Gain in dB---->');
xlabel('Frequency in rad/sec---->');
%bandpass filter
wn=[wp ws];
b=fir1(n,wn,y);
[h,om]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,3);
plot(om/pi,m);
ylabel('Gain in dB---->');
Dr.A.I.T. Medical Electronics--2010 28
Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G

xlabel('Frequency in rad/sec---->');

%bandstop filter
b=fir1(n,wn,'stop',y);
[h,om]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,4);
plot(om/pi,m);
ylabel('Gain in dB---->');
xlabel('Frequency in rad/sec---->');

OUTPUT:

Enter the passband ripple: .05


Enter the stopband ripple: .03
Enter the passband frequency: 1300
Enter the stopband frequency: 1600
Enter the sampling frequency: 7400
The order is:

n=

26

Dr.A.I.T. Medical Electronics--2010 29


Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G

DESIGN OF FIR FILTER USING KAISER WINDOW


AIM: To write a matlab program to design a FIR filter using Kaiser window and to
verify the output.

ALGORITHM:

1. Start the program.


2. Clear the command window using ‘clc’ function.
3. Get the pass band and stop band ripples.
4. Get the pass band and stop band frequencies.
5. Get the sampling frequency.
Dr.A.I.T. Medical Electronics--2010 30
Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G

6. Calculate the order of filter.


7. Calculate the transfer function of the filter using the co-
efficients.
8. Plot magnitude and phase responses.
9. End the program.

PROGRAM:

%kaiser window computation

clc;
close all;
clear all;
rp=input('Enter the passband ripple: ');
rs=input('Enter the stopband ripple: ');
fp=input('Enter the passband frequency: ');
fs=input('Enter the stopband frequency: ');
f=input('Enter the sampling frequency: ');
beta=input('Enter the beta value: ');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n=ceil(num/dem);
n1=n+1;
if(rem(n,2)~=0)
n1=n;
n=n-1;
end
disp('The order is:');n

y=kaiser(n1,beta);

%lowpass filter
b=fir1(n,wp,y);
[h,om]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,1);
plot(om/pi,m);
ylabel('Gain in dB---->');
xlabel('Frequency in rad/sec---->');

%highpass filter
b=fir1(n,wp,'high',y);
[h,om]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,2);
plot(om/pi,m);
Dr.A.I.T. Medical Electronics--2010 31
Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G

ylabel('Gain in dB---->');
xlabel('Frequency in rad/sec---->');

%bandpass filter
wn=[wp ws];
b=fir1(n,wn,y);
[h,om]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,3);
plot(om/pi,m);
ylabel('Gain in dB---->');
xlabel('Frequency in rad/sec---->');

%bandstop filter
b=fir1(n,wn,'stop',y);
[h,om]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,4);
plot(om/pi,m);
ylabel('Gain in dB---->');
xlabel('Frequency in rad/sec---->');

OUTPUT:

Enter the passband ripple: .05


Enter the stopband ripple: .03
Enter the passband frequency: 1300
Enter the stopband frequency: 1600
Enter the sampling frequency: 7400
Enter the beta value: 7
The order is:

n=

26

Dr.A.I.T. Medical Electronics--2010 32


Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G

.    REALIZATION OF IIR FILTERS


AIM: To write a matlab program to design a IIR filters.

ALGORITHM:

1. Start the program.


2. Get the cut off frequency and sampling frequency.
3. Get the order of the filter.
4. Calculate the transfer function of the filter using the co-efficient.
5. Plot magnitude and phase responses.
6. End the program.

PROGRAM:

(a) BUTTERWORTH LPF


Dr.A.I.T. Medical Electronics--2010 33
Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G

fc=input('Enter the cut off freq');


fs=input('Enter the sampling freq');
n=input('Enter the order of the filter');
Wn=fc*(2/fs);
[b,a]=butter(n,Wn);
freqz(b,a,128,fs);
xlabel('Frequency');
ylabel('Gain in dB');
title('Butterworth Low Pass Filter');

OUTPUT:

Enter the cut off freq: 300


Enter the sampling freq: 1000
Enter the order of the filter: 3

Butterworth Low Pass Filter


0
G a in in d B

-50

-100

-150
0 50 100 150 200 250 300 350 400 450 500
Frequency

0
P h a s e (d e g re e s )

-100

-200

-300
0 50 100 150 200 250 300 350 400 450 500
Frequency (Hz)

Dr.A.I.T. Medical Electronics--2010 34


Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G

(b) CHEBYSHEV LPF

fc=input('Enter the cut off freq');


fs=input('Enter the sampling freq');
n=input('Enter the order of the filter');
r=input('Enter the ripple factor');
Wn=fc*(2/fs);
[b,a]=cheby1(n,r,Wn);
freqz(b,a,128,fs);
xlabel('Frequency');
ylabel('Gain in dB');
title('Chebyshev Low Pass Filter');

OUTPUT:

Enter the cut off freq: 300


Enter the sampling freq: 1000
Enter the order of the filter: 5
Enter the ripple factor: 17

Chebyshev Low Pass Filter


0

-100
Gain in dB

-200

-300
0 50 100 150 200 250 300 350 400 450 500
Frequency

-100
Phase (degrees)

-200

-300

-400

-500
0 50 100 150 200 250 300 350 400 450 500
Frequency (Hz)
Dr.A.I.T. Medical Electronics--2010 35
Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G

(c) CHEBYSHEV HPF:

fc=input('Enter the cut off freq');


fs=input('Enter the sampling freq');
n=input('Enter the order of the filter');
r=input('Enter the ripple factor');
Wn=fc*(2/fs);
[b,a]=cheby1(n,r,Wn,'high');
freqz(b,a,128,fs);
xlabel('Frequency');
ylabel('Gain in dB');
title('Chebyshev High Pass Filter');

OUTPUT:

Enter the cut off freq: 300


Enter the sampling freq: 1000
Enter the order of the filter: 5
Enter the ripple factor: 17

Chebyshev High Pass Filter


0

-100
Gain in dB

-200

-300
0 50 100 150 200 250 300 350 400 450 500
Frequency

100

0
Phase (degrees)

-100

-200

-300

-400
0 50 100 150 200 250 300 350 400 450 500
Frequency (Hz)

Dr.A.I.T. Medical Electronics--2010 36


Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G

(d) CHEBYSHEV BPF

fs=input('Enter the sampling freq');


fc1=input('Enter the lower cut off freq');
fc2=input('Enter the upper cut off freq');
n=input('Enter the order of the filter');
r=input('Enter the ripple factor');
Wn1=fc1*(2/fs);
Wn2=fc2*(2/fs);
Wn=[Wn1,Wn2];
[b,a]=cheby1(n,r,Wn);
freqz(b,a,128,fs);
xlabel('Frequency');
ylabel('Gain in dB');
title('Chebyshev Band Pass Filter');

OUTPUT:
Enter the sampling freq2000
Enter the lower cut off freq300
Enter the upper cut off freq500
Enter the order of the filter3
Enter the ripple factor17

Chebyshev Band Pass Filter


0

-50
Gain in dB

-100

-150

-200
0 100 200 300 400 500 600 700 800 900 1000
Frequency

0
Phase (degrees)

-200

-400

-600

-800
0 100 200 300 400 500 600 700 800 900 1000
Frequency (Hz)

Dr.A.I.T. Medical Electronics--2010 37


Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G

(e) Butterworth HPF

rp=input('enter the pass band ripple');


rs=input('enter the stop band ripple');
fp=input('enter the pass band frequency');
fs=input('enter the stop band frequency');
f=input('enter the sampling frequency');
wp=(2*fp)/f;
ws=(2*fs)/f;

[n,wn]=BUTTORD(wp,ws,rp,rs);
[b,a]=BUTTER(n,wn,'high');
w=0:.01:pi;
[h,w]=FREQZ(b,a,w,'whole');
m=20*log10(abs(h));
an=angle(h);

subplot(2,1,1),plot(w/pi,m);
grid
xlabel('normalised frequency');
ylabel('gain in db');
title('magnitude response');

subplot(2,1,2), plot(w/pi,an);
grid;
xlabel('normalised frequency');
ylabel('phase in radian');
title('phase response');

OUTPUT:

Dr.A.I.T. Medical Electronics--2010 38


Digital Signal Processing Lab Manual Prof. SHIVASHANKAR and JAYANTHI. G

Dr.A.I.T. Medical Electronics--2010 39

Das könnte Ihnen auch gefallen