IIR filter source program designed with matlab
(1) IIR first-order low-pass filter P576
clear;
fi=1;fs=10;Gc2=0.9;
wc=2*pi*fi/fs;
omegac=tan(wc/2);
alpha=(sqrt(Gc2)/sqrt(1-Gc2))*omegac;
a=(1-alpha)/(1+alpha);
b=(1-a)/2;
w=0:pi/300:pi;
Hw2=alpha^2./(alpha^2+(tan(w/2)).^2);
plot(w/pi,Hw2);
grid;
hold on;
(2) First-order high-pass filter P581
clear;
fi=1;fs=10;Gc2=0.5;
wc=2*pi*fi/fs;
omegac=tan(wc/2);
alpha=(sqrt(1-Gc2)/(sqrt(Gc2)))*omegac;
a=(1-alpha)/(1+alpha);
b=(1+a)/2;
w=0:pi/300:pi;
Hw2=(tan(w/2).^2)./(alpha^2+(tan(w/2)).^2);
plot(w/pi,Hw2);
grid;
hold on;
(3) Notch filter
clear;
Gb2=0.5;
w0=0.35*pi;
deltaw=0.1*pi;
b=1/(1+tan(deltaw/2)*(sqrt(1-Gb2)/sqrt(Gb2)));
B=[1 -2*cos(w0) 1].*b;
A=[1 -2*b*cos(w0) (2*b-1)];
w=0:pi/500:pi;
H=freqz(B,A,w);
plot(w/pi,abs(H));
grid;
(4) Peak filter
clear;
And=3;
Gb2=10^(-Ac/10);
w0=0.35*pi;
deltaw=0.1*pi;
b=1/(1+tan(deltaw/2)*(sqrt(Gb2)/sqrt(1-Gb2)));
B=[1 0 -1].*(1-b);
A=[1 -2*b*cos(w0) (2*b-1)];
w=0:pi/500:pi;
H=freqz(B,A,w);
plot(w/pi,abs(H));
grid;
(5) IIR low-pass filtering (Butterworth)
% IIR Lowpass Use Butterworth
% copyright by Etual
clear;
fs=20;fpass=4;fstop=5;
Ap=0.5;As=10;
wp=2*pi*fpass/fs;ws=2*pi*fstop/fs;
omegap=tan(wp/2);omegas=tan(ws/2);
ep=sqrt(10^(Ap/10)-1);
es=sqrt(10^(As/10)-1);
N=ceil(log(es/ep)/log(omegas/omegap));
omega0=omegap/ep^(1/N);
K=floor(N/2);
for i=1:K
theta(i)=pi*(N-1+2*i)/(2*N);
end
for i=1:K
G(i)=omega0^2/(1-2*omega0*cos(theta(i))+omega0^2);
end
for i=1:K
a1(i)=2*(omega0^2-1)/(1-2*omega0*cos(theta(i))+omega0^2);
end
for i=1:K
a2(i)=(1+2*omega0*cos(theta(i))+omega0^2)/(1-2*omega0*cos(theta(i))+omega0^2);
end
if K<(N/2)
G0=omega0/(omega0+1);a0=(omega0-1)/(omega0+1);
end
w=0:pi/300:pi;
Hw2=1./(1+(tan(w/2)/omega0).^(2*N));
plot(w/pi,Hw2);
grid;
(6) IIR high-pass filter (Butterworth)
% IIR Hightpass Use Butterworth
% copyright by Etual
clear;
fs=20;fpass=5;fstop=4;
Ap=0.5;As=10;
wp=2*pi*fpass/fs;ws=2*pi*fstop/fs;
omegap=cot(wp/2);omegas=cot(ws/2);
ep=sqrt(10^(Ap/10)-1);
es=sqrt(10^(As/10)-1);
N=ceil(log(es/ep)/log(omegas/omegap));
omega0=omegap/ep^(1/N);
K=floor(N/2);
for i=1:K
theta(i)=pi*(N-1+2*i)/(2*N);
end
for i=1:K
G(i)=omega0^2/(1-2*omega0*cos(theta(i))+omega0^2);
end
for i=1:K
a1(i)=-2*(omega0^2-1)/(1-2*omega0*cos(theta(i))+omega0^2);
end
for i=1:K
a2(i)=(1+2*omega0*cos(theta(i))+omega0^2)/(1-2*omega0*cos(theta(i))+omega0^2);
end
if K<(N/2)
G0=omega0/(omega0+1);a0=-(omega0-1)/(omega0+1);
end
w=(0+eps):pi/300:pi;
Hw2=1./(1+(cot(w/2)/omega0).^(2*N));
plot(w/pi,Hw2);
grid;
(7) IIR bandpass filtering (Butterworth)
% IIR Bandpass Use Butterworth
% copyright by Etual
clear;
fs=20;fpa=2;fpb=4;fsa=1.5;fsb=4.5;
Ap=0.0877;As=16.9897;
wpa=2*pi*fpa/fs;wpb=2*pi*fpb/fs;wsa=2*pi*fsa/fs;wsb=2*pi*fsb/fs;
c=sin(wpa+wpb)/(sin(wpa)+sin(wpb));
omegap=abs((c-cos(wpb))/sin(wpb));
omegasa=(c-cos(wsa))/sin(wsa);omegasb=(c-cos(wsb))/sin(wsb);
omegas=min(abs(omegasa),abs(omegasb));
ep=sqrt(10^(Ap/10)-1);es=sqrt(10^(As/10)-1);
N=ceil(log(es/ep)/log(omegas/omegap));
omega0=omegap/ep^(1/N);
K=floor(N/2);
for i=1:K
theta(i)=pi*(N-1+2*i)/(2*N);
end
for i=1:K
G(i)=omega0^2/(1-2*omega0*cos(theta(i))+omega0^2);
end
for i=1:K
a1(i)=4*c*(omega0*cos(theta(i))-1)/(1-2*omega0*cos(theta(i))+omega0^2);
end
for i=1:K
a2(i)=2*(2*c^2+1-omega0^2)/(1-2*omega0*cos(theta(i))+omega0^2);
end
for i=1:K
a3(i)=-(4*c*(omega0*cos(theta(i))+1))/(1-2*omega0*cos(theta(i))+omega0^2);
end
for i=1:K
a4(i)=(1+2*omega0*cos(theta(i))+omega0^2)/(1-2*omega0*cos(theta(i))+omega0^2);
end
if K<(N/2)
G0=omega0/(1+omega0);a0(1)=-2*c/(1+omega0);a0(2)=(1-omega0)/(1+omega0);
end
w=(0+eps):pi/300:pi;
Hw2=1./(1+((c-cos(w))./(omega0*sin(w))).^(2*N));
plot(w/pi,Hw2);
grid;
(8) IIR band-stop filtering (Butterworth)
% IIR Bandstop Use Butterworth
% copyright by Etual
clear;
fs=20;fpa=1.5;fpb=4.5;fsa=2;fsb=4;
Ap=0.5;As=10;
wpa=2*pi*fpa/fs;wpb=2*pi*fpb/fs;wsa=2*pi*fsa/fs;wsb=2*pi*fsb/fs;
c=sin(wpa+wpb)/(sin(wpa)+sin(wpb));
omegap=abs(sin(wpb)/(c-cos(wpb)));
omegasa=sin(wsa)/(cos(wsa)-c);omegasb=sin(wsb)/(cos(wsb)-c);
omegas=min(abs(omegasa),abs(omegasb));
ep=sqrt(10^(Ap/10)-1);es=sqrt(10^(As/10)-1);
N=ceil(log(es/ep)/log(omegas/omegap));
omega0=omegap/ep^(1/N);
K=floor(N/2);
theta=zeros(1,K);
for i=1:K
theta(i)=pi*(N-1+2*i)/(2*N);
end
G=zeros(1,K);a1=zeros(1,K);a2=zeros(1,K);
for i=1:K
G(i)=omega0^2/(1-2*omega0*cos(theta(i))+omega0^2);
end
for i=1:K
a1(i)=2*(omega0^2-1)/(1-2*omega0*cos(theta(i))+omega0^2);
end
for i=1:K
a2(i)=(1+2*omega0*cos(theta(i))+omega0^2)/(1-2*omega0*cos(theta(i))+omega0^2);
end
if K<(N/2)
G0=omega0/(omega0+1);a0=(omega0-1)/(omega0+1);
end
w=(0+eps):pi/300:pi;
Hw2=1./(1+(sin(w)./(omega0*(c-cos(w)))).^(2*N));
plot(w/pi,Hw2);
grid;
(9) IIR low-pass filtering (Chebyshev 1)
% IIR Lowpass Use Chebyshev Type 1
% copyright by Etual
clear;
fs=20;fpass=4;fstop=5;
Ap=0.5;As=10;
wp=2*pi*fpass/fs;ws=2*pi*fstop/fs;
omegap=tan(wp/2);omegas=tan(ws/2);
ep=sqrt(10^(Ap/10)-1);
es=sqrt(10^(As/10)-1);
e=es/ep;w=omegas/omegap;
N=ceil(log(e+sqrt(e^2-1))/log(w+sqrt(w^2-1)));
a=log(1/ep+sqrt(1/ep^2+1))/N;
omega0=omegap*sinh(a);
K=floor(N/2);
theta=zeros(1,K);omega=zeros(1,K);
for i=1:K
theta(i)=pi*(N-1+2*i)/(2*N);
end
for i=1:K
omega(i)=omegap*sin(theta(i));
end
G=zeros(1,K);a1=zeros(1,K);a2=zeros(1,K);
for i=1:K
G(i)=(omega0^2+omega(i)^2)/(1-2*omega0*cos(theta(i))+omega0^2+omega(i)^2);
end
for i=1:K
a1(i)=2*(omega0^2+omega(i)^2-1)/(1-2*omega0*cos(theta(i))+omega0^2+omega(i)^2);
end
for i=1:K
a2(i)=(1+2*omega0*cos(theta(i))+omega0^2+omega(i)^2)/(1-2*omega0*cos(theta(i))+omega0^2+omega(i)^2);
end
if K<(N/2)
G0=omega0/(omega0+1);a0=(omega0-1)/(omega0+1);
else
H0=sqrt(1/(1+ep^2));
end
f=0:1/300:10;
Hf2=1./(1+ep^2*(cheby(N,tan(pi*f/fs)/omegap)).^2);
plot(f,abs(Hf2));
grid;
(9) IIR low-pass filtering (Chebyshev 1)
% IIR Lowpass Use Chebyshev Type 2
% copyright by Etual
clear;
fs=20;fpass=4;fstop=5;
Ap=0.5;As=10;
wp=2*pi*fpass/fs;ws=2*pi*fstop/fs;
omegap=tan(wp/2);omegas=tan(ws/2);
ep=sqrt(10^(Ap/10)-1);
es=sqrt(10^(As/10)-1);
e=es/ep;w=omegas/omegap;
N=ceil(log(e+sqrt(e^2-1))/log(w+sqrt(w^2-1)));
a=log(es+sqrt(es^2+1))/N;
omega0=omega/birth(a);
K=floor(N/2);
for i=1:K
theta(i)=pi*(N-1+2*i)/(2*N);
end
for i=1:K
omega(i)=omegas/sin(theta(i));
end
for i=1:K
G(i)=(1+omega(i)^-2)/(1-2*omega0^-1*cos(theta(i))+omega0^-2+omega(i)^-2);
end
for i=1:K
a1(i)=2*(1-omega0^-2+omega(i)^-2)/(1-2*omega0^-1*cos(theta(i))+omega0^-2+omega(i)^-2);
end
for i=1:K
a2(i)=(1+2*omega0^-1*cos(theta(i))+omega0^-2+omega(i)^-2)/(1-2*omega0^-1*cos(theta(i))+omega0^-2+omega(i)^-2);
end
for i=1:K
b1(i)=2*(1-omega(i))/(1+omega(i));
end
if K<(N/2)
G0=omega0/(omega0+1);a0=(omega0-1)/(omega0+1);
else
H0=sqrt(1/(1+ep^2));
end
f=(0+eps):1/100:10;
Hf2=(cheby(N,omegas./tan(pi*f/fs))).^2./((cheby(N,omegas./tan(pi*f/fs))).^2+es^2);
plot(f,abs(Hf2));
grid;
(10) Function cheby.m used in chebyshev
function CN=cheby(N,x)
if x<=1
CN=cos(N*cos(x));
else
CN=cosh(N*log(x+sqrt(x.^2-1)));
end
Previous article:Method of Designing FIR Filter Using MATLAB
Next article:Stepper Motor Positioning Control System VHDL Program and Simulation
Recommended ReadingLatest update time:2024-11-16 23:51
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Talk about picking up leaks on Xianyu - Sangfor Internet Behavior Audit AC1300 (Part 1)
- C2000 chip calculation skills and precautions
- The beauty of algorithms
- Worried about switching from Class AB to Class D? No need to worry
- "Practice together in 2021" + continue to persevere
- [TI recommended course] #[High Precision Laboratory] Magnetic Sensor Technology#
- In the information age, how to protect information security?
- Bluetooth controlled stepper motor driver and firmware - Seeking paid technical assistance
- BAT chip industry procurement recruitment
- A look at hybrid electric vehicles from the perspective of driving methods and related main technologies