我创建了一个多反馈二阶低通滤波器,它可以放大,还可以在输出端添加一个直流参考信号。
为了模拟它,我创建了下面的代码,这些代码在以前的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 )

最佳答案

我不知道为什么这样做,但至少在Matlab2013b中是这样。在计算Hs之前添加一个步骤来进行字符转换:

HsChar= char(Hs);
numHs = eval(HsChar);
bode(numHs);

10-06 00:53