You are on page 1of 4

Bilinear

clc
clear all
close all
lp=0.2*pi;
ls=0.3*pi;
rp=1;
as=16;
e=((10^(0.1*rp))-1)^(0.5);
A=10^(as/20);
lr=ls/lp;
alpha=(1/e)+(1+(1/(e^2)))^0.5;
g=((A^2-1)/e^2)^0.5;
N=ceil((log10((g+(g^2-1)^0.5)))/(log10(lr+(lr^2-1)^0.5)));
a=0.5*((alpha^(1/N))-((1/alpha)^(1/N)));
b=0.5*((alpha^(1/N))+((1/alpha)^(1/N)));
for k=0:N-1
    ak=(a*lp)*(cos((pi/2)+(((2*k+1)*pi)/(2*N))));
    lk=(b*lp)*(sin((pi/2)+(((2*k+1)*pi)/(2*N))));
    pk(k+1)=ak+(1j*lk);
end
if N%2==0
    k=-prod(pk);
else
    k=-prod(pk)*(1/sqrt(1+(e^2)));
end
omega=0:0.01:1;
for i=1:length(omega)
    d=1;
    for m=1:length(pk)
        s=2*((1-exp(-1j*omega(i)))/(1+exp(-1j*omega(i))));
        d=d*(s-pk(m));
    end
    ha(i)=abs(k/d);
    hal(i)=20*log10(ha(i));
end
ha
subplot(2,1,1)
plot(omega,ha);
xlabel('frequency');
ylabel('(ha)');
title({'frequency responce';'318126512137'});
grid on
subplot(2,1,2)
plot(hal)
xlabel('normalized freq');
ylabel('(hal)');
title({'gain in db';'318126512137'});
grid on

Kaiser

clc;
close all;
wp=0.2*pi;
ws=0.3*pi;
wc=(ws+wp)/2;
As=50;
NTW=(ws-wp)/(2*pi);
M=ceil(((As-7.35)/(14.36*NTW))+1)+1;
if As>=50
    beta=0.1102*(As-8.7);
elseif (21<As)&&(As<50)
    beta=(0.5842*((As-21)^0.4))+(0.07886*(As-21));
else
    beta=0;
end    
for n=0:M-1
    k=beta*((1-((1-((2*n)/(M-1)))^2))^0.5);
    w(n+1)=besseli(0,k)/besseli(0,beta);
end
alpha=(M-1)/2;
n=0:M-1;
m=n-alpha+0.0001;
hd=sin(wc*m)./(pi*m);
h=hd.*w;
subplot(2,2,1)
plot(w)
subplot(2,2,2)
plot(hd)
subplot(2,2,3)
plot(h)
[Mag,Freq]=freqz(h);
Mag_db=20*log10(abs(Mag));
subplot(2,2,4)
plot(Freq,Mag_db)
Chebichev

clc
clear all
close all
%Given specification
T=1;
wp=0.2*pi;
ws=0.3*pi;
op=(2/T)*tan(wp/2);
os=(2/T)*tan(ws/2);
Rp=1;
As=16;
%Parameters computation
ebs=sqrt((10^(0.1*Rp))-1);
A=10^(As/20);
oc=op;
or=os/op;
g=sqrt(((A^2)-1)/(ebs^2));
N=ceil((log10(g+sqrt((g^2)-1)))/(log10(or+sqrt((or^2)-1))));
alpha=(1/ebs)+sqrt(1+(1/(ebs^2)));
a=(1/2)*((alpha^(1/N))-((1/alpha)^(1/N)));
b=(1/2)*((alpha^(1/N))+((1/alpha)^(1/N)));
%Poles computation
for k=0:N-1
    sigk=(a*oc)*cos((pi/2)+((2*k+1)*pi/(2*N)));
    omgk=(b*oc)*sin((pi/2)+((2*k+1)*pi/(2*N)));
    P(k+1)=sigk+(1i*omgk);
end
%Selection of LHP
f=find(real(P)<0);
P1=P(f);
%calculation for 'K'
if rem(N,2)==0
    K=-prod(P1);
else
    K=-prod(P1)*(1/sqrt(1+(ebs^2)));
end
%Transfer function
omg=0:0.01:pi;
for i=1:length(omg)
    H=1;
    for j=1:length(P1)
        H=H*(1i*omg(i)-P1(j));
    end
    Ha(i)=abs(K/H);
    Ha1(i)=20*log10(Ha(i));
end
plot(omg,Ha);
xlabel('frequency');
ylabel('|Ha|');
title('frequency response-318126512137');
grid on
figure,
plot(omg,Ha1);
xlabel('frequency');
ylabel('20log10|Ha1|');
title('frequency response-318126512137');
grid on

You might also like