/*************************************************************************** mfbfilter.cpp ---------------- begin : Wed Apr 10 2014 copyright : (C) 2014 by Vadim Kuznetsov email : ra3xdh@gmail.com ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #ifdef HAVE_CONFIG_H # include #endif #include "mfbfilter.h" MFBfilter::MFBfilter(Filter::FilterFunc ffunc_, Filter::FType type_, FilterParam par) : Filter(ffunc_,type_,par) { switch (ftype) { case Filter::LowPass : Nr1=3; Nc1=2; break; case Filter::HighPass : Nr1=2; Nc1=3; break; default: break; } //Nr1 = 3; //Nc1 = 2; Nop1 = 1; } void MFBfilter::createLowPassSchematic(QString &s) { //int const N_R=4; // number of resisitors in 2-order Sallen-Key stage //int const N_C=2; // number of capacitors in 2-order Sallen-Key stage RC_elements stage; int dx = 0; int N2ord = order/2; // number of 2-nd order stages int N1stOrd = order%2; // number of 1-st order stages s += "\n").arg((10.0*Fc)/1000.0); s += "<.DC DC1 1 60 440 0 61 0 0 \"26.85\" 0 \"0.001\" 0 \"1 pA\" 0 \"1 uV\" 0 \"no\" 0 \"150\" 0 \"no\" 0 \"none\" 0 \"CroutLU\" 0>\n"; s += "\n"; s += QString("\n").arg(70+dx); s += QString("\n").arg(70+dx); for (int i=1; i<=N2ord; i++) { stage = Sections.at(i-1); qDebug()<\n").arg(200+dx); s += QString("\n").arg(360+dx); s += QString("\n").arg(1+(i-1)*Nop1).arg(390+dx); s += QString("\n").arg(2+(i-1)*Nc1).arg(200+dx).arg(C2,0,'f',3).arg(suffix2); s += QString("\n").arg(1+(i-1)*Nc1).arg(320+dx).arg(C1,0,'f',3).arg(suffix1); s += QString("\n").arg(1+(i-1)*Nr1).arg(200+dx).arg(stage.R1,0,'f',3); s += QString("\n").arg(2+(i-1)*Nr1).arg(150+dx).arg(stage.R2,0,'f',3); s += QString("\n").arg(3+(i-1)*Nr1).arg(250+dx).arg(stage.R3,0,'f',3); dx += 510; } if (N1stOrd!=0) { createFirstOrderComponentsLPF(s,Sections.last(),dx+10); } s += "\n"; s += "\n"; dx = 0; s += "<70 250 120 250 \"in\" 120 220 22 \"\">\n"; s += "<70 250 70 300 \"\" 0 0 0 \"\">\n"; for (int i=1; i<=N2ord; i++) { if (i!=1) { s += QString("<%1 250 %2 270 \"\" 0 0 0 \"\">\n").arg(120+dx).arg(120+dx); s += QString("<%1 270 %2 270 \"\" 0 0 0 \"\">\n").arg(dx-40).arg(120+dx); } s += QString("<%1 250 %2 250 \"\" 0 0 0 \"\">\n").arg(180+dx).arg(200+dx); s += QString("<%1 250 %2 250 \"\" 0 0 0 \"\">\n").arg(200+dx).arg(220+dx); s += QString("<%1 210 %2 250 \"\" 0 0 0 \"\">\n").arg(200+dx).arg(200+dx); s += QString("<%1 250 %2 320 \"\" 0 0 0 \"\">\n").arg(200+dx).arg(200+dx); s += QString("<%1 290 %2 350 \"\" 0 0 0 \"\">\n").arg(360+dx).arg(360+dx); s += QString("<%1 130 %2 150 \"\" 0 0 0 \"\">\n").arg(200+dx).arg(200+dx); s += QString("<%1 130 %2 130 \"\" 0 0 0 \"\">\n").arg(200+dx).arg(320+dx); s += QString("<%1 130 %2 150 \"\" 0 0 0 \"\">\n").arg(320+dx).arg(320+dx); s += QString("<%1 250 %2 250 \"\" 0 0 0 \"\">\n").arg(280+dx).arg(320+dx); s += QString("<%1 250 %2 250 \"\" 0 0 0 \"\">\n").arg(320+dx).arg(360+dx); s += QString("<%1 210 %2 250 \"\" 0 0 0 \"\">\n").arg(320+dx).arg(320+dx); s += QString("<%1 130 %2 130 \"\" 0 0 0 \"\">\n").arg(320+dx).arg(470+dx); s += QString("<%1 270 %2 270 \"\" 0 0 0 \"\">\n").arg(430+dx).arg(470+dx); if ((2*i)==order) { s += QString("<%1 130 %2 270 \"out\" %3 170 70 \"\">\n").arg(470+dx).arg(470+dx).arg(500+dx); } else { s += QString("<%1 130 %2 270 \"\" 0 0 0 \"\">\n").arg(470+dx).arg(470+dx); } dx += 510; } if (N1stOrd!=0) { createFirstOrderWires(s,dx+10,270); } s += "\n"; } void MFBfilter::createHighPassSchematic(QString &s) { RC_elements stage; int dx = 0; int N2ord = order/2; // number of 2-nd order stages int N1stOrd = order%2; // number of 1-st order stages s += "\n").arg((10.0*Fc)/1000.0); s += "<.DC DC1 1 60 440 0 61 0 0 \"26.85\" 0 \"0.001\" 0 \"1 pA\" 0 \"1 uV\" 0 \"no\" 0 \"150\" 0 \"no\" 0 \"none\" 0 \"CroutLU\" 0>\n"; s += "\n"; s += QString("\n").arg(70+dx); s += QString("\n").arg(70+dx); for (int i=1; i<=N2ord; i++) { stage = Sections.at(i-1); qDebug()<\n").arg(200+dx); s += QString("\n").arg(360+dx); s += QString("\n").arg(1+(i-1)*Nop1).arg(390+dx); s += QString("\n").arg(1+(i-1)*Nr1).arg(200+dx).arg(stage.R1,0,'f',3); s += QString("\n").arg(2+(i-1)*Nr1).arg(320+dx).arg(stage.R2,0,'f',3); s += QString("\n").arg(1+(i-1)*Nc1).arg(200+dx).arg(C1,0,'f',3).arg(suffix1); s += QString("\n").arg(2+(i-1)*Nc1).arg(150+dx).arg(C2,0,'f',3).arg(suffix2); s += QString("\n").arg(3+(i-1)*Nc1).arg(250+dx).arg(C1,0,'f',3).arg(suffix1); dx += 510; } if (N1stOrd!=0) { createFirstOrderComponentsHPF(s,Sections.last(),dx+10); } s += "\n"; s += "\n"; dx = 0; s += "<70 250 120 250 \"in\" 120 220 22 \"\">\n"; s += "<70 250 70 300 \"\" 0 0 0 \"\">\n"; for (int i=1; i<=N2ord; i++) { if (i!=1) { s += QString("<%1 250 %2 270 \"\" 0 0 0 \"\">\n").arg(120+dx).arg(120+dx); s += QString("<%1 270 %2 270 \"\" 0 0 0 \"\">\n").arg(dx-40).arg(120+dx); } s += QString("<%1 250 %2 250 \"\" 0 0 0 \"\">\n").arg(180+dx).arg(200+dx); s += QString("<%1 250 %2 250 \"\" 0 0 0 \"\">\n").arg(200+dx).arg(220+dx); s += QString("<%1 210 %2 250 \"\" 0 0 0 \"\">\n").arg(200+dx).arg(200+dx); s += QString("<%1 250 %2 320 \"\" 0 0 0 \"\">\n").arg(200+dx).arg(200+dx); s += QString("<%1 290 %2 350 \"\" 0 0 0 \"\">\n").arg(360+dx).arg(360+dx); s += QString("<%1 130 %2 150 \"\" 0 0 0 \"\">\n").arg(200+dx).arg(200+dx); s += QString("<%1 130 %2 130 \"\" 0 0 0 \"\">\n").arg(200+dx).arg(320+dx); s += QString("<%1 130 %2 150 \"\" 0 0 0 \"\">\n").arg(320+dx).arg(320+dx); s += QString("<%1 250 %2 250 \"\" 0 0 0 \"\">\n").arg(280+dx).arg(320+dx); s += QString("<%1 250 %2 250 \"\" 0 0 0 \"\">\n").arg(320+dx).arg(360+dx); s += QString("<%1 210 %2 250 \"\" 0 0 0 \"\">\n").arg(320+dx).arg(320+dx); s += QString("<%1 130 %2 130 \"\" 0 0 0 \"\">\n").arg(320+dx).arg(470+dx); s += QString("<%1 270 %2 270 \"\" 0 0 0 \"\">\n").arg(430+dx).arg(470+dx); if ((2*i)==order) { s += QString("<%1 130 %2 270 \"out\" %3 170 70 \"\">\n").arg(470+dx).arg(470+dx).arg(500+dx); } else { s += QString("<%1 130 %2 270 \"\" 0 0 0 \"\">\n").arg(470+dx).arg(470+dx); } dx += 510; } if (N1stOrd!=0) { createFirstOrderWires(s,dx+10,270); } s += "\n"; } void MFBfilter::calcHighPass() { float R1,R2,C1,C2; float Wc = 2*M_PI*Fc; 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; qDebug()<calcFirstOrder(); } void MFBfilter::calcLowPass() { float R1,R2,R3,C1,C2; float Wc = 2*M_PI*Fc; 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; qDebug()<calcFirstOrder(); }