mirror of
https://github.com/ra3xdh/qucs_s
synced 2025-03-28 21:13:26 +00:00
Added SallenKey bandpass filter calculation. It works. MFB bandpass doesnot works.
This commit is contained in:
parent
9d2d1e7c77
commit
7074d2e6e1
@ -39,12 +39,16 @@ Filter::Filter(Filter::FilterFunc ffunc_, Filter::FType type_, FilterParam par)
|
||||
TW = par.TW;
|
||||
BW = fabs(Fu -Fl);
|
||||
F0 = sqrt(Fu*Fl);
|
||||
if (ftype==Filter::BandPass) { // BandPass
|
||||
Fc=BW; // cutoff freq. of LPF prototype
|
||||
float Fs1 = Fu + TW;
|
||||
float Fs1lp = fabsf(Fs1 - (F0*F0)/Fs1); // stopband freq. of LPF prototype
|
||||
float Fs2 = Fl - TW;
|
||||
float Fs2lp = fabsf(Fs2 - (F0*F0)/Fs2);
|
||||
Fs = std::min(Fs1lp,Fs2lp);
|
||||
} else if (ftype==Filter::BandStop) { // BandStop
|
||||
|
||||
}
|
||||
Ap = 3.0;
|
||||
As = 20.0;
|
||||
qDebug()<<Fc<<Fs;
|
||||
|
@ -196,6 +196,16 @@ void MFBfilter::createHighPassSchematic(QString &s)
|
||||
s += "</Wires>\n";
|
||||
}
|
||||
|
||||
void MFBfilter::createBandPassSchematic(QString &s)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void MFBfilter::createBandStopSchematic(QString &s)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void MFBfilter::calcHighPass()
|
||||
{
|
||||
float R1,R2,C1,C2;
|
||||
@ -259,3 +269,72 @@ void MFBfilter::calcLowPass()
|
||||
|
||||
this->calcFirstOrder();
|
||||
}
|
||||
|
||||
void MFBfilter::calcBandPass()
|
||||
{
|
||||
float W0 = 2*M_PI*F0;
|
||||
float R1,R2,R3,C1,C2;
|
||||
//float rho = Kv/Q;
|
||||
//float gamma = 1.0;
|
||||
int cnt = 1;
|
||||
|
||||
for (int k=1; k <= order/2; k++) {
|
||||
float re = Poles.at(k-1).real();
|
||||
float im = Poles.at(k-1).imag();
|
||||
float B = -2.0*re;
|
||||
float C = re*re + im*im;
|
||||
|
||||
float H = C + 4.0*Q*Q;
|
||||
float E = (1.0/B)*sqrt(0.5*(H+sqrt(H*H-(4.0*B*B*Q*Q))));
|
||||
float F = (B*E)/Q;
|
||||
float D = 0.5*(F+sqrt(F*F-4.0));
|
||||
|
||||
qDebug()<<D<<E<<Q;
|
||||
|
||||
float rho = Kv*sqrt(C)/Q;
|
||||
float beta = D/E;
|
||||
float gamma = D*D;
|
||||
|
||||
C1 = 10.0/F0;
|
||||
C2 = C1*(rho*beta-gamma)/gamma;
|
||||
R1 = 1.0/(rho*W0*C1);
|
||||
R2 = beta/((C1*(gamma-rho*beta)+gamma*C2)*W0);
|
||||
R3 = (1.0/C1+1.0/C2)/(beta*W0);
|
||||
|
||||
RC_elements current_section;
|
||||
current_section.N = cnt;
|
||||
current_section.R1 = R1;
|
||||
current_section.R2 = R2;
|
||||
current_section.R3 = R3;
|
||||
current_section.C1 = C1;
|
||||
current_section.C2 = C2;
|
||||
Sections.append(current_section);
|
||||
|
||||
cnt++;
|
||||
|
||||
beta = 1.0/(D*E);
|
||||
gamma = 1.0/(D*D);
|
||||
C1 = 10.0/F0;
|
||||
C2 = C1*(rho*beta-gamma)/gamma;
|
||||
R1 = 1.0/(rho*W0*C1);
|
||||
R2 = beta/((C1*(gamma-rho*beta)+gamma*C2)*W0);
|
||||
R3 = (1.0/C1+1.0/C2)/(beta*W0);
|
||||
|
||||
current_section.N = cnt;
|
||||
current_section.R1 = R1;
|
||||
current_section.R2 = R2;
|
||||
current_section.R3 = R3;
|
||||
current_section.C1 = C1;
|
||||
current_section.C2 = C2;
|
||||
Sections.append(current_section);
|
||||
|
||||
cnt++;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void MFBfilter::calcBandStop()
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -27,8 +27,12 @@ class MFBfilter : public Filter
|
||||
protected:
|
||||
void calcHighPass();
|
||||
void calcLowPass();
|
||||
void calcBandPass();
|
||||
void calcBandStop();
|
||||
void createHighPassSchematic(QString &s);
|
||||
void createLowPassSchematic(QString &s);
|
||||
void createBandPassSchematic(QString &s);
|
||||
void createBandStopSchematic(QString &s);
|
||||
|
||||
public:
|
||||
MFBfilter(Filter::FilterFunc ffunc_, Filter::FType type_, FilterParam par);
|
||||
|
@ -117,6 +117,78 @@ void SallenKey::calcHighPass()
|
||||
calcFirstOrder();
|
||||
}
|
||||
|
||||
|
||||
void SallenKey::calcBandPass()
|
||||
{
|
||||
float W0 = 2*M_PI*F0;
|
||||
float R1,R2,R3,R4,C1;
|
||||
//float rho = Kv/Q;
|
||||
//float gamma = 1.0;
|
||||
int cnt = 1;
|
||||
|
||||
for (int k=1; k <= order/2; k++) {
|
||||
float re = Poles.at(k-1).real();
|
||||
float im = Poles.at(k-1).imag();
|
||||
float B = -2.0*re;
|
||||
float C = re*re + im*im;
|
||||
|
||||
float H = C + 4.0*Q*Q;
|
||||
float E = (1.0/B)*sqrt(0.5*(H+sqrt(H*H-(4.0*B*B*Q*Q))));
|
||||
float F = (B*E)/Q;
|
||||
float D = 0.5*(F+sqrt(F*F-4.0));
|
||||
|
||||
qDebug()<<D<<E<<Q;
|
||||
|
||||
float rho = Kv*sqrt(C)/Q;
|
||||
float beta = D/E;
|
||||
float gamma = D*D;
|
||||
|
||||
C1 = 10.0/F0;
|
||||
R1 = 2.0/(rho*W0*C1);
|
||||
R2 = 2.0/((-beta+sqrt((rho-beta)*(rho-beta)+8.0*gamma))*W0*C1);
|
||||
R3 = (1.0/R1+1.0/R2)/(gamma*W0*W0*C1*C1);
|
||||
R4 = 2.0*R3;
|
||||
|
||||
RC_elements current_section;
|
||||
current_section.N = cnt;
|
||||
current_section.R1 = 1000*R1;
|
||||
current_section.R2 = 1000*R2;
|
||||
current_section.R3 = 1000*R3;
|
||||
current_section.R4 = 1000*R4;
|
||||
current_section.C1 = C1;
|
||||
current_section.C2 = C1;
|
||||
Sections.append(current_section);
|
||||
|
||||
cnt++;
|
||||
|
||||
beta = 1.0/(D*E);
|
||||
gamma = 1.0/(D*D);
|
||||
C1 = 10.0/F0;
|
||||
R1 = 2.0/(rho*W0*C1);
|
||||
R2 = 2.0/((-beta+sqrt((rho-beta)*(rho-beta)+8.0*gamma))*W0*C1);
|
||||
R3 = (1.0/R1+1.0/R2)/(gamma*W0*W0*C1*C1);
|
||||
R4 = 2.0*R3;
|
||||
|
||||
current_section.N = cnt;
|
||||
current_section.R1 = 1000*R1;
|
||||
current_section.R2 = 1000*R2;
|
||||
current_section.R3 = 1000*R3;
|
||||
current_section.R4 = 1000*R4;
|
||||
current_section.C1 = C1;
|
||||
current_section.C2 = C1;
|
||||
Sections.append(current_section);
|
||||
|
||||
cnt++;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void SallenKey::calcBandStop()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SallenKey::createHighPassSchematic(QString &s)
|
||||
{
|
||||
int const N_R=4; // number of resisitors in 2-order Sallen-Key stage
|
||||
@ -279,3 +351,15 @@ void SallenKey::createLowPassSchematic(QString &s)
|
||||
|
||||
s += "</Wires>\n";
|
||||
}
|
||||
|
||||
void SallenKey::createBandPassSchematic(QString &s)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SallenKey::createBandStopSchematic(QString &s)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -31,8 +31,12 @@ protected:
|
||||
|
||||
void calcHighPass();
|
||||
void calcLowPass();
|
||||
void calcBandPass();
|
||||
void calcBandStop();
|
||||
void createHighPassSchematic(QString &s);
|
||||
void createLowPassSchematic(QString &s);
|
||||
void createBandPassSchematic(QString &s);
|
||||
void createBandStopSchematic(QString &s);
|
||||
|
||||
public:
|
||||
SallenKey(Filter::FilterFunc ffunc_, Filter::FType type_, FilterParam par);
|
||||
|
Loading…
x
Reference in New Issue
Block a user