我创建了一个多反馈二阶低通滤波器,它可以放大并为输出添加直流参考。
为了模拟它,我在下面创建了用于在以前的 MATLAB 版本中工作的代码。现在在 2013a 版本中,它不再工作了。
clear all
close all
syms s Rf R1 R2 C1 Cf Vref V2 V1
Zf1 = R2+1/s/Cf;
Al1 = [(1/Zf1+1/Rf+1/R1+s*C1) (-s*C1) (0)];
Al2 = [(-s*C1) (1/Zf1+1/Rf+1/R1+s*C1) (-1/Zf1-1/Rf)];
Al3 = [(-1/Zf1/s/Cf) (1/Zf1/s/Cf) (-1/Zf1/s/Cf+1)];
A = [Al1; Al2; Al3];
B = [(Vref*(1/Zf1+1/Rf)+V2/R1) ;(V1/R1) ; (Vref*(1-1/Zf1/s/Cf))];
V=A^-1*B;
Vo = simplify(V(3));
Vo = collect(Vo,Vref);
pretty(Vo);
%damp = sqrt(2)/2; % butterworth filter
%wc = 2*pi*150;
%coef_s = 2*damp/wc;
fc = 150;
[z,p,k] = butter(2,1,'low','s');
modpole = abs(p(1));
alpha = abs(real(p(1)));
damp = alpha/modpole;
wc = 2*pi*fc*modpole;
coef_s = 2*damp/wc;
Gain_0Hz = 4.7;
clear syms
R1 = 1E3
Rf = Gain_0Hz*R1
Cf = 82E-9
R2calc = solve('Cf*(Rf*R2/R1+R2+Rf)=coef_s',R2);
R2 = eval(R2calc)
C1calc = solve('2*C1*Rf*R2*Cf=1/wc^2',C1);
C1 = eval(C1calc)
Hs = (Vo - Vref)/(V2-V1);
Hs = simplify(Hs);
pretty(Hs);
s = tf('s');
numHs = eval(Hs); % ofending command, should replace sym s by tf('s') as previous versions.
bode(numHs);
不幸的是,在我升级到 2013a MATLAB 后,此代码停止工作。显示的错误是:
Error using evalin
Undefined function 'power' for input arguments of
type 'tf'.
Error in sym/eval (line 11)
s = evalin('caller',vectorize(map2mat(char(x))));
从@Fija 应用修复后,恢复了正常操作。结果如下所示:
Vref - (Rf V1 - Rf V2) / (R1 + Cf R1 R2 s + Cf R1 Rf s +
2
Cf R2 Rf s + 2 C1 Cf R1 R2 Rf s )
R1 =
1000
Rf =
4700
Cf =
8.2000e-08
R2 =
2.3858e+03
C1 =
6.1218e-07
Rf / (R1 + Cf R1 R2 s + Cf R1 Rf s + Cf R2 Rf s +
2
2 C1 Cf R1 R2 Rf s )