Thanks Zoro for this reply. It works as I want it to get the transfer function. Accurate! The result is pasted below with the code
code:
Enter the Filter response method You will use
Enter(c) for Chebyshev : c
You choose Chebyshev Approximation :
Enter (o) if You know the order & ripple factor or (d) for a filter design : o
Enter the order of Chebyshev filter : 2
Enter the ripple factor of the passband : 0.1526
Cheb_P =
2 0 -1
T_NB2EPS =
0.0931 0 -0.0931 0 0.0233
T_NB2EPS2 =
0.0931 0 -0.0931 0 1.0233
thepoles =
-1.3810 + 1.1863i
-1.3810 - 1.1863i
1.3810 + 1.1863i
1.3810 - 1.1863i
Transfer function:
1
---------------------
s^2 + 2.762 s + 3.314
---------- Post added at 20:02 ---------- Previous post was at 19:07 ----------
Zoro,
However, I am having two problems with this result. The first one is; it is not given me the transfer function of odd number order accurately. The second one is the swapping of roots of the polynomials . The swapping as you will observed should have been: -0.9660i - 0.2471 0.9660i - 0.2471 ...... you will see what I mean below in the results
I have posted the code below for you to see and the results. Cheers!
if (way == 'd')
ripples = input('\n Enter the Ripples value of the passband in dB Amax : ');
ws = input('\n Enter the normalized Rejection frequency ws: ');
att = input('\n Enter the Attenuation value at this frequency in dB Amin : ');
wp = input('\n Enter the frequency in wp : ');
po = ripples / 10;
po_att=att/10;
const = 10 .^ po;
const_att= 10.^po_att;
eibsln = sqrt((const - 1));
eibs_att=sqrt((const_att - 1));
n = (acosh((eibs_att)/(eibsln))/acosh(ws/wp));
n = ceil
;
fprintf('\n The order of the filter is %d',n)
fprintf('\n The value of ripple factor is %d',eibsln)
elseif (way == 'o')
n = input('\n Enter the order of Chebyshev filter : ');
eibsln = input('\n Enter the ripple factor of the passband : ');
else
fprintf('\n Sorry! You entered a wrong choice');
end
% Get the poles
Cheb_P=ChebyshevPoly
T_NB2=conv(Cheb_P,Cheb_P);
T_NB2EPS=T_NB2 * eibsln .^(2)
T_NB2EPS2=T_NB2EPS;
T_NB2EPS2(end)=T_NB2EPS(end)+1
% Get the poles
thepoles=roots(T_NB2EPS2)
hh = find (real(thepoles)< 0);
stpoles = thepoles(hh);
den = poly(stpoles);
den = real(den);
H = tf(1,den) % Transfer function
Results:
Enter the order of Chebyshev filter : 3
Enter the ripple factor of the passband : 0.5088
Cheb_P =
4 0 -3 0
T_NB2EPS =
4.1420 0 -6.2131 0 2.3299 0 0
T_NB2EPS2 =
4.1420 0 -6.2131 0 2.3299 0 1.0000
thepoles =
-0.9660 + 0.2471i
-0.9660 - 0.2471i
0.9660 + 0.2471i
0.9660 - 0.2471i
0.0000 + 0.4942i
0.0000 - 0.4942i
Transfer function:
1
----------------------
s^2 + 1.932 s + 0.9942
Hi Oshaye3,
The problen in your code is that T_NB2EPS2 is defined as a scalar (whose value is the last component of T_NB2EPS plus one). You need a vector.
The last line, i.e.:
T_NB2EPS2= (T_NB2EPS(end)+1)
need to be reformulted. One way is:
T_NB2EPS2=T_NB2EPS;
T_NB2EPS2(end)=T_NB2EPS(end)+1;
Another way:
T_NB2EPS2= [T_NB2EPS(1:end-1), T_NB2EPS(end)+1];
The first one is better: it works equally for row or column vectors.
In the second way, for column vectors the "," should be replaced by ";".
Regards
Z