0% found this document useful (0 votes)
58 views

Programs For Matlab1

The document describes various analog filter designs including: 1) Butterworth high pass, low pass, band pass, and stop filters with plots of the gain and phase responses. 2) Chebyshev type 1 high pass, low pass, band pass, and stop filters with plots of the gain and phase responses. 3) Chebyshev type 2 high pass, low pass, and band pass filters with plots of the gain and phase responses. The filters are designed using Butterworth and Chebyshev approximations and their frequency responses are analyzed. Plots of the gain and phase are provided for each filter type.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views

Programs For Matlab1

The document describes various analog filter designs including: 1) Butterworth high pass, low pass, band pass, and stop filters with plots of the gain and phase responses. 2) Chebyshev type 1 high pass, low pass, band pass, and stop filters with plots of the gain and phase responses. 3) Chebyshev type 2 high pass, low pass, and band pass filters with plots of the gain and phase responses. The filters are designed using Butterworth and Chebyshev approximations and their frequency responses are analyzed. Plots of the gain and phase are provided for each filter type.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

UNIT SAMPLE SEQUENCE REAL EXPONENTIAL SEQUENCE

n=-5:15; close all;


g=[zeros(1,5) 1 zeros(1,15)]; clear all;
h=[zeros(1,10) 1 zeros(1,10)]; clf;
subplot(2,1,1); n=0:35;
stem(n,g); a=1.2;
xlabel('time index'); k=0.2;
ylabel('amplitude'); x=k*a.^+n;
title('UNIT SAMPLE SEQUENCE'); stem(n,x);
axis([-5 15 0 1.2]); xlabel('time index');
subplot(2,1,2); ylabel('amplitude');
stem(n,h); title('REAL EXPONENTIAL SEQUENCE');
xlabel('time index');
ylabel('amplitude');
title('DELAYED UNIT SAMPLE SEQUENCE'); COMPLEX EXPONENTIAL SEQUENCE
axis([-5 15 0 1.2]); close all;
clear all;
UNIT STEP SEQUENCE clf;
n=-5:15; c=-(1/2)+(pi/6)*i;
i=[zeros(1,5) ones(1,6) zeros(1,10)]; k=2;
j=[zeros(1,10) ones(1,6) zeros(1,5)]; n=0:40;
subplot(2,1,1); x=k*exp(c*n);
stem(n,i); subplot(2,1,1);
xlabel('time index'); stem(n,real(x));
ylabel('amplitude'); xlabel('time index');
title('UNIT STEP SEQUENCE'); ylabel('real part');
axis([-5 15 0 1.2]); title('COMPLEX EXPONENTIAL SEQUENCE');
subplot(2,1,2); subplot(2,1,2);
stem(n,j); stem(n,imag(x));
xlabel('time index'); xlabel('time index');
ylabel('amplitude'); ylabel('imaginary part');
title('DELAYED UNIT STEP SEQUENCE');
axis([5 15 0 1.2]);
Analog butter worth high pass filter
SOME OF SINESOIDAL SIGNALS
ws=0.5;
n=0:1000; wp=0.875;
m1=0.4; rp=0.2;
m2=1; rs=40;
m3=2.5; [N,wn]=buttord(wp,ws,rp,rs,'s');
fh=0.1; [B,A]=butter(N,wn,'HIGH','s');
f1=0.01; w=0:0.01:pi;
xh=sin(2*pi*fh*n); [h1,om]=freqs(B,A,w);
xl=sin(2*pi*f1*n); m=20*log10(abs(h1));
y1=(1+m1*xl).*xh; an=angle(h1);
y2=(1+m2*xl).*xh; subplot(2,1,1);
y3=(1+m3*xl).*xh; plot(om/pi,m);
subplot(5,1,1); xlabel('(a) normalized frequency');
plot(n,xh,'m'); ylabel('gain in db');
xlabel('time'); title('butterworth high pass filter');
ylabel('amplitude'); grid;
title('carrier signal'); subplot(2,1,2);
grid; plot(om/pi,an);
subplot(5,1,2); xlabel('(b) normalized frequency');
plot(n,xl,'g'); ylabel('phase in radians');
xlabel('time'); grid;
ylabel('amplitude'); Analog butter worth LOW PASS filter
title('modulating signal'); wp=0.5;
grid; ws=0.875;
subplot(5,1,3); rp=0.2;
plot(n,y1,'h'); rs=40;
xlabel('time'); [N,wn]=buttord(wp,ws,rp,rs,'s');
ylabel('amplitude'); [B,A]=butter(N,wn,'LOW','s');
title('modulated signal'); w=0:0.01:pi;
grid; [h1,om]=freqs(B,A,w);
subplot(5,1,4); m=20*log10(abs(h1));
plot(n,y2,'b'); an=angle(h1);
xlabel('time'); subplot(2,1,1);
ylabel('amplitude'); plot(om/pi,m);
title('critical modulated signal'); xlabel('(a) normalized frequency');
grid; ylabel('gain in db');
subplot(5,1,5); title('butterworth LOW pass filter');
plot(n,y3,'k'); grid;
xlabel('time'); subplot(2,1,2);
ylabel('amplitude'); plot(om/pi,an);
title('over'); xlabel('(b) normalized frequency');
grid; ylabel('phase in radians');
grid;
Analog butter worth BAND PASS filter ANALOG CHEBYSHEV TYPE1 HIGHPASS FILTER
wp=[0.3 0.5]; ws=0.24;
ws=[0.1 0.8]; wp=0.35;
rp=0.2; rp=0.29;
rs=40; rs=29;
[N,wn]=buttord(wp,ws,rp,rs,'s'); [N,wn]=cheb1ord(wp,ws,rp,rs,'s');
[B,A]=butter(N,wn,'BANDPASS','s'); [B,A]=cheby1(N,rp,wn,'HIGH','s');
w=0:0.01:pi; w=0:0.01:pi;
[h1,om]=freqs(B,A,w); [h1,om]=freqs(B,A,w);
m=20*log10(abs(h1)); m=20*log10(abs(h1));
an=angle(h1); an=angle(h1);
subplot(2,1,1); subplot(2,1,1);
plot(om/pi,m); plot(om/pi,m);
xlabel('(a) normalized frequency'); xlabel('(a) normalized frequency');
ylabel('gain in db'); ylabel('gain in db');
title('BUTTERWORTH BAND PASS FILTER'); title('chebyshev_1 high pass filter');
grid; grid;
subplot(2,1,2); subplot(2,1,2);
plot(om/pi,an); plot(om/pi,an);
xlabel('(b) normalized frequency'); xlabel('(b) normalized frequency');
ylabel('phase in radians'); ylabel('phase in radians');
grid; grid;

Analog butter worth BAND STOP filter ANALOG CHEBYSHEV TYPE1 LOWPASS FILTER
wp=[0.1 0.6]; wp=0.24;
ws=[0.3 0.5]; ws=0.35;
rp=0.2; rp=0.29;
rs=40; rs=29;
[N,wn]=buttord(wp,ws,rp,rs,'s'); [N,wn]=cheb1ord(wp,ws,rp,rs,'s');
[B,A]=butter(N,wn,'STOP','s'); [B,A]=cheby1(N,rp,wn,'LOW','s');
w=0:0.01:pi; w=0:0.01:pi;
[h1,om]=freqs(B,A,w); [h1,om]=freqs(B,A,w);
m=20*log10(abs(h1)); m=20*log10(abs(h1));
an=angle(h1); an=angle(h1);
subplot(2,1,1); subplot(2,1,1);
plot(om/pi,m); plot(om/pi,m);
xlabel('(a) normalized frequency'); xlabel('(a) normalized frequency');
ylabel('gain in db'); ylabel('gain in db');
title('BUTTERWORTH BAND STOP FILTER'); title('chebyshev_1 low pass filter');
grid; grid;
subplot(2,1,2); subplot(2,1,2);
plot(om/pi,an); plot(om/pi,an);
xlabel('(b) normalized frequency'); xlabel('(b) normalized frequency');
ylabel('phase in radians'); ylabel('phase in radians');
grid; grid;
ANALOG CHEBYSHEV TYPE1 BANDPASS FILTER ANALOG CHEBYSHEV TYPE2 HIGHPASS FILTER
wp=[0.3 0.5]; ws=0.28;
ws=[0.1 0.8]; wp=0.32;
rp=0.29; rp=0.34;
rs=29; rs=34;
[N,wn]=cheb1ord(wp,ws,rp,rs,'s'); [N,wn]=cheb2ord(wp,ws,rp,rs,'s');
[B,A]=cheby1(N,rp,wn,'BANDPASS','s'); [B,A]=cheby2(N,rs,wn,'HIGH','s');
w=0:0.01:pi; w=0:0.01:pi;
[h1,om]=freqs(B,A,w); [h1,om]=freqs(B,A,w);
m=20*log10(abs(h1)); m=20*log10(abs(h1));
an=angle(h1); an=angle(h1);
subplot(2,1,1); subplot(2,1,1);
plot(om/pi,m); plot(om/pi,m);
xlabel('(a) normalized frequency'); xlabel('(a) normalized frequency');
ylabel('gain in db'); ylabel('gain in db');
title('chebyshev_1 BANDPASS filter'); title('chebyshev_1 high pass filter');
grid; grid;
subplot(2,1,2); subplot(2,1,2);
plot(om/pi,an); plot(om/pi,an);
xlabel('(b) normalized frequency'); xlabel('(b) normalized frequency');
ylabel('phase in radians'); ylabel('phase in radians');
grid; grid;
ANALOG CHEBYSHEV TYPE1 BANDSTOP FILTER
wp=[0.1 0.6]; ANALOG CHEBYSHEV TYPE2 LOWPASS FILTER
ws=[0.3 0.5]; wp=0.28;
rp=0.2; ws=0.32;
rs=40; rp=0.34;
[N,wn]=cheb1ord(wp,ws,rp,rs,'s'); rs=34;
[B,A]=cheby1(N,rp,wn,'STOP','s'); [N,wn]=cheb2ord(wp,ws,rp,rs,'s');
w=0:0.01:pi; [B,A]=cheby2(N,rs,wn,'LOW','s');
[h1,om]=freqs(B,A,w); w=0:0.01:pi;
m=20*log10(abs(h1)); [h1,om]=freqs(B,A,w);
an=angle(h1); m=20*log10(abs(h1));
subplot(2,1,1); an=angle(h1);
plot(om/pi,m); subplot(2,1,1);
xlabel('(a) normalized frequency'); plot(om/pi,m);
ylabel('gain in db'); xlabel('(a) normalized frequency');
title('chebyshev_1 STOP filter'); ylabel('gain in db');
grid; title('chebyshev_2 low pass filter');
subplot(2,1,2); grid;
plot(om/pi,an); subplot(2,1,2);
xlabel('(b) normalized frequency'); plot(om/pi,an);
ylabel('phase in radians'); xlabel('(b) normalized frequency');
grid; ylabel('phase in radians');
grid;
ANALOG CHEBYSHEV TYPE2 BANDPASS FILTER
wp=[0.3 0.5];
ws=[0.1 0.8];
rp=0.29;
rs=29;
[N,wn]=cheb2ord(wp,ws,rp,rs,'s');
[B,A]=cheby2(N,rs,wn,'BANDPASS','s');
w=0:0.01:pi;
[h1,om]=freqs(B,A,w);
m=20*log10(abs(h1));
an=angle(h1);
subplot(2,1,1);
plot(om/pi,m);
xlabel('(a) normalized frequency');
ylabel('gain in db');
title('chebyshev_2 BANDPASS filter');
grid;
subplot(2,1,2);
plot(om/pi,an);
xlabel('(b) normalized frequency');
ylabel('phase in radians');
grid;

ANALOG CHEBYSHEV TYPE2 BANDSTOP FILTER


wp=[0.1 0.6];
ws=[0.3 0.5];
rp=0.22;
rs=40;
[N,wn]=cheb2ord(wp,ws,rp,rs,'s');
[B,A]=cheby2(N,rs,wn,'STOP','s');
w=0:0.01:pi;
[h1,om]=freqs(B,A,w);
m=20*log10(abs(h1));
an=angle(h1);
subplot(2,1,1);
plot(om/pi,m);
xlabel('(a) normalized frequency');
ylabel('gain in db');
title('chebyshev_2 BANDSTOP filter');
grid;
subplot(2,1,2);
plot(om/pi,an);
xlabel('(b) normalized frequency');
ylabel('phase in radians');
grid;
IIR HIGHPASS FILTERS IIR LOWPASS FILTERS
ws=0.3; wp=0.3;
wp=0.7; ws=0.7;
rp=18; rp=18;
rs=180; rs=180;
[N,wn]=buttord(wp,ws,rp,rs); [N,wn]=buttord(wp,ws,rp,rs);
[B,A]=butter(N,wn,'HIGH'); [B,A]=butter(N,wn,'low');
k=0:0.01:pi; k=0:0.01:pi;
[H1,W]=freqz(B,A,k); [H1,W]=freqz(B,A,k);
H1=20*log10(abs(h1)); H1=20*log10(abs(h1));
subplot(3,1,1); subplot(3,1,1);
plot(k/pi,h1); plot(k/pi,h1);
title('butterworth high pass filter'); title('butterworth lowpass filter');
grid; grid;
[N1,WN1]=cheb1ord(wp,ws,rp,rs); [N1,WN1]=cheb1ord(wp,ws,rp,rs);
R1=40; R1=40;
[B1,A1]=cheby1(N1,R1,WN1,'HIGH'); [B1,A1]=cheby1(N1,R1,WN1,'low');
k=0:0.01:pi; k=0:0.01:pi;
[H2,W2]=freqz(B1,A1,k); [H2,W2]=freqz(B1,A1,k);
H2=20*log(abs(H2)); H2=20*log(abs(H2));
subplot(3,1,2); subplot(3,1,2);
plot(k/pi,H2); plot(k/pi,H2);
title('chebyshev type_1 highpass filter'); title('chebyshev type_1 lowpass filter');
grid; grid;
[N2,WN2]=cheb2ord(wp,ws,rp,rs); [N2,WN2]=cheb2ord(wp,ws,rp,rs);
R2=40; R2=40;
[B2,A2]=cheby2(N2,R2,WN2,'HIGH'); [B2,A2]=cheby2(N2,R2,WN2,'low');
k=0:01:pi; k=0:01:pi;
[H3,W3]=freqz(B2,A2,k); [H3,W3]=freqz(B2,A2,k);
H3=20*log(abs(H3)); H3=20*log(abs(H3));
subplot(3,1,3); subplot(3,1,3);
plot(k/pi,H3); plot(k/pi,H3);
axis([0.1 -250 100]); axis([0.1 -250 100]);
title('chebyshev type-2 highpass filter'); title('chebyshev type-2 lowpass filter');
grid; grid;
CIRCULAR CONVOLUTION
#include<stdio.h>
LINEAR CONVOLUTION int m,n,x[30],h[30],y[30],i,j,temp[30],k,x2[30],a[30];
void main()
{
#include<stdio.h> printf("Enter the length of the first sequence:\n");
int x[20],h[20],y[20],N1,N2,n,m; scanf("%d",&m);
main() printf("Enter the length of the second sequence:\n");
{ scanf("%d",&n);
printf("Enter the length of input sequence printf("Enter the first sequence:\n");
x(n)\t:N1="); for(i=0;i<m;i++)
scanf("%d",&N1); scanf("%d",&x[i]);
printf("Enter the length of impulse response
h(n)\t:N2="); printf("Enter the second sequence:\n");
scanf("%d",&N2); for(j=0;j<n;j++)
printf("Enter %d samples for input sequence scanf("%d",&h[j]);
x(n):\n",N1); if(m-n!=0)
for(n=0;n<N1;n++) { if(m>n)
scanf("%d",&x[n]); {
printf("Enter %d samples for impulse for(i=n;i<m;i++)
response h(n):\n",N2);
h[i]=0;
for(n=0;n<N2;n++)
n=m;
scanf("%d",&h[n]);
}
printf("Input sequence \nx(n)=");
for(i=m;i<n;i++)
for(n=0;n<N1;n++)
x[i]=0;
printf("\t%d",x[n]);
m=n; }
printf("\nImpulse Response \nh(n)=");
y[0]=0;
for(n=0;n<N2;n++)
a[0]=h[0];
printf("\t%d",h[n]);
for(j=1;j<n;j++)
for(n=0;n<N1+N2-1;n++)
a[j]=h[n-j];
{
/*circular convolution*/
y[n]=0;
for(m=0;m<=n;m++) for(i=0;i<n;i++)
y[0]+=x[i]*a[i];
y[n]=y[n]+x[m]*h[n-m];
for(k=1;k<n;k++)
}
{
printf("\n Response of LT1 system
is\ny(n)="); y[k]=0;
for(n=0;n<N1+N2-1;n++) for(j=1;j<n;j++)
printf("\t%d",y[n]); x2[j]=a[j-1];
} x2[0]=a[n-1];
for(i=0;i<n;i++)
{
a[i]=x2[i];
y[k]+=x[i]*x2[i];
}}
printf("The circular convolution\n");
for(i=0;i<n;i++)
printf("%d\t",y[i]); }

You might also like