前提是你的输入信号的时域采样率要和滤波器的频域采样率要保持一致,这样就涉及定时器触发ADC采样,用STM32的定时器来配置采样率, 附带Matlab平台仿真实现: clear all
fs=250; %数字滤波器的采样频率fs=1000hz
f=50; Phz的正弦信号
t=0:1/fs:4; %时间间隔,ADC采样频率250hz
s=sin(2*pi*f*t); IIR_B=[0.90239774423695518,-0.55771247730967288,0.90239774423695518];
IIR_A= [1,-0.55771247730967288,0.80479548847391036]; w01=0;
w02=0;
w03=0; for i=1:1000
w01=s(i)-IIR_A(2)*w02-IIR_A(3)*w03;
y0(i)=IIR_B(1)*w01+IIR_B(2)*w02+IIR_B(3)*w03;
w03=w02;
w02=w01;
end figure
subplot(211)
axis([1,1000,-1,1]);
hold on
plot(s);
title('直接II型实现—原始信号时域');
subplot(212)
plot(y0,'r'); title('直接II型实现—信号滤波之后');
|