Skip to content

Commit

Permalink
Start 2-port matching
Browse files Browse the repository at this point in the history
  • Loading branch information
andresmmera committed Jul 29, 2017
1 parent c2595bf commit e057aad
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 3 deletions.
3 changes: 3 additions & 0 deletions qucs/qucs-wideband-matching/GRABIM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1055,5 +1055,8 @@ vector<double> GRABIM::NelderMead(vector<double> x)
return getRow(X, 0);
}

void GRABIM::SetAmplifierS2P(vector<vector<complex<double>>> amps2p)
{

}

1 change: 1 addition & 0 deletions qucs/qucs-wideband-matching/GRABIM.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class GRABIM
void setSearchMode(int);
void SimplifyNetwork(bool);
bool refine;//Runs a Nelder-Mead local optimizer to refine results
void SetAmplifierS2P(vector<vector<complex<double>>>);

private:
vector<double> GridSearch();
Expand Down
1 change: 1 addition & 0 deletions qucs/qucs-wideband-matching/QucsWidebandMatching.qrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<RCC>
<qresource prefix="/">
<file>bitmaps/MatchingNetwork.svg</file>
<file>bitmaps/amplifier.svg</file>
<file>bitmaps/big.qucs.xpm</file>
</qresource>
</RCC>
110 changes: 110 additions & 0 deletions qucs/qucs-wideband-matching/bitmaps/amplifier.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions qucs/qucs-wideband-matching/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,11 @@ int IO::loadS1Pdata(std::string filepath, terminal Port)
return 0;
}

//Reads a s2p Touchstone file
int IO::loadS2Pdata(std::string)
{

}

// Load and source impedances may be sampled at different frequencies. It is essential to resample them
// using the same frequency basis. This requires interpolation of complex data. It would be desirable to use
Expand Down Expand Up @@ -437,6 +442,13 @@ vector<complex<double>> IO::getLoadImpedance()
return ZL;
}


vector<vector<complex<double>>> IO::getAmplifierS2P()
{
ResampleImpedances();
return AmpS2P;
}

vector<double> IO::getFrequency()
{
ResampleImpedances();
Expand Down
3 changes: 3 additions & 0 deletions qucs/qucs-wideband-matching/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ class IO
~IO();
int exportGNUplot(GRABIM_Result, string, bool);
int loadS1Pdata(std::string, terminal);
int loadS2Pdata(std::string);
int ResampleImpedances();
vector<complex<double>> getSourceImpedance();
vector<complex<double>> getLoadImpedance();
vector<vector<complex<double>>> getAmplifierS2P();
vector<double> getFrequency();
void set_constant_ZS_vs_freq(complex<double>);
void set_constant_ZL_vs_freq(complex<double>);
Expand All @@ -65,6 +67,7 @@ class IO
// ZS and ZL are the source and load impedances, respectively whereas fS and fL indicates the frequencies where
// ZS and ZL were sampled
vector<complex<double>> ZS, ZL;
vector<vector<complex<double>>> AmpS2P;
vector<double> fS, fL;

vector<double> freq;//More often than not, ZS and ZL are sampled at different frecuencies, so it is necessary to have
Expand Down
44 changes: 44 additions & 0 deletions qucs/qucs-wideband-matching/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,19 @@ ui::ui()
sz = imgWidget->size();
imgWidget->setFixedSize(.2*sz);

//Amplifier
QPixmap pixmap(":/bitmaps/amplifier.svg");
QIcon ButtonIcon(pixmap);
AmplifierS2Pbutton = new QPushButton();
AmplifierS2Pbutton->setIcon(ButtonIcon);
AmplifierS2Pbutton->setIconSize(pixmap.rect().size());
AmplifierS2Pbutton->setVisible(false);
connect(AmplifierS2Pbutton, SIGNAL(clicked()), this, SLOT(BrowseAmplifier_S2P()));


Impedancelayout->addWidget(SourceImpGroupBox,0,0);
Impedancelayout->addWidget(imgWidget,0,1);
Impedancelayout->addWidget(AmplifierS2Pbutton,0,1);
Impedancelayout->addWidget(LoadImpGroupBox,0,2);


Expand Down Expand Up @@ -150,6 +160,8 @@ ui::ui()
FreqgroupBox->setSizePolicy( sizePolicy );

// Options
TwoPortMatchingCheckbox = new QCheckBox("2-port matching");
connect(TwoPortMatchingCheckbox, SIGNAL(stateChanged(int)), this, SLOT(TwoPortMatchingCheckbox_state(int)));
UseGNUplotCheckbox = new QCheckBox("Use GNUplot");
UseGNUplotCheckbox->setChecked(true);
RefineCheckbox = new QCheckBox("Refine");
Expand All @@ -161,6 +173,7 @@ ui::ui()

OptionsLayout->addWidget(UseGNUplotCheckbox, 0, 0);
OptionsLayout->addWidget(RefineCheckbox, 0, 1);
OptionsLayout->addWidget(TwoPortMatchingCheckbox, 0, 2);
OptionsLayout->addWidget(new QLabel("Temp folder GNUplot:"), 1, 0);
OptionsLayout->addWidget(GNUplotButton, 1, 1);
GNUplot_path = "/tmp";
Expand Down Expand Up @@ -290,6 +303,14 @@ void ui::go_clicked()
}
inout_operations->set_constant_ZS_vs_freq(zs_temp);
}
if (TwoPortMatchingCheckbox->isChecked())
{
inout_operations->loadS2Pdata(AmpFile.toStdString());
}
else
{
inout_operations->loadS2Pdata("");
}

if (!FixedZLCheckbox->isChecked())
{
Expand Down Expand Up @@ -349,6 +370,7 @@ void ui::go_clicked()
// Impedance and frequency settings
MatchingObject->SetSourceImpedance(inout_operations->getSourceImpedance());
MatchingObject->SetLoadImpedance(inout_operations->getLoadImpedance());
MatchingObject->SetAmplifierS2P(inout_operations->getAmplifierS2P());
MatchingObject->SetFrequency(inout_operations->getFrequency());
MatchingObject->refine = RefineCheckbox->isChecked();
MatchingObject->setSearchMode(0);//Default mode
Expand Down Expand Up @@ -396,6 +418,13 @@ void ui::LoadImpedance_clicked()
tr("Open S-parameter file"), QCoreApplication::applicationDirPath());
}

// Opens a file dialog to select the s2p data
void ui::BrowseAmplifier_S2P()
{
AmpFile = QFileDialog::getOpenFileName(this,
tr("Open S-parameter file"), QCoreApplication::applicationDirPath());
}

// Apart from generating a Qucs schematic, the S parameters of the network are stored in GNUplot format
// so the user can check the performance of the network without running Qucs
void ui::GNUplotOutput_clicked()
Expand Down Expand Up @@ -516,3 +545,18 @@ void ui::slotShowResult()
if(ResultState > 5) c = 3000;
QTimer::singleShot(c, this, SLOT(slotShowResult()));
}

//This function catches the event triggered by the 2-port checkbox
void ui::TwoPortMatchingCheckbox_state(int state)
{
if (state == Qt::Unchecked)
{
imgWidget->setVisible(true);
AmplifierS2Pbutton->setVisible(false);
}
else
{
imgWidget->setVisible(false);
AmplifierS2Pbutton->setVisible(true);
}
}
8 changes: 5 additions & 3 deletions qucs/qucs-wideband-matching/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,20 @@ class ui :public QMainWindow

private:
QPushButton * SourceFileButton, * LoadFileButton;
QPushButton * RunButton;
QPushButton * RunButton, *AmplifierS2Pbutton;
QPushButton * GNUplotButton;
QWidget * centralWidget;
QSvgWidget *imgWidget;
QComboBox *SearchModeCombo;
QComboBox *minFUnitsCombo, * maxFUnitsCombo;
QCheckBox *UseGNUplotCheckbox, *RefineCheckbox;
QLabel *minFLabel, *maxFLabel, *SearchModeLabel, *LabelResult;
QString SourceFile, LoadFile;
QString SourceFile, LoadFile, AmpFile;
QString GNUplot_path;
QLineEdit * minFEdit, * maxFEdit;
QGroupBox *SourceImpGroupBox, *LoadImpGroupBox;

QCheckBox * FixedZLCheckbox, * FixedZSCheckbox;
QCheckBox * FixedZLCheckbox, * FixedZSCheckbox, *TwoPortMatchingCheckbox;
QLineEdit * FixedZSLineedit, *FixedZLLineedit;

QLabel *ZLOhmLabel, *ZSOhmLabel;
Expand All @@ -93,6 +93,8 @@ class ui :public QMainWindow
void FixedZSCheckbox_clicked();
void FixedZLCheckbox_clicked();
void slotShowResult();
void TwoPortMatchingCheckbox_state(int);
void BrowseAmplifier_S2P();

private:
complex<double> getComplexImpedanceFromText(char *);
Expand Down

0 comments on commit e057aad

Please sign in to comment.