Skip to content

Commit

Permalink
Qucs Wideband Matching tool
Browse files Browse the repository at this point in the history
This PR is a tool for designing wideband matching networks between
complex, frequency dependent impedances. It is based on the grid search
algorithm described in [1], however the implementation differs from the
original where it was found convenient.

The workflow is the following:

    The user enters the source/load impedance data and the frequency
band where a good matching condition is required. 1.1 Whenever the
impedance depends on the frequency, it must be specified using a s1p
file.

2 Search mode selection: The tool comes with a set of default circuit
candidates for the best matching network, but the user can also specify
custom topologies (L/C/TL) using a text file. The response of the
default topologies was analytically calculated beforehand, so the
execution is faster than when using an arbitrary network.

    For every candidate topology:
    3.1 The program sets a suitable starting point depending on the
impedance of the components at the mean frequency.
    3.2 Grid search. A hypercube is build over the current pivot and
then every vertex is evaluated. At the end of each iteration, the
hypercube is moved to the best vertex or, otherwise, it is
shrunk/expanded. When the stop condition is met, a ‘rough’ local optimum
should be achieved.

    Those topologies which gave a good matching condition (say <10dB)
after the grid search are chosen to refine their results with a local
optimiser. At some point, I have linked Nlopt library and tested a few
derivative free optimizers such as Subplex, Praxis and Nelder-Mead. The
Subplex method claims to outperform NM when the dimension of the problem
is high, but, in general, a matching network should be kept as simple as
possible (so typically, dimension < 6). On the other hand, the Praxis
algorithm, as a variant of the Powell’s method, relies on the assumption
that the objective function follows a quadratic expression... but I am
not pretty sure that the matching network design problem meets this
condition. Finally, the Nelder-Mead algorithm is dead simple to
implement and the results seem to be good enough… so it was the one I
have chosen.

    At the end of the program, the best matching network is copied to
clipboard in the same way as other Qucs tools do.

In order to verify the tool is working as expected, the user/developer
can execute a command line testbench (qucs-wideband-
matching/testbench/testbench)

For sure there is plenty of room for improvement, so comments are
welcome :)

[1] Broadband direct-coupled and RF matching networks. Thomas R.
Cuthbert, 1999
[2] Convergence properties of the Nelder-Mead simplex method in low
dimensions. J.F. Lagarias, J.A. Reeds. SIAM J. OPTIM, Vol 9, No. 1, pp.
112-147

Added logging.c(/h)
  • Loading branch information
andresmmera committed Aug 17, 2016
1 parent e3f1844 commit 20e3cd4
Show file tree
Hide file tree
Showing 41 changed files with 6,087 additions and 4 deletions.
56 changes: 55 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,58 @@ Debug
CMakeScripts
*.cxx_parameters
shadow

/qucs-core/build-aux/ar-lib
/qucs-core/build-aux/compile
/qucs-core/build-aux/test-driver
/qucs-core/build-aux/ylwrap
/qucs-core/src/components/verilog/DLS_1ton.cpp
/qucs-core/src/components/verilog/DLS_nto1.cpp
/qucs-core/src/components/verilog/EKV26MOS.cpp
/qucs-core/src/components/verilog/MESFET.cpp
/qucs-core/src/components/verilog/andor4x2.cpp
/qucs-core/src/components/verilog/andor4x3.cpp
/qucs-core/src/components/verilog/andor4x4.cpp
/qucs-core/src/components/verilog/binarytogrey4bit.cpp
/qucs-core/src/components/verilog/comp_1bit.cpp
/qucs-core/src/components/verilog/comp_2bit.cpp
/qucs-core/src/components/verilog/comp_4bit.cpp
/qucs-core/src/components/verilog/constants.vams
/qucs-core/src/components/verilog/dff_SR.cpp
/qucs-core/src/components/verilog/disciplines.vams
/qucs-core/src/components/verilog/dmux2to4.cpp
/qucs-core/src/components/verilog/dmux3to8.cpp
/qucs-core/src/components/verilog/dmux4to16.cpp
/qucs-core/src/components/verilog/fa1b.cpp
/qucs-core/src/components/verilog/fa2b.cpp
/qucs-core/src/components/verilog/gatedDlatch.cpp
/qucs-core/src/components/verilog/greytobinary4bit.cpp
/qucs-core/src/components/verilog/ha1b.cpp
/qucs-core/src/components/verilog/hpribin4bit.cpp
/qucs-core/src/components/verilog/jkff_SR.cpp
/qucs-core/src/components/verilog/log_amp.cpp
/qucs-core/src/components/verilog/logic_0.cpp
/qucs-core/src/components/verilog/logic_1.cpp
/qucs-core/src/components/verilog/mod_amp.cpp
/qucs-core/src/components/verilog/mux2to1.cpp
/qucs-core/src/components/verilog/mux4to1.cpp
/qucs-core/src/components/verilog/mux8to1.cpp
/qucs-core/src/components/verilog/nigbt.cpp
/qucs-core/src/components/verilog/pad2bit.cpp
/qucs-core/src/components/verilog/pad3bit.cpp
/qucs-core/src/components/verilog/pad4bit.cpp
/qucs-core/src/components/verilog/photodiode.cpp
/qucs-core/src/components/verilog/phototransistor.cpp
/qucs-core/src/components/verilog/potentiometer.cpp
/qucs-core/src/components/verilog/tff_SR.cpp
/qucs-core/src/components/verilog/vcresistor.cpp
/qucs-core/src/converter/parse_spice.hpp
/qucs-core/src/converter/parse_vcd.hpp
/qucs-core/src/parse_citi.hpp
/qucs-core/src/parse_csv.hpp
/qucs-core/src/parse_dataset.hpp
/qucs-core/src/parse_mdl.hpp
/qucs-core/src/parse_netlist.hpp
/qucs-core/src/parse_touchstone.hpp
/qucs-core/src/parse_zvr.hpp
/qucs/ar-lib
/compile
2 changes: 1 addition & 1 deletion qucs-core/src/logging.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# include <config.h>
#endif

#include <stdio.h>

#include <stdlib.h>
#include <stdarg.h>

Expand Down
2 changes: 1 addition & 1 deletion qucs-core/src/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#define LOG_ERROR 0
#define LOG_STATUS 1

#include <stdio.h>
__BEGIN_DECLS

void logprint (int, const char *, ...);
Expand Down
1 change: 1 addition & 0 deletions qucs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ qucs-help/qucshelp
qucs-lib/qucslib
qucs-transcalc/qucstrans
qucs-rescodes/qucsrescodes
qucs-powercombining/qucspowercombining
qucs/qucs
debian/files
debian/qucs.debhelper.log
Expand Down
1 change: 1 addition & 0 deletions qucs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ ADD_SUBDIRECTORY( qucs-rescodes )
#ADD_SUBDIRECTORY( examples )
ADD_SUBDIRECTORY( translations )
ADD_SUBDIRECTORY( contrib )
ADD_SUBDIRECTORY(qucs-wideband-matching)


#
Expand Down
3 changes: 3 additions & 0 deletions qucs/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ SUBDIRS = \
qucs-lib \
qucs-rescodes \
qucs-transcalc \
qucs-wideband-matching \
translations \
contrib \
$(RELEASEDIRS)
Expand All @@ -48,6 +49,7 @@ app_PROGS = $(top_builddir)/qucs/qucs \
$(top_builddir)/qucs-lib/qucslib \
$(top_builddir)/qucs-edit/qucsedit \
$(top_builddir)/qucs-rescodes/qucsrescodes \
$(top_builddir)/qucs-wideband-matching/QucsWidebandMatching \
$(top_builddir)/qucs-transcalc/qucstrans

install-exec-hook: mac-install-apps mac-deploy-framework
Expand All @@ -71,6 +73,7 @@ mac-install-apps:
qucsedit) desc="Qucs Editor";; \
qucrescodes) desc="Qucs Resistor codes";; \
qucstrans) desc="Qucs Transcalc";; \
qucspowercombining) desc="Qucs Power combining";; \
esac && \
cat $(srcdir)/Info.plist | \
sed -e "s/@version@/$(PACKAGE_VERSION)/g" | \
Expand Down
1 change: 1 addition & 0 deletions qucs/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,7 @@ AC_CONFIG_FILES([Makefile
qucs-lib/library/Makefile
qucs-attenuator/Makefile
qucs-rescodes/Makefile
qucs-wideband-matching/Makefile
qucs/Makefile
qucs/octave/Makefile
qucs/components/Makefile
Expand Down
159 changes: 159 additions & 0 deletions qucs/qucs-wideband-matching/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
PROJECT(QucsWidebandMatching CXX C)
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
cmake_policy(VERSION 2.6)

# use top VERSION file
file (STRINGS ${PROJECT_SOURCE_DIR}/../VERSION QUCS_VERSION)
message(STATUS "Configuring ${PROJECT_NAME} (GUI): VERSION ${QUCS_VERSION}")

set(PROJECT_VERSION "${QUCS_VERSION}")

set(PROJECT_VENDOR "Qucs team. This program is licensed under the GNU GPL")
set(PROJECT_COPYRIGHT_YEAR "2016")
set(PROJECT_DOMAIN_FIRST "qucs")
set(PROJECT_DOMAIN_SECOND "org")

SET(CMAKE_BUILD_TYPE Debug)

ADD_DEFINITIONS( -DHAVE_CONFIG_H )

# define variables
SET(BINARYDIR "${CMAKE_INSTALL_PREFIX}/bin/")
#SET(BITMAPDIR "${CMAKE_INSTALL_PREFIX}/share/qucs/bitmaps/")
SET(DOCDIR "${CMAKE_INSTALL_PREFIX}/share/qucs/docs/")
SET(LANGUAGEDIR "${CMAKE_INSTALL_PREFIX}/share/qucs/lang/")
SET(LIBRARYDIR "${CMAKE_INSTALL_PREFIX}/share/qucs/library/")
SET(OCTAVEDIR "${CMAKE_INSTALL_PREFIX}/share/qucs/octave/")

# configure the header config.h
CONFIGURE_FILE (
"${PROJECT_SOURCE_DIR}/../config.h.cmake"
"${PROJECT_BINARY_DIR}/config.h"
)

INCLUDE_DIRECTORIES("${PROJECT_BINARY_DIR}")

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall ") # enable warning level
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x ") # enable C++11

# flag not available in mingw 4.8.2, MSVC10
IF(NOT WIN32)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-register ")
ENDIF()

FIND_PACKAGE( Qt4 REQUIRED )
SET( QT_USE_QTGUI TRUE )

INCLUDE( ${QT_USE_FILE} )

ADD_DEFINITIONS(${QT_DEFINITIONS})

#ADD_SUBDIRECTORY( bitmaps ) -> added as resources

SET( wb_matching_sources main.cpp ui.cpp io.cpp MathOperations.cpp mat.cpp sparengine.cpp GRABIM.cpp)

SET( wb_matching_moc_headers ui.h io.h MathOperations.h mat.h sparengine.h GRABIM.h)

QT4_WRAP_CPP( wb_matching_moc_sources ${wb_matching_moc_headers} )

SET(RESOURCES QucsWidebandMatching.qrc)

QT4_ADD_RESOURCES(RESOURCES_SRCS ${RESOURCES})

IF(APPLE)
# set information on Info.plist file
SET(MACOSX_BUNDLE_INFO_STRING "${PROJECT_NAME} ${PROJECT_VERSION}")
SET(MACOSX_BUNDLE_BUNDLE_VERSION "${PROJECT_NAME} ${PROJECT_VERSION}")
SET(MACOSX_BUNDLE_LONG_VERSION_STRING "${PROJECT_NAME} ${PROJECT_VERSION}")
SET(MACOSX_BUNDLE_SHORT_VERSION_STRING "${PROJECT_VERSION}")
SET(MACOSX_BUNDLE_COPYRIGHT "${PROJECT_COPYRIGHT_YEAR} ${PROJECT_VENDOR}")
SET(MACOSX_BUNDLE_GUI_IDENTIFIER "${PROJECT_DOMAIN_SECOND}.${PROJECT_DOMAIN_FIRST}")
SET(MACOSX_BUNDLE_BUNDLE_NAME "${PROJECT_NAME}")
SET(MACOSX_BUNDLE_ICON_FILE QucsWidebandMatching.icns)

# set where in the bundle to put the icns file
SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_SOURCE_DIR}/../qucs/bitmaps/QucsWidebandMatching.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
# include the icns file in the target
SET(attenuator_sources ${attenuator_sources} ${CMAKE_CURRENT_SOURCE_DIR}/../qucs/bitmaps/QucsWidebandMatching.icns)

ENDIF(APPLE)

ADD_EXECUTABLE( QucsWidebandMatching MACOSX_BUNDLE WIN32
${attenuator_sources}
${attenuator_moc_sources}
${RESOURCES_SRCS} )

TARGET_LINK_LIBRARIES( QucsWidebandMatching ${QT_LIBRARIES} )

#INSTALL (TARGETS qucsattenuator DESTINATION bin)
#
# Prepare the installation
#
SET(plugin_dest_dir bin)
SET(qtconf_dest_dir bin)
SET(APPS "${CMAKE_INSTALL_PREFIX}/bin/${PROJECT_NAME}")
IF(APPLE)
SET(plugin_dest_dir ${PROJECT_NAME}.app/Contents/MacOS)
SET(qtconf_dest_dir ${PROJECT_NAME}.app/Contents/Resources)
SET(APPS "${CMAKE_INSTALL_PREFIX}/bin/${PROJECT_NAME}.app")
ENDIF(APPLE)

IF(WIN32)
SET(APPS "${CMAKE_INSTALL_PREFIX}/bin/${PROJECT_NAME}.exe")
ENDIF(WIN32)

#
# Install the Qucs application, on Apple, the bundle is
# installed as on other platforms it'll go into the bin directory.
#
INSTALL(TARGETS ${PROJECT_NAME}
BUNDLE DESTINATION bin COMPONENT Runtime
RUNTIME DESTINATION bin COMPONENT Runtime
)

# man pages
INSTALL( FILES QucsWidebandMatching.1 DESTINATION share/man/man1 )


#
# Install needed Qt plugins by copying directories from the qt installation
# One can cull what gets copied by using 'REGEX "..." EXCLUDE'
#
IF(APPLE)
INSTALL(DIRECTORY "${QT_PLUGINS_DIR}/imageformats" DESTINATION bin/${plugin_dest_dir}/plugins COMPONENT Runtime)
ENDIF()
#
# install a qt.conf file
# this inserts some cmake code into the install script to write the file
#
IF(APPLE)
INSTALL(CODE "
file(WRITE \"\${CMAKE_INSTALL_PREFIX}/bin/${qtconf_dest_dir}/qt.conf\" \"\")
" COMPONENT Runtime)
ENDIF()

#--------------------------------------------------------------------------------
# Use BundleUtilities to get all other dependencies for the application to work.
# It takes a bundle or executable along with possible plugins and inspects it
# for dependencies. If they are not system dependencies, they are copied.

# directories to look for dependencies
IF(APPLE)
SET(DIRS ${QT_LIBRARY_DIRS})
ENDIF()

# Now the work of copying dependencies into the bundle/package
# The quotes are escaped and variables to use at install time have their $ escaped
# An alternative is the do a configure_file() on a script and use install(SCRIPT ...).
# Note that the image plugins depend on QtSvg and QtXml, and it got those copied
# over.
IF(APPLE)
INSTALL(CODE "
file(GLOB_RECURSE QTPLUGINS
\"\${CMAKE_INSTALL_PREFIX}/bin/${plugin_dest_dir}/plugins/*${CMAKE_SHARED_LIBRARY_SUFFIX}\")
include(BundleUtilities)
fixup_bundle(\"${APPS}\" \"\${QTPLUGINS}\" \"${DIRS}\")
" COMPONENT Runtime)
ENDIF()


Loading

0 comments on commit 20e3cd4

Please sign in to comment.