Is there any other way to find Transfer function H(z) for an IIR Butterworth Filter?
9 ビュー (過去 30 日間)
古いコメントを表示
close all;
clc;clear all;
%ButterWorth IIR LowPass Filter
Rp=input('Enter PassBand Ripple:');
As=input('Enter Stopband Ripple:');
wp=input('Enter Digital Passband Frequency:');
ws=input ('Enter Digital Stopband Frequency:');
T = input('Enter the Sampling Time Period in Seconds:');
%PreWarping these frequencies into digital domain
omegap = (2/T)*tan(wp/2);
omegas = (2/T)*tan(ws/2);
%Calculating order
num=log10((10^(0.1*Rp)-1)/((10^(0.1*As)-1)));
den=2*log10(omegap/omegas);
N=ceil(num/den);
%Calculating Cut off Frequencies
x1=(10^(0.1*Rp)-1);
x2=(10^(0.1*As)-1);
pow=1/(2*N);
omegac1=omegap/(x1^(pow));
omegac2=omegas/(x2^pow);
omegac=(omegac1+omegac2)/2;
%Calculating Poles
limit=((2*N)-1);
p1=zeros(1,limit+1);
for k=0:limit
pow1=(1j*pi)/(2*N);
e=exp(pow1*((2*k)+N+1));
p1(k+1)=omegac*e;
end
p=zeros(1,N);
%Selection of left Half plane Poles
for k=0:limit
if(real(p1(k+1))<0)
p(k+1)=p1(k+1);
end
end
%Determining Analog Prototype Filter Transfer Function Ha(s)
syms s z
den1=1;
num1=omegac^N;
lt=length(p);
for g=1:lt
den1=den1*(s-p(g));
end
Ha=num1/den1;
%Bilinear Transformation
H=subs(Ha,s,(2/T)*(z-1)/(z+1));
H gives the tranfer function , but the z terms are just as it is. The desired result is that it should be in terms of z^2, z^3 ... etc
Is there any other way to obtain transfer function H(z)? Also How can i find difference equation from H(z)?
3 件のコメント
Star Strider
2022 年 12 月 11 日
One missing item are the units of the inputs. I partially corrected for them here, although the magnitude (checked using the freqz function) is still not correct. I leave those to you.
% close all;
% clc;clear all;
% % % SPECIFICATIONS: Rp = 1 Db, As = 50 dB, wp = 10 Hz, ws = 20 Hz, Fs = 100 Hz
%ButterWorth IIR LowPass Filter
% Rp=input('Enter PassBand Ripple:');
% As=input('Enter Stopband Ripple:');
% wp=input('Enter Digital Passband Frequency:');
% ws=input ('Enter Digital Stopband Frequency:');
% T = input('Enter the Sampling Time Period in Seconds:');
Rp = db2mag(-1); % Convert From dB To Magnitude
As = db2mag(-50); % Convert From dB To Magnitude
T = 0.01; % Sampling Interval (1/Fs)
wp = 10*pi*T*2; % Converted From Hz To rad/s & Corrected For Nyquist Frequency
ws = 20*pi*T*2; % Converted From Hz To rad/s & Corrected For Nyquist Frequency
%PreWarping these frequencies into digital domain
omegap = (2/T)*tan(wp/2);
omegas = (2/T)*tan(ws/2);
%Calculating order
num=log10((10^(0.1*Rp)-1)/((10^(0.1*As)-1)))
num = abs(num)
den=2*log10(omegap/omegas)
den = abs(den)
N=ceil(num/den)
%Calculating Cut off Frequencies
x1=(10^(0.1*Rp)-1);
x2=(10^(0.1*As)-1);
pow=1/(2*N);
omegac1=omegap/(x1^(pow));
omegac2=omegas/(x2^pow);
omegac=(omegac1+omegac2)/2;
%Calculating Poles
limit=((2*N)-1);
p1=zeros(1,limit+1);
for k=0:limit
pow1=(1j*pi)/(2*N);
e=exp(pow1*((2*k)+N+1));
p1(k+1)=omegac*e;
end
p=zeros(1,N);
%Selection of left Half plane Poles
for k=0:limit
if(real(p1(k+1))<0)
p(k+1)=p1(k+1);
end
end
%Determining Analog Prototype Filter Transfer Function Ha(s)
syms s z
den1=1;
num1=omegac^N;
lt=length(p);
for g=1:lt
den1=den1*(s-p(g));
end
Ha=num1/den1;
%Bilinear Transformation
H=subs(Ha,s,(2/T)*(z-1)/(z+1))
[Hn,Hd] = numden(H)
Hnn = sym2poly(Hn)
Hnd = sym2poly(Hd)
figure
freqz(Hnn, Hnd, 2^16, 1/double(T))
set(subplot(2,1,1), 'YLim',[-10 0]) % Zoom Y-Axis Of Magnitude Plot (Optional)
.
回答 (1 件)
Sai
2022 年 12 月 28 日
I understand that you are trying to get your final transfer function in powers of z. With small changes in code without modifying your logic, you can get it as shown in below code snippet.
close all;
clc;clear all;
%ButterWorth IIR LowPass Filter
Rp=input('Enter PassBand Ripple:');
As=input('Enter Stopband Ripple:');
wp=input('Enter Digital Passband Frequency:');
ws=input ('Enter Digital Stopband Frequency:');
T = input('Enter the Sampling Time Period in Seconds:');
%PreWarping these frequencies into digital domain
omegap = (2/T)*tan(wp/2);
omegas = (2/T)*tan(ws/2);
%Calculating order
num=log10((10^(0.1*Rp)-1)/((10^(0.1*As)-1)));
den=2*log10(omegap/omegas);
N=abs(ceil(num/den));
%Calculating Cut off Frequencies
x1=(10^(0.1*Rp)-1);
x2=(10^(0.1*As)-1);
pow=1/(2*N);
omegac1=omegap/(x1^(pow));
omegac2=omegas/(x2^pow);
omegac=(omegac1+omegac2)/2;
%Calculating Poles
limit=((2*N)-1);
p1=zeros(1,limit+1);
for k=0:limit
pow1=(1j*pi)/(2*N);
e=exp(pow1*((2*k)+N+1));
p1(k+1)=omegac*e;
end
p=zeros(1,N);
%Selection of left Half plane Poles
for k=0:limit
if(real(p1(k+1))<0)
p(k+1)=p1(k+1);
end
end
num1=omegac^N;
den1 = p;
%Bilinear Transformation
[zd,pd] = bilinear(num1,den1,1,T)
H = (tf(zd,pd,T))
There are direct MATLAB functions like buttord (for determining filter order and cutoff frequency), butter(for obtaining filter coefficients), bilinear (for converting analog to digital) by which you can design Butterworth filters. Refer to the below documentation pages for more information
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!