
butterworth[p_]:=Module[{},
    n = 2*p;
    denom = 1;
    For[k=0,k<p,k++,
        c=-2*Cos[Pi/(2*n)+k*Pi/n+Pi/2];
        denom = denom*(s^2+c*s+1); 
    ];
    Return[1/denom]; 
] 
                
T=butterworth[3]
                
H[x_]:=T/.s->I*x;
GdB[x_]:=20*Log[10,Abs[H[x]]];
phase[x_]:=Arg[H[x]]*180/Pi;
                
Plot[GdB[10^lx],{lx,-2,2},AxesLabel->{"log(x)","GdB"},
                            PlotRange->{{-2,2},{-60,10}}]
Plot[phase[10^lx],{lx,-2,2},AxesLabel->{"log(x)","phase"}]
Get["../simulin/simulineaire.m"];

filtre[r_,c_,k_,g_]:=Module[{},
    n=6;
    A=Table[0,{n},{n}];
    B=Table[0,{n}];
    A=ajouterResistance[A,1,2,r];
    A=ajouterResistance[A,2,3,r];
    A=ajouterResistance[A,5,4,(k-1)*r0];
    A=ajouterResistance[A,4,6,r0];
    A=ajouterCapacite[A,2,5,c];
    A=ajouterCapacite[A,3,6,c];
    {A,B}=ajouterSourceTensionSTCT[A,B,5,6,3,4,g];
    {A,B}=ajouterMasse[A,B,6];
    {A,B}=definirEntree[A,B,1];
    Return[{A,B}];
]
                
{A,B}=filtre[R,C,K,g];
T=transfert[A,B,5]
                
p=2;
n=2*p;
K=Table[N[3+2*Cos[Pi/(2*n)+i*Pi/n+Pi/2]],{i,0,p-1}]
                
p=3;
n=2*p;
K=Table[N[3+2*Cos[Pi/(2*n)+i*Pi/n+Pi/2]],{i,0,p-1}]
                
