Commit 5e078929 authored by thomas.forbriger's avatar thomas.forbriger Committed by thomas.forbriger
Browse files

new filter set compiles

This is a legacy commit from before 2015-03-01.
It may be incomplete as well as inconsistent.
See COPYING.legacy and README.history for details.


SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/trunk
SVN Revision: 1279
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 4e0f8654
# this is <Makefile>
# ----------------------------------------------------------------------------
# $Id: Makefile,v 1.3 2002-11-13 18:51:51 forbrig Exp $
# $Id: Makefile,v 1.4 2003-01-05 17:36:51 forbrig Exp $
#
# Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
#
......@@ -14,9 +14,9 @@
# ============================================================================
#
all: libfourier.a libfourier.doc
all: libfourier.a libfourier.doc install-include libfourierxx.a
flist: Makefile $(wildcard *.f *.inc)
flist: Makefile $(wildcard *.f *.inc *.h *.cc)
echo $^ | tr ' ' '\n' | sort > $@
.PHONY: edit
......@@ -55,8 +55,15 @@ docs: $(DOCS)
%.o77: %.f
$(FC) $(FFLAGS) -c -o $@ $<
.PHONY: clean
clean:
-/bin/rm -fv *.o *.bak *.doc *.o77 flist
-find . -name \*.bak | xargs --no-run-if-empty /bin/rm -v
-find . -name \*.o | xargs --no-run-if-empty /bin/rm -v
-find . -name \*.d | xargs --no-run-if-empty /bin/rm -v
-find . -name \*.h.strip | xargs --no-run-if-empty /bin/rm -v
-/bin/rm -vf flist *.o install-include *.xxx junk*
cd tests; $(MAKE) clean
libfourier.doc: $(LIBSRC) $(wildcard *.inc)
makefdoc.pl $@ $^
......@@ -70,4 +77,188 @@ libfourier.a: $(LIBOBS)
$(RANLIB) $@
newlib $@
# ============================================================================
#
#
# A note on header files:
# We extensively comment class declarations within the header files. The
# reduce compilation time when using the library code, comments will be
# stripped from the header files that are exportet. These stripped versions
# are placed in the source code path with name *.h.strip and will be linked to
# INCINSTALLPATH with name *.h.
#
# Although comment stripping could be done by perl with an elaborate regular
# expression, we prefer the remcmmnt command by Jari Laaksonen. You can find
# the code at
# http://www.eti.pg.gda.pl/KATEDRY/kecs/lab-cpp/snippets/
# If it is not available to you, you should set REMCMMNT=cat (see below)
#
# REVISIONS and CHANGES
# 30/12/2002 V1.0 Thomas Forbriger
#
# ============================================================================
#
# environment variables
# ---------------------
#
# You will like to set the following environment variables:
#
# LOCINCLUDEDIR Defines the path where header files will be copied for
# usage in your own projects. You will pass this path to
# the precompiler with the -I option.
# LOCLIBDIR Defines the path where the binary library will be
# placed.
# WWWBASEDIR Defines the path to your personal homepage. That's the
# place where doxygen output will be written too (see
# below).
#
# You will find the installed library header files in $(LOCINCLUDEDIR)/aff
# files
# -----
# all header files used within this project
HEADERS=$(shell find . -name \*.h)
# all source code to be compiled to object files and to be included
# in the binary version of the library
# (see below for the configuration of a preinstantiated version of template
# code)
SRC=fcommand.cc filter.cc polesnzeroes.cc
# test programs are placed in a subdirectory
TESTS=$(wildcard tests/*.cc)
# whereever we find a README, we will use it
README=$(shell find . -name README)
# place where we will copy header files
INCINSTALLPATH=$(LOCINCLUDEDIR)/fourier
# place where we will copy the binary library
LIBINSTALLPATH=$(LOCLIBDIR)
# name of headers with comments stripped off (these are linked to your include
# directory)
STRIPHEADER=$(addsuffix .strip,$(notdir $(HEADERS)))
# name of installed (exported) header files (these are the names in your
# include directory)
INSTHEADER=$(addprefix $(INCINSTALLPATH)/,$(filter-out ./tests/%,$(HEADERS)))
# if defined, empty lines are kept in comment-stripped headers
# to synchronize line numbers (necessary during library debugging)
EMPTYPRINT=1
#EMPTYPRINT=0
# define this to be cat in case you do not have remcmmnt available
REMCMMNT=remcmmnt
#REMCMMNT=cat
# compiler and preprocessor flags
FLAGS=
CXXFLAGS=-Wall -pedantic $(FLAGS) -O3
CXXFLAGS=-Wall $(FLAGS) -O3
LDFLAGS=-L$(LOCLIBDIR)
CPPFLAGS=-I$(LOCINCLUDEDIR) $(FLAGS)
LIBOBSXX=$(patsubst %.cc,%.o,$(SRC))
libfourierxx.a: install-include $(LIBOBSXX)
ar rcv $@ $(LIBOBS)
ranlib $@
cp -vpf $@ $(LIBINSTALLPATH)
#======================================================================
# dependencies
# ------------
#
# The compiler is used to create dependency files, which are included below.
%.d: %.cc
$(SHELL) -ec '$(CXX) -M $(CPPFLAGS) $(TMPPARDEF) $< \
| sed '\''s,\($(notdir $*)\)\.o[ :]*,$(dir $@)\1.o $@ : ,g'\'' \
> $@; \
[ -s $@ ] || rm -f $@'
-include $(patsubst %.cc,%.d,$(SRC))
#======================================================================
# header files
# ------------
#
# Since we extensively document the class structures within the header files,
# these should be stripped for the production version (otherwise the compiler
# has to scan all comments on each compile). Stripping is done by the rule
# below and is controlled by the variables REMCMMNT and EMPTYPRINT (see
# above).
# comment stripping
# -----------------
# awk rule assumes that the first non-comment line starts with '#'
# and that the first (copyright) comment end with pattern "^ */"
%.h.strip: %.h
awk 'BEGIN {hot=1;} /^ \*\// { if (hot) { hot=2; print; next;} }\
/^#/ { hot=0; } \
{ if (hot==2) { print ""; } else if (hot) { print; } }' $< > $@
$(REMCMMNT) $< | awk 'BEGIN {hot=0;} \
/^ *$$/ { if ((hot) && ($(EMPTYPRINT))) { print ""; } next; } \
/^#/ { hot=1; } { if (hot) print; }' >> $@
#----------------------------------------------------------------------
.PRECIOUS: %.h.strip
$(INCINSTALLPATH)/%.h: %.h.strip
mkdir -vp $(dir $@)
-rm -fv $@
ln -svf $$(pwd)/$< $@
# install header files
install-include: $(INSTHEADER)
echo $^ | tr ' ' '\n'
touch $@
#======================================================================
# documentation part
# ------------------
#
# targets commonly used:
# ----------------------
#
# make doxyclean removes all documentation
# make doxydoc creates doxygen documentation in the DOXYWWWPATH
# make doxyview creates doxygen documentation and launches netscape to
# browse in the documentation
# make doxyfullconf edit the doxygen configuration file
#
# The targets are prepared for two documentation configurations. There is a
# "full" configuration defined in doxyfull.cfg and a "brief" configuration in
# doxybrief.cfg. However doxygen itself does not really support to distinguish
# between brief and full just due to the config-file. So just use the doxyfull
# target.
#
# If you launch "make doxyfull" the documentation will be written to
# DOXYWWWPATH (see below). This is meant to export the documentation through
# your homepage. The doxyfull directory is just a symbolic link to this
# directory.
#
DOXYWWWPATH=$(WWWBASEDIR)/libfourier
.PHONY: doxyclean doxyview doxybriefview doxyfullconf doxybriefconf
doxyclean: ;/bin/rm -rfv docfull/* docbrief docfull
DOXYSRC=$(README) $(HEADERS) $(SRC)
doc%/html/index.html: doxy%.cfg $(DOXYSRC)
mkdir -vp $(DOXYWWWPATH)
ln -sfv $(DOXYWWWPATH) $(patsubst doxy%.cfg,doc%,$<)
doxygen $<
doxybriefconf doxyfullconf: doxy%conf:
doxywizard $(patsubst doxy%conf,doxy%.cfg,$@)
doxyfull doxybrief: doxy%: doxyclean doc%/html/index.html
doxydoc: doxyfull
doxyfullview doxybriefview: doxy%view: doxy%
netscape doc$(patsubst doxy%view,%,$@)/html/index.html &
doxyview: doxydoc doxyfullview
# ----- END OF Makefile -----
/*! \file fcommand.cc
* \brief process filter commands (implementation)
*
* ----------------------------------------------------------------------------
*
* $Id: fcommand.cc,v 1.1 2003-01-05 17:36:51 forbrig Exp $
* \author Thomas Forbriger
* \date 05/01/2003
*
* process filter commands (implementation)
*
* Copyright (c) 2003 by Thomas Forbriger (IMG Frankfurt)
*
* REVISIONS and CHANGES
* - 05/01/2003 V1.0 Thomas Forbriger
*
* ============================================================================
*/
#define TF_FCOMMAND_CC_VERSION \
"TF_FCOMMAND_CC V1.0 "
#define TF_FCOMMAND_CC_CVSID \
"$Id: fcommand.cc,v 1.1 2003-01-05 17:36:51 forbrig Exp $"
#include <fourier/fcommand.h>
#include <fstream>
#include <string>
#include <sstream>
#include <tfxx/error.h>
using std::cout;
using std::endl;
namespace fourier {
void FilterCommands::FilterCommands::help() const
{
cout << "filter library commands:" << endl;
cout << "rem any comment (ignored)" << endl;
cout << "# any comment (ignored)" << endl;
cout << "dif differentiate" << endl;
cout << "int integrate" << endl;
cout << "lp2 in,h second order low-pass (see foufil_lp2)" << endl;
cout << "hp2 in,h second order high-pass (see foufil_hp2)" << endl;
cout << "lpb in,ord "
<< "Butterworth low-pass of order ord (see foufil_lpb)" << endl;
cout << "hpb in,ord "
<< "Butterworth high-pass of order ord (see foufil_hpb)" << endl;
cout << "fac factor mutiply by factor" << endl;
cout << "mod normal "
<< "switch back to normal filters (default)" << endl;
cout << "mod inverse switch to inverse filters" << endl;
cout << "mod period "
<< "switch to specification by period (default)" << endl;
cout << "mod frequency switch to specification by frequency " << endl;
cout << "end terminate file reading" << endl;
cout << endl;
cout << TF_FCOMMAND_H_VERSION << endl;
cout << TF_FCOMMAND_H_CVSID << endl;
cout << TF_FILTERS_H_VERSION << endl;
cout << TF_FILTERS_H_CVSID << endl;
cout << TF_POLESNZEROES_H_VERSION << endl;
cout << TF_POLESNZEROES_H_CVSID << endl;
}
/*----------------------------------------------------------------------*/
void FilterCommands::read(const char* filename)
{
std::ifstream ifs(filename);
read(ifs);
}
/*----------------------------------------------------------------------*/
void FilterCommands::read(std::istream& is)
{
bool hot=is.good();
std::string line;
while(hot)
{
std::getline(is, line);
hot=command(line.c_str()) && is.good();
}
}
/*----------------------------------------------------------------------*/
bool FilterCommands::command(const char* command)
{
bool result=true;
std::string cmd(command);
std::istringstream cmdline(cmd);
std::string token;
cmdline >> token;
double par, h;
int ord;
if (token.find("rem")!=std::string::npos)
{ } else if (token.find("#")!=std::string::npos)
{ } else if (token.find("dif") != std::string::npos)
{ setdif();
} else if (token.find("int") != std::string::npos)
{ setint();
} else if (token.find("lp2") != std::string::npos)
{ cmdline >> par >> h; setlp2(par, h);
} else if (token.find("lpb") != std::string::npos)
{ cmdline >> par >> ord; setlpb(par, ord);
} else if (token.find("hp2") != std::string::npos)
{ cmdline >> par >> h; sethp2(par, h);
} else if (token.find("hpb") != std::string::npos)
{ cmdline >> par >> ord; sethpb(par, ord);
} else if (token.find("fac") != std::string::npos)
{ cmdline >> par; numfactor(par);
} else if (token.find("mod") != std::string::npos)
{
cmdline >> token;
if (token.find("frequency")!=std::string::npos)
{ setfreqmod();
} else if (token.find("period")!=std::string::npos)
{ setpermod();
} else if (token.find("normal")!=std::string::npos)
{ setnormal();
} else if (token.find("inverse")!=std::string::npos)
{ setinverse();
} else
{ TFXX_abort("ERROR (FilterCommands): illegal mode!"); }
} else if (token.find("end") != std::string::npos)
{ result=false;
} else
{ TFXX_abort("ERROR (FilterCommands): illegal command!"); }
return(result);
}
} // namespace fourier
/* ----- END OF fcommand.cc ----- */
/*! \file fcommand.h
* \brief evaluate filter commands (prototypes)
*
* ----------------------------------------------------------------------------
*
* $Id: fcommand.h,v 1.1 2003-01-05 17:36:51 forbrig Exp $
* \author Thomas Forbriger
* \date 05/01/2003
*
* evaluate filter commands (prototypes)
*
* Copyright (c) 2003 by Thomas Forbriger (IMG Frankfurt)
*
* REVISIONS and CHANGES
* - 05/01/2003 V1.0 Thomas Forbriger
*
* ============================================================================
*/
// include guard
#ifndef TF_FCOMMAND_H_VERSION
#define TF_FCOMMAND_H_VERSION \
"TF_FCOMMAND_H V1.0 "
#define TF_FCOMMAND_H_CVSID \
"$Id: fcommand.h,v 1.1 2003-01-05 17:36:51 forbrig Exp $"
#include<iostream>
#include<fourier/filters.h>
namespace fourier {
class FilterCommands: public Filter {
public:
typedef Filter Tbase;
typedef Tbase::Tcvalue Tcvalue;
FilterCommands(): Tbase() { }
FilterCommands(const char* filename): Tbase() { read(filename); }
FilterCommands(std::istream& is): Tbase() { read(is); }
void help() const;
void read(std::istream& is);
void read(const char* filename);
bool command(const char* command);
}; // class FilterCommands
} // namespace fourier
#endif // TF_FCOMMAND_H_VERSION (includeguard)
/* ----- END OF fcommand.h ----- */
/*! \file filter.cc
* \brief filter types (implementation)
*
* ----------------------------------------------------------------------------
*
* $Id: filter.cc,v 1.1 2003-01-05 17:36:51 forbrig Exp $
* \author Thomas Forbriger
* \date 05/01/2003
*
* filter types (implementation)
*
* Copyright (c) 2003 by Thomas Forbriger (IMG Frankfurt)
*
* REVISIONS and CHANGES
* - 05/01/2003 V1.0 Thomas Forbriger
*
* ============================================================================
*/
#define TF_FILTER_CC_VERSION \
"TF_FILTER_CC V1.0 "
#define TF_FILTER_CC_CVSID \
"$Id: filter.cc,v 1.1 2003-01-05 17:36:51 forbrig Exp $"
#include <fourier/filters.h>
#include <tfxx/error.h>
namespace fourier {
const double Filter::pi;
const Filter::Tcvalue Filter::ime=Tcvalue(0.,1.);
/*----------------------------------------------------------------------*/
Filter::Tcvalue Filter::omega(const Filter::Tcvalue& par) const
{
Tcvalue retval;
if (isfreqmod()) { retval=2.*pi*par; } else { retval=2.*pi/par; }
return(retval);
}
/*----------------------------------------------------------------------*/
void Filter::setint()
{
this->Tbase::setpole(Tcvalue(0.,0.));
this->Tbase::denfactor(Tcvalue(0.,1.));
}
/*----------------------------------------------------------------------*/
void Filter::setdif()
{
this->Tbase::setzero(Tcvalue(0.,0.));
this->Tbase::numfactor(Tcvalue(0.,1.));
}
/*----------------------------------------------------------------------*/
void Filter::sethpb(const Filter::Tcvalue& par, const int& ord)
{
Tcvalue om=omega(par);
TFXX_assert((ord>0), "ERROR (Filter hpb): illegal order!");
for (int i=1; i<=ord; ++i)
{
this->Tbase::setzero(Tcvalue(0.,0.));
Tcvalue pole=om*std::exp(ime*pi*(2.*i-1.)/(2.*ord));
this->Tbase::setpole(pole);
}
}
/*----------------------------------------------------------------------*/
void Filter::setlpb(const Filter::Tcvalue& par, const int& ord)
{
Tcvalue om=omega(par);
TFXX_assert((ord>0), "ERROR (Filter lpb): illegal order!");
for (int i=1; i<=ord; ++i)
{
this->Tbase::numfactor(-ime*om);
Tcvalue pole=om*std::exp(ime*pi*(2.*i-1.)/(2.*ord));
this->Tbase::setpole(pole);
}
}
/*----------------------------------------------------------------------*/
void Filter::sethp2(const Filter::Tcvalue& par, const double& h)
{
Tcvalue om=omega(par);
this->Tbase::setzero(Tcvalue(0.,0.));
this->Tbase::setzero(Tcvalue(0.,0.));
Tcvalue pole=om*(ime*h+std::sqrt(1.-h*h));
this->Tbase::setpole(pole);
pole=om*(ime*h-std::sqrt(1.-h*h));
this->Tbase::setpole(pole);
}
/*----------------------------------------------------------------------*/
void Filter::setlp2(const Filter::Tcvalue& par, const double& h)
{
Tcvalue om=omega(par);
this->Tbase::numfactor(-ime*om);
this->Tbase::numfactor(-ime*om);
Tcvalue pole=om*(ime*h+std::sqrt(1.-h*h));
this->Tbase::setpole(pole);
pole=om*(ime*h-std::sqrt(1.-h*h));
this->Tbase::setpole(pole);
}
} // namespace fourier
/* ----- END OF filter.cc ----- */
/*! \file filters.h
* \brief provides specific filters (prototypes)
*
* ----------------------------------------------------------------------------
*
* $Id: filters.h,v 1.1 2003-01-05 17:36:51 forbrig Exp $
* \author Thomas Forbriger
* \date 05/01/2003
*
* provides specific filters (prototypes)
*
* Copyright (c) 2003 by Thomas Forbriger (IMG Frankfurt)
*
* REVISIONS and CHANGES
* - 05/01/2003 V1.0 Thomas Forbriger
*
* ============================================================================
*/
// include guard
#ifndef TF_FILTERS_H_VERSION
#define TF_FILTERS_H_VERSION \
"TF_FILTERS_H V1.0 "
#define TF_FILTERS_H_CVSID \
"$Id: filters.h,v 1.1 2003-01-05 17:36:51 forbrig Exp $"
#include<fourier/polesnzeroes.h>
namespace fourier {
class Filter: public PolesNZeroes {
public:
typedef PolesNZeroes Tbase;
typedef Tbase::Tcvalue Tcvalue;
static const double pi=3.141592653589793;
static const Tcvalue ime;
Filter(): Tbase(), Mfrequency(true) { }
void clear() { this->Tbase::clear(); Mfrequency=true; }
void setfreqmod() { Mfrequency=true; }
void setpermod() { Mfrequency=false; }
bool isfreqmod() const { return(Mfrequency); }
bool ispermod() const { return(!Mfrequency); }
Tcvalue eval(const double& omega) const
{ return(this->eval(Tcvalue(omega))); }
Tcvalue eval(const Tcvalue& par) const
{ return(this->Tbase::operator()(omega(par))); }
Tcvalue omega(const Tcvalue& par) const;
void setint();
void setdif();
void sethpb(const Tcvalue& par, const int& ord);
void sethpb(const double& par, const int& ord)
{ sethpb(Tcvalue(par), ord); }
void setlpb(const Tcvalue& par, const int& ord);
void setlpb(const double& par, const int& ord)
{ setlpb(Tcvalue(par), ord); }
void sethp2(const Tcvalue& par, const double& h);
void sethp2(const double& par, const double& h)
{ sethp2(Tcvalue(par), h); }
void setlp2(const Tcvalue& par, const double& h);
void setlp2(const double& par, const double& h)
{ setlp2(Tcvalue(par), h); }
private:
// use frequency (or period)
bool Mfrequency;
}; // class Filter
} // namespace fourier
#endif // TF_FILTERS_H_VERSION (includeguard)
/* ----- END OF filters.h ----- */
/*! \file polesnzeroes.cc
* \brief pole and zero filters (implementation)
*
* ----------------------------------------------------------------------------
*