3

我创建了一个多反馈二阶低通滤波器,它可以放大并为输出添加直流参考。

差分二阶多反馈低通滤波器

为了模拟它,我在下面创建了用于在以前的 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 )

结果滤波器的波德图

4

2 回答 2

3

我真的不知道为什么会这样,但至少它适用于 matlab 2013b。在评估之前添加一个执行字符转换的步骤Hs

HsChar= char(Hs);
numHs = eval(HsChar);   
bode(numHs);
于 2014-02-14T15:08:44.917 回答
1

从链接http://www.mathworks.com/matlabcentral/answers/6355-how-do-i-get-the-coefficients-of-this-symbolic-expression试试这个,

[c,t] = coeffs(evalin(symengine,['denom('char(Hs)')']),s);

在漂亮的代码之后。然后你可以在 c 上使用 eval 来计算系数,数值上,那么它只是在分母中使用这些系数的 tf 。所以,

s = tf('s');
numHs = eval(Hs);    % ofending command, should replace sym s by tf('s') as previous versions.
bode(numHs);

变成,

[c,t] = coeffs(evalin(symengine,['denom(' char(Hs) ')']),s);
H = tf(nominator,denominator);
bode(H);

因为你已经有了提名权?这应该可以解决问题。

于 2014-02-14T15:03:15.853 回答