Matlab

  • April 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Matlab as PDF for free.

More details

  • Words: 3,386
  • Pages: 66
GENERATION OF BASIC SIGNALS

Expt.No.1 Date: 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.

1

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); stem(t3,y3); ylabel('Amplitude---->'); xlabel('(c)n---->');

2

%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---->');

3

OUTPUT 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

4

RESULT Thus the MATLAB program for generation of various types of signals was written and the waveforms were obtained.

5

LINEAR CONVOLUTION OF TWO GIVEN SEQUENCES

Expt No.2 Date:

AIM To write a MATLAB program to perform linear convolution.

ALGORITHM

1. 2. 3. 4.

Start the program. Clear the command window using ‘clc’ function. Get the two signals x(n) and h(n) using ‘input’ function. 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.

6

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(3,2,1); stem(x); ylabel('Amplitude---->'); xlabel('(a)n---->'); subplot(3,2,2); stem(h); ylabel('Amplitude---->'); xlabel('(b)n---->'); subplot(3,2,3); stem(y); ylabel('Amplitude---->'); xlabel('(c)n---->'); disp('The resultant signal is:');y

7

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

8

RESULT Thus the matlab program to perform linear convolution was written and the output was obtained.

9

CIRCULAR CONVOLUTION OF TWO GIVEN SEQUENCES

Expt No.3 Date:

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.

10

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) j=N+j; end y(n)=y(n)+g(i)*h(j); end end subplot(3,2,1); stem(g); ylabel('Amplitude---->'); xlabel('(a)n---->'); subplot(3,2,2); stem(h); ylabel('Amplitude---->'); xlabel('(b)n---->'); subplot(3,2,3); stem(y); ylabel('Amplitude---->'); xlabel('(c)n---->'); disp('The resultant signal is; ');y 11

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

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

12

RESULT Thus the matlab program to perform circular convolution was written and the output was obtained.

13

DFT OF A GIVEN SEQUENCE USING FFT Expt No.4 Date:

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.

14

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

15

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 Columns 7 through 8 0 -5.8284 + 2.4142i

16

-0.1716 - 0.4142i

0

RESULT Thus the matlab program to perform DFT of a given sequence using FFT was written and the output was obtained.

17

IDFT OF A GIVEN SEQUENCE USING IFFT Expt No.5 Date:

AIM To write a matlab program to perform IDFT of a given sequence using IFFT.

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.

18

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); ylabel('Amplitude---->'); xlabel('(c)n---->'); disp('The resultant signal is:');y

19

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

20

0

0.5000

0

RESULT Thus the matlab program to perform IDFT of a given sequence using IFFT was written and the output was obtained.

DESIGN OF BUTTERWORTH LOW PASS IIR FILTER 21

Expt No.6 Date:

AIM To write a matlab program to design a Butterworth lowpass filter 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 coefficients. 8. Plot magnitude and phase responses. 9. End the program.

PROGRAM clc; close all; 22

clear all; wp=input('Enter the passband frequency: '); ws=input('Enter the stopband frequency: '); rp=input('Enter the passband ripple : '); rs=input('Enter the passband 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:.01:pi; [h,omega]=freqz(b,a,w); gain=20*log10(abs(h)); subplot(2,2,1); plot(omega/pi,gain); grid; xlabel('\omega/pi,gain'); ylabel('Gain in db---->'); title('IIR Butterworth LPF: gain'); subplot(2,2,2); an=angle(h); 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

OUTPUT Enter the passband frequency: 20 23

Enter the stopband frequency: 30 Enter the passband ripple : 2 Enter the passband ripple : 10 Enter the sampling frequency: 100 Order of the filter is: N= 3

24

RESULT Thus the matlab program to design a Butterworth lowpass filter was written and the output was obtained.

DESIGN OF BUTTERWORTH HIGH PASS IIR FILTER 25

Expt No.7 Date:

AIM To write a matlab program to design a Butterworth highpass filter 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 coefficients. 8. Plot magnitude and phase responses. 9. End the program.

PROGRAM clc; close all; clear all; 26

wp=input('Enter the passband frequency: '); ws=input('Enter the stopband frequency: '); rp=input('Enter the passband ripple : '); rs=input('Enter the passband 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,'high'); w=0:.01:pi; [h,omega]=freqz(b,a,w); gain=20*log10(abs(h)); subplot(2,2,1); plot(omega/pi,gain); grid; xlabel('\omega/pi,gain'); ylabel('Gain in db---->'); title('IIR Butterworth HPF: gain'); subplot(2,2,2); an=angle(h); 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

OUTPUT Enter the passband frequency: 30 Enter the stopband frequency: 20 27

Enter the passband ripple : 2 Enter the passband ripple : 10 Enter the sampling frequency: 100 Order of the filter is: N= 3

28

RESULT Thus the matlab program to design a Butterworth highpass filter was written and the output was obtained.

DESIGN OF BUTTERWORTH BAND PASS IIR FILTER Expt No.8 29

Date:

AIM To write a matlab program to design a Butterworth bandpass filter 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 coefficients. 8. Plot magnitude and phase responses. 9. End the program.

PROGRAM clc; close all; clear all; wp=input('Enter the passband frequency: '); 30

ws=input('Enter the stopband frequency: '); rp=input('Enter the passband ripple : '); rs=input('Enter the passband 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:.01:pi; [h,omega]=freqz(b,a,w); gain=20*log10(abs(h)); subplot(2,2,1); plot(omega/pi,gain); grid; xlabel('\omega/pi,gain'); ylabel('Gain in db---->'); title('IIR Butterworth BPF: gain'); subplot(2,2,2); an=angle(h); 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

OUTPUT Enter the passband frequency: [40 65] Enter the stopband frequency: [30 75] Enter the passband ripple : 1 Enter the passband ripple : 40 31

Enter the sampling frequency: 200 Order of the filter is: N= 8

32

RESULT Thus the matlab program to design a Butterworth bandpass filter was written and the output was obtained.

DESIGN OF BUTTERWORTH BAND STOP IIR FILTER Expt No.9 33

Date:

AIM To write a matlab program to design a Butterworth bandstop filter 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 coefficients. 8. Plot magnitude and phase responses. 9. End the program.

PROGRAM clc; close all; clear all; wp=input('Enter the passband frequency: '); ws=input('Enter the stopband frequency: '); 34

rp=input('Enter the passband ripple : '); rs=input('Enter the passband 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:.01:pi; [h,omega]=freqz(b,a,w); gain=20*log10(abs(h)); subplot(2,2,1); plot(omega/pi,gain); grid; xlabel('\omega/pi,gain'); ylabel('Gain in db---->'); title('IIR Butterworth BSF: gain'); subplot(2,2,2); an=angle(h); 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

OUTPUT Enter the passband frequency: [30 75] Enter the stopband frequency: [45 65] Enter the passband ripple : 1 Enter the passband ripple : 40 35

Enter the sampling frequency: 200 Order of the filter is: N= 7

36

RESULT Thus the matlab program to design a Butterworth bandstop filter was written and the output was obtained.

DESIGN OF CHEBYSHEV-I LOW PASS IIR FILTER Expt No.10

37

Date:

AIM To write a matlab program to design a chebyshev-I lowpass filter 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 coefficients. 8. Plot magnitude and phase responses. 9. End the program.

PROGRAM clc; close all; clear all; wp=input('Enter the passband frequency: '); 38

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:.01:pi; [h,omega]=freqz(b,a,w); gain=20*log10(abs(h)); subplot(2,2,1); plot(omega/pi,gain); grid; xlabel('\omega/pi,gain'); ylabel('Gain in db---->'); title('IIR Chebyshev-I LPF: gain'); subplot(2,2,2); an=angle(h); plot(omega/pi,an); grid; xlabel('\omega/pi,gain'); ylabel('Phase in radians---->'); title('IIR Chebyshev LPF: phase'); disp('Order of the filter is: ');N

OUTPUT Enter the passband frequency: 30 Enter the stopband frequency: 80 Enter the passband ripple : 20 Enter the stopband ripple : 300 Enter the sampling frequency: 200 Order of the filter is: 39

N= 14

40

RESULT Thus the matlab program to design a chbyshev-I lowpass filter was written and the output was obtained.

DESIGN OF CHEBYSHEV-II LOW PASS IIR FILTER Expt No.11

41

Date:

AIM To write a matlab program to design a chebyshev-II lowpass filter 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 coefficients. 8. Plot magnitude and phase responses. 9. End the program.

PROGRAM clc; close all; clear all; wp=input('Enter the passband frequency: '); ws=input('Enter the stopband frequency: '); 42

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:.01:pi; [h,omega]=freqz(b,a,w); gain=20*log10(abs(h)); subplot(2,2,1); plot(omega/pi,gain); grid; xlabel('\omega/pi,gain'); ylabel('Gain in db---->'); title('IIR Chebyshev LPF: gain'); subplot(2,2,2); an=angle(h); plot(omega/pi,an); grid; xlabel('\omega/pi,gain'); ylabel('Phase in radians---->'); title('IIR Chebyshev LPF: phase'); disp('Order of the filter is: ');N

OUTPUT Enter the passband frequency: 90 Enter the stopband frequency: 60 Enter the passband ripple : 100 Enter the passband ripple : 250 Enter the sampling frequency: 200 Order of the filter is: 43

N= 9

44

RESULT Thus the matlab program to design a chebyshev-II lowpass filter was written and the output was obtained.

DESIGN OF FIR FILTER USING RECTANGULAR WINDOW Expt No. 12 Date: 45

AIM To write a matlab program to design a FIR filter using rectangular 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 coefficients. 8. Plot magnitude and phase responses. 9. End the program.

PROGRAM %rectangular window computation clc; close all; clear all; rp=input('Enter the passband ripple: 46

');

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=rectwin(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---->'); 47

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: 48

n= 26

49

RESULT Thus the matlab program to design a FIR filter using rectangular window was written and the output was verified.

DESIGN OF FIR FILTER USING HAMMING WINDOW Expt No. 13 Date: 50

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 coefficients. 8. Plot magnitude and phase responses. 9. End the program.

PROGRAM %hamming window computation clc; close all; clear all; rp=input('Enter the passband ripple: 51

');

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---->'); 52

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: 53

n= 26

54

RESULT Thus the matlab program to design a FIR filter using hamming window was written and the output was verified.

DESIGN OF FIR FILTER USING KAISER WINDOW Expt No. 14 Date:

55

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. 6. Calculate the order of filter. 7. Calculate the transfer function of the filter using the coefficients. 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: 56

');

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); 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)); 57

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: 58

n= 26

59

RESULT Thus the matlab program to design a FIR filter using Kaiser window was written and the output was verified.

DESIGN OF IIR FILTER USING BILINEAR TRANSFORMATION Expt No. 15 Date: 60

AIM To write a matlab program to design an IIR filter using bilinear transformation technique and to verify the output.

ALGORITHM

1. Start the program. 2. Clear the command window using ‘clc’ function. 3. Get the input values of input poles and zeroes. 4. Get the input value of sampling interval. 5. Compute the [z,p] values using bilinear transformation technique. 6. Print the output. 7. End the program.

PROGRAM %bilinear transform clc; close all; clear all; 61

pin=input('Enter the poles: '); zin=input('Enter the zeros: '); t=input('Enter the sampling interval:'); [z,p]=bilinear(zin,pin,1/t)

OUTPUT Enter the poles: [1 3 2] Enter the zeros: 2 Enter the sampling interval:1

62

z= 0.1667

0.3333

0.1667

1.0000 -0.3333

0.0000

p=

RESULT Thus the matlab program for design of IIR filter using bilinear transformation was written and the output was verified.

DESIGN OF IIR FILTER USING IMPULSE INVARIANCE Expt No. 16 63

Date:

AIM To write a matlab program to design an IIR filter using impulse invariance technique and to verify the output.

ALGORITHM

1. Start the program. 2. Clear the command window using ‘clc’ function. 3. Get the input values of input poles and zeroes. 4. Get the input value of sampling interval. 5. Compute the [z,p] values using impulse invariance technique. 6. Print the output. 7. End the program.

PROGRAM

64

%impulse invariance clc; close all; clear all; pin=input('Enter the poles: '); zin=input('Enter the zeros: '); t=input('Enter the sampling interval:'); [z,p]=impinvar(zin,pin,1/t)

OUTPUT Enter the poles: [1 3 2] Enter the zeros: 2 65

Enter the sampling interval:1 z= 0

0.4651

p= 1.0000 -0.5032

0.0498

RESULT Thus the matlab program for design of IIR filter using impulse invariance was written and the output was verified.

66

Related Documents

Matlab
July 2020 24
Matlab
May 2020 31
Matlab
April 2020 36
Matlab
May 2020 39
Matlab
August 2019 56
Matlab
November 2019 32