diff --git a/Build b/Build new file mode 100644 index 0000000..21ecc9f --- /dev/null +++ b/Build @@ -0,0 +1,6 @@ +#! /bin/bash +# I'm still using Gtk2! +g++ -g `pkg-config --cflags gtk+-2.0 gdk-2.0 libgnome-2.0 libgnomeui-2.0 gdk-pixbuf-xlib-2.0` -o rbfilter ./rbfilter.cpp ./Calcs.cpp ./Rauch.cpp ./Sallen_and_Key.cpp ./Discrete.cpp `pkg-config --libs gtk+-2.0 gdk-2.0 libgnome-2.0 libgnomeui-2.0 gdk-pixbuf-xlib-2.0` +echo "Done!" +read + diff --git a/Calcs.cpp b/Calcs.cpp new file mode 100644 index 0000000..d25ae40 --- /dev/null +++ b/Calcs.cpp @@ -0,0 +1,1039 @@ +/** \file +'Calcs.cpp' is one of the files intended to hold the functions for +calculation purposes. + +It is not involved with GUIs and so it is expected that it will not (or +barely) need editting for porting to a different OS. +*/ + +// *************************** +// #include +// #pragma hdrstop +#include +#include "math.h" +#include "Calcs.h" +#include +#include +#include +#include +// #include "filter.h" +// #include "control.h" +// *************************** + +#if SHOW_FILE_COMPILING +#pragma message "Compiling Calcs.cpp" +#endif + +TFilter filter; + +TFilter::TFilter( ) +{ + fclass = Lowpass; + sclass = Bessel; + cclass = SallKey; + frequency = 1.0; + bandwidth = 0.25; + gain = 1.0; + poles = 3; + zeroes = 0; + fmax = tmax = 2.0; + ripple = 0.1; + a0 = 0.70794578; + type = '0'; // 'Prototype' filter. +} + + + +double isinh(double x) +{ + double y=1.0; + do { + y+=(x-sinh(y))/cosh(y); + } while(((sinh(y)-x)/x) >=0.001); + return(y); +} + + + +double n_to_freq(int n, double f1, int nmax=FSTEPS, int decades=2) +{ + return(f1 * pow10(double(n) * decades / nmax)); +} + + + + +using namespace std; + +// void bessel(TFilter& filter); +// void butterworth(TFilter& filter); +// void chebyshev(TFilter& filter); +// void lowpass(TFilter& filter, double f); +// void highpass(TFilter& filter); + +void geffe(double sigma, double omega, double w0, double bw, double &a1, double &b1, double &a2, double &b2); + +double atof(string s) +{ + double d; + sscanf(s.c_str(), "%lf", &d); + return(d); +} + + + +void +TFilter::_pole(double a, double w) +{ +// Draw pole at (a,w). +int aa, ww; + +#if VERBOSE + cout << "Pole at " << a << ", " << w << "\n"; +#endif +} + + + +void TFilter::show_filter(void) +{ + int i; +#if VERBOSE + cout << "No of poles:" << poles << "\n"; + cout << "No of zeroes:" << zeroes << "\n"; + + for(i=0; ifclass = f1.fclass; + this->cclass = f1.cclass; + this->T = f1.T; + this->q = f1.q; + this->pole = f1.pole; + this->zero = f1.zero; +} + + + +/// Put the poles into falling order of imaginary part. As only a few objects are to be sorted, use a bubble sort. +void TFilter::sort(void) +{ + stage s0; + int i, j; + for(j=0; j < poles-1; j++) for(i=0; i < poles-1; i++) { + if(st[i].pole.imag( ) < st[i+1].pole.imag( )) { + // poles in wrong order, swap them. + s0.pole = st[i].pole; + st[i].pole = st[i+1].pole; + st[i+1].pole = s0.pole; + } + } +} + + + +double TFilter::fgain(double f) +{ + unsigned i, k; + double t, q; + complex j = std::complex(0.0, 1.0); + complex s, r; + double rf; + rf = 1.0; + for(k=0; k<(poles/2); k++) { + t = st[k].T, q = st[k].q; + s = std::complex(0.0, (2.0*M_PI)*f); + r = 1.0/(1.0+s*t/q+s*s*t*t); + rf *= abs(r); + } + if(k < (poles+1)/2) { + s = std::complex(0.0, (2.0*M_PI)*f); + r = 1.0/(1.0+s*tau); + rf *= abs(r); + } + return(rf); +} + + + +/// We want to normalise the filter so the cut-off is at 1.0 radians per second. +void TFilter::Proto_normalise(void) +{ + int k; + double f, f1; + double g, g1; + char logstr[256]; + log("\n"); + for(f = 0.1; f < 10.0; f *= 1.01) { + g = fgain(f); + if(g < a0) break; + g1 = g; + f1 = f; + } +// std::cout << "Gain is " << g1 << " at " << f1 << ", and " << g << " at " << f << "\n"; + sprintf(logstr, "Prototype gain is %f at %f, and %f at %f", g1, f1, g, f); + log(logstr); + f = 2.0 * M_PI * (f * (-a0 + g1) + f1 * (-g + a0)) / (-g + g1); + for(k=0; k<(poles); k++) { + st[k].pole /= f; + } + + std::cout << "f = " << f << "\n"; + show_filter("Normalised prototype"); + log("\n"); +} + + + +/** +Calculate the t and q values for each stage from the poles with +positive imaginary parts (i.e. one of each pair), and if the +number of poles is odd, calculate the tau value from the remaining +pole. +*/ +void TFilter::ts_and_qs(void) +{ + unsigned i, j, k; + double theta; + double tt, qq; + + log(""); + +#if VERBOSE + cout << "ts_and_qs\n"; +#endif + switch(fclass) { + case Lowpass: k = poles/2; break; + case Highpass: k = poles/2; break; + case Bandpass: k = poles; break; + } + + for(i=0, j=0; i"); +} + + + +void TFilter::butterworth(void) +{ + unsigned i; + double theta; + double tt, qq; + log(""); + theta=M_PI/(2.0*poles); + for(i=0; i(-sin(theta)*2.0*M_PI, 0.0); + st[i].pole = std::complex (-sin(theta), 0.0); + } else { +// pole[i] = std::complex (-sin(theta)*2.0*M_PI, cos(theta)*2.0*M_PI); + st[i].pole = std::complex (-sin(theta), cos(theta)); + } + log("pole at ", st[i].pole); + theta += M_PI/poles; + } + + type = 'P'; + + log("/Butterworth"); +} + + + +void +TFilter::bessel(void) +{ +int i, j, k, nn; +double a[20], b[20], bb[20], bbb[20], aa[10], ww[10], limit, p, q, + qq, tt, dd, t, w; + std::ofstream file; + int n; + + log(""); + n = poles; + /// Bessel-Thomson filter design. + if((n<3)||(n>19)) { + cout << "Unreasonable order.\n"; + return; + } + nn=n; + limit=exp(std::log(3.5)*n)*0.00001; + /// Evaluate the terms of the polynomial. + for(i=0; i<=19; i++) a[i]=b[i]=bb[i]=bbb[i]=0; + bbb[0]=bbb[1]=1.0; + bb[0]=bb[1]=3.0, bb[2]=1.0; + for(i=3; i<=n; i++) { + for(j=0; j<=n; j++)b[j]=(2*i-1)*bb[j]; + for(j=2; j<=n; j++) b[j]+=bbb[j-2]; + for(j=0; j<=n; j++) { + bbb[j]=bb[j]; + bb[j]=b[j]; + } + } +#if VERBOSE + cout << "Bessel polynomial:\n"; + for(i=0; i<=n; i++) cout << "a[" << i << "]=" << b[i] << " "; cout << "\n"; +#endif + for(i=0; i<=n; i++) a[n-i]=b[i]; + k=0; + file.open("pfile.z"); + if(!file) { + cout << "\nUnable to open 'pfile.z'\n"; + return; + } + file << "Bessel: P " << n << " " << 0; + // 440 + int pp = 0; + do { + p=q=0.01; + do { + b[0]=a[0]; + b[1]=a[1]-b[0]*p; + for(i=2; i<=n;i++) b[i]=a[i]-b[i-2]*q-b[i-1]*p; + if(b[n-2]==0) b[n-2]=0.000001; + q=a[n]/b[n-2]; //530 + p=(a[n-1]-b[n-3]*q)/b[n-2]; + } while((abs(b[n-1]) >= limit) || (abs(b[n]) >= limit)); + cout << "Solution at " << -p/2.0 << " +/- j*" << sqrt(q-(p*p/4.0)) << "\n"; + file << " " << -p/2.0 << " " << sqrt(q-(p*p/4.0)) << "\n"; + st[pp++].pole = complex(-p/2.0, sqrt(q-(p*p/4.0))); + st[pp++].pole = complex(-p/2.0, -sqrt(q-(p*p/4.0))); + aa[k]=-p/2.0, ww[k]=sqrt(q-(p*p/4.0)); + k++; + for(i=0; i<=n; i++) a[i]=b[i]; + n-=2; + } while(n>2); + if(n==1) { + // 720 + cout << "Solution at " << -b[1]/b[0] << "\n"; + file << " " << -b[1]/b[0]; + st[pp++].pole = complex(-b[1]/b[0], 0.0); + } else { + //660 + cout << "Solution' at " << -a[1]/(2.0*a[0]); + cout << " +/-j*" << (sqrt(-a[1]*a[1]+4.0*a[0]*a[2])/(2.0*a[0])); + file << " " << -a[1]/(2.0*a[0]) << " " << sqrt(-a[1]*a[1]+4.0*a[0]*a[2])/(2.0*a[0]); + st[pp++].pole = complex(-a[1]/(2.0*a[0]), sqrt(-a[1]*a[1]+4.0*a[0]*a[2])/(2.0*a[0])); + st[pp++].pole = complex(-a[1]/(2.0*a[0]), -sqrt(-a[1]*a[1]+4.0*a[0]*a[2])/(2.0*a[0])); + k++; + } + file.close(); + + for(i=0; i<=nn/2; i++) { + _pole(aa[i]/3.0, ww[i]/3.0); + _pole(aa[i]/3.0, -ww[i]/3.0); + } + if(nn%2) { + _pole(-b[1]/(3.0*b[0]), 0); +// pole[nn - 1] = complex(-b[1]/(3.0*b[0], 0.0)); + } + +#if VERBOSE + cout << "\nEndBessel\n"; +#endif + + // 940 + if(dd!='D') ; + type = 'P'; + + log(""); +} + + + +void +TFilter::chebyshev(void) +{ +char dump; + +int i; + +double aa[20], ww[20], g, a, w, tt, qq; + + // Chebyshev filter design. + log(""); + unsigned n = poles; + g = ripple; + + for(i=1; i<=n; i++) { + a=-sin((2*i-1)*M_PI/(2*n))*sinh(isinh(1.0/g)/n); + + w=cos((2*i-1)*M_PI/(2*n))*cosh(isinh(1.0/g)/n); + + if(fabs(w)<1e-9) w=0; + + st[i-1].pole = complex(a, w); + + cout << "\n" << a << ", " << w; + aa[i]=-a, ww[i]=w; + } + + type = 'P'; + +#if VERBOSE + cout << "EndChebyshev\n"; +#endif + + log(""); +} + + + +void +TFilter::lowpass(void) +{ + unsigned i; + log(""); +// Mod 2016-09-01-RB +// for(i=0; i"); +} + + + +/** +Convert the continuous filter to discrete form via the bilinear transformation +*/ +void TFilter::bilinear(void) +{ + std::complex _bilinear(std::complex s, double Ts); + double normalise(double fc, double fs); + unsigned i; + double fc, fs, omega; + + log(""); + + for(i=0; i= fs/2.0) { + std::cout << "That doesn't make sense! Cut-off must be less than sampling freq / 2.\n" << + "Here fc = " << fc << " and fs = " << fs << "\n"; + return; + } + omega = normalise(fc, fs); + std::cout << "\nStage " << i << "\nomega =" << omega << "\n"; + double omega_ac = tan(omega/2.0); + std::cout << "omega_ac =" << omega_ac << "\n\n"; + st[i].iir1.transform(fclass, omega_ac, st[i].q); + st[i].iir1.write(i); +/* st[i].iir1.step(0.0); + std::cout << "\n"; + std::cout << "Direct Form 1 realisation.\n--------------------------\n"; + for(i=0; i<200; i++) std::cout << st[i].iir1.step(1.0) << "\n"; +*/ +// st[i].z = _bilinear(st[i].pole, 1000.0); + } + + log(""); +} + + +/** +Calculate the frequency response of the filter. +*/ +void +bode_calc(TFilter& filter) +{ +// extern TControl_window *Control_window; + unsigned i, k; + double f, w; + double t, q; + std::complex s, r, j; + double temp; + double max_gain = 0.0; + ofstream bode_file; + + filter.log(""); + j = std::complex(0.0, 1.0); + +// filter.fmax = 1.0 * filter.frequency * M_PI / 2.0; + filter.fmax = 0.1 * filter.frequency; + for(i=0; i(0.0, (2.0*M_PI)*f); + r = 1.0/(1.0+s*t/q+s*s*t*t); + if(filter.fclass == Bandpass) r *= s * t; + if(filter.fclass == Highpass) r *= s * s * t * t; + filter.freq_resp[i] *= abs(r); + } + } + if(k < (filter.poles+1)/2) { +// t = 1.0 / abs(filter.pole[k]); + for(i=0; i(0.0, (2.0*M_PI)*f); + r = 1.0/(1.0+s*filter.tau); + if(filter.fclass == Bandpass) { cout << "How do we have a bandpass filter with an odd pole?\n"; r *= s * filter.tau; } + if(filter.fclass == Highpass) r *= s * filter.tau; + filter.freq_resp[i] *= abs(r); + } + } + +/// Normalise gain + if(filter.fclass == Bandpass) { + for(i=0, max_gain=0; i max_gain) max_gain = filter.freq_resp[i]; + } + for(i=0; i"); +} + + + +/** +'step_calc' convolves the impulse response of each stage with a step function +so as to derive the step response of the entire filter. +*/ +void +TFilter::step_calc(void) +{ +// extern TControl_window *Control_window; + char logstr[256]; + unsigned i, k, u; + double ti, w, w0; + double tt, qq, zeta; + double a, b; + double input[TSTEPS], output[TSTEPS], stage_n[TSTEPS]; + double integral, max; + double k1, dt; + std::complex s, r, j; + ofstream step_file; + + log(""); + j = std::complex(0.0, 1.0); + + switch(fclass) { + case Lowpass: tmax = 5.0/frequency; break; + case Bandpass: tmax = 5.0/bandwidth; break; + case Highpass: tmax = 2.0/frequency; break; + default: cout << "Unknown fclass\n"; exit(-1); + } + dt = tmax/TSTEPS; + + sprintf(logstr, "tmax = %f seconds", tmax); + log(logstr); + +// c = tmax / 5.0; + /// Start with step function + for(i=0; i"); +} + + + +double scale(TFilter filter) +{ + double max = 0; + int i; + for(i = 0; i < filter.poles; i++) { + if(-(double)filter.st[i].pole.real() > max) max = -(double)filter.st[i].pole.real(); + if((double)filter.st[i].pole.imag() > max) max = (double)filter.st[i].pole.imag(); + } + return((max * 4.0) / 3.0); +} + + + +void TFilter::Calculate(void) +{ + char str[256]; + int i; + log(""); + +/// Create prototype filter. + switch(sclass) { + case Butterworth: butterworth( ); break; + case Bessel: bessel( ); sort( ); break; + case Chebyshev: chebyshev( ); break; + default: cout << "Unknown filter!" << "\n"; return; + } + /// Adjust prototype filter so attenuation is x dB at 1 Hertz. + std::cout << "***** Prototype filter *****\n"; + for(i=0; i"); +} + + + +void TFilter::log(string s) +{ +#if LOG + ofstream logfile; + logfile.open("./rbfilter.log", ios::app); + logfile << s << "\n"; + logfile.close( ); +#endif +} + + + +void TFilter::log(string s, double d) +{ + ostringstream s1; + std::string s2; + s1 << s << d; + s2 = s1.str( ); + log(s2); +} + + + + +void TFilter::log(string s, double *pd) +{ + ostringstream s1; + std::string s2; + s1 << s << *pd; + s2 = s1.str( ); + log(s2); +} + + + +/// Log the array pd but no more than 100 elements of it. +void TFilter::log(string s, double *pd, int n) +{ + int i; +#if LOG + char s1[128]; + n = n>100? 100: n; + for(i=0; i<(n-1); i++) { + sprintf(s1, "%s %f", s.c_str( ), *(pd+i)); + log(s1); + } + log(""); +#endif +} + + + + +void TFilter::log(string s, std::complex c) +{ + ostringstream s1; + std::string s2; + s1 << s << c; + s2 = s1.str( ); + log(s2); +} + + + + +void TFilter::print_T_q(void) +{ +// cout << s << "\n"; +} + + + +/// 'transform( )' transforms the prototype filter to the desired type (e.g. bandpass) and frequency. +void TFilter::transform(void) +{ +char t, type; +int i; +double p[10], z[10]; +ifstream ifile; +ofstream ofile; + + type = TFilter::type; + log(""); + if(type != 'P') { + cout << "\nFile has already been transformed.\n"; + return; + } + /// 220; Transform to the chosen type. + do { + switch(fclass) { + case Lowpass: + lowpass( ); + type = 'L'; + for(i=0; i"); +} + + + +/** Transform to highpass +Keep the q values unaltered but take the reciprocal of the magnitude; adjust the magnitudes for +frequency; add zeroes at the origin. +*/ +void +TFilter::highpass(void) +{ +int i, type; +double dsq, d, ratio; +double a1, w1; + + log(""); + for(i=0; i(a1, w1); + st[i].zero = complex(0.0, 0.0); + st[i].pole *= 2.0 * M_PI * frequency; +// st[i].zero *= 2.0 * M_PI * frequency; + std::cout << " to " << st[i].pole << "\n"; + } + + fclass = Highpass; + zeroes = poles; + type='H'; + + log(""); +} + + + +/// Transform the filter to bandpass using the Geffe algotithm. +void TFilter::bandpass(void) +{ +int i, j; +double f, w1, a1, d, bw, w0, b1, a2, b2; +ofstream ofile; +TFilter filter1; + + log(""); +/// Transformation to bandpass doubles the number of poles! +// if(poles % 2) log("Odd order! Impossible"); + + for(i=0, j=0; i(a1, b1); + filter1.st[j++].pole = complex(a1, -b1); + if(i != poles - 1) { + filter1.st[j++].pole = complex(a2, b2); + filter1.st[j++].pole = complex(a2, -b2); + ofile << -a1 << " " << b1 << " " << -a2 << " " << b2 << "\n"; + } else ofile << -a1 << " " << b1 << "\n"; + } + zeroes = poles; + filter1.poles = 2 * poles; + type = 'B'; + filter1.type = type; +/* if(n%2) + ofile << p[n]*bw/2.0 << " " << sqrt(w0*w0-p[n]*p[n]*bw*bw/4.0) << "\n"; + ofile.close(); +*/ + + for(i=0; i"); +} + + + +double arccos(double x) +{ + return(2.0 * atan(sqrt(1.0 - x*x) / (1.0 + x))); +} + + + +/** +'geffe' is an implementation of the "Geffe" algorithm which transforms a low pass prototype filter into a bandpass filter. The "Geffe" algorithm is described in "Analogue Filter Design" by M. E. van Valkenburg. +*/ +void +geffe(double sigma, double omega, double w0, double bw, + double &a1, double &b1, double &a2, double &b2) +{ +double c, d, e, g, q, k, w, w01, w02, qc, a, b; +double q1, q2; // Used for checking. + + filter.log(""); + + qc=w0/bw; + c=sigma*sigma+omega*omega; + d=-2.0*sigma/qc; + e=4.0+c/(qc*qc); + g=sqrt(e*e-4.0*d*d); + q=sqrt((e+g)/2.0)/d; + k=sigma*q/qc; + // As originally written, 'w' would often be evaluated as 'nan'. This is intended to avoid that problem. + if(fabs((k*k-1.0) < 0.0001)) w = k; + else w=k+sqrt(k*k-1.0); + w01=w*w0; + w02=w0/w; + a1=w01/(2.0*q); + a2=w02/(2.0*q); + a=1.0/(2.0*q); +#if 1 + b=sin(atan(sqrt((1.0-a*a)/(a*a)))); + b1=w01*b; + b2=w02*b; +#else + b1 = -w01*sin(arccos(1.0 / (2.0 * q))); + b2 = -w02*sin(arccos(1.0 / (2.0 * q))); +#endif + // Check: + q1 = (a1*a1+b1*b1)/(2.0*a1); + q2 = (a2*a2+b2*b2)/(2.0*a2); + cout << "q=" << q1 << " & " << q2 << "\n"; + + filter.log(""); +} + + + + diff --git a/Calcs.h b/Calcs.h new file mode 100644 index 0000000..3540104 --- /dev/null +++ b/Calcs.h @@ -0,0 +1,120 @@ +#ifndef CALCSH +#define CALCSH + +/*! \file Calcs.h +*/ + +#include +using std::string; +#include +#include +#include +#include +#include +#include "Enums.h" +#include "Discrete.h" + +#define FSTEPS 1000 +#define TSTEPS 1000 +#define IMAX 19 +#define MAXS 19 + +#define LOG true + +#define NORMALISE + +#define VERBOSE false + +// Shall we show detailed response data? +// #define SHOW_STAGES + +using namespace std; + + + + +/*! \class stage +Describes one stage of a cascaded continuous filter. +*/ +class stage { +public: + filter_class fclass; + circuit_class cclass; + double T, q; + std::complex pole, zero; +// double t, q; + double R1, R2, R3, C1, C2, C3; + double gain; + std::complex z; + iir iir1; + void R_low_pass(void); + void R_high_pass(void); + void R_band_pass(void); + void synthesise_R_low(void); + void synthesise_R_band(void); + void synthesise_R_high(void); + void synthesise_SK_low(void); + void synthesise_SK_band(void); + void synthesise_SK_high(void); + void bilinear(void); + stage& operator= (stage& f1); +}; + + +class TFilter { +// private: +public: + filter_class fclass; + circuit_class cclass; + shape_class sclass; + double frequency; + double gain; + unsigned int poles, zeroes; +// std::complex pole[20], zero[20]; + double /* t[10], q[10],*/ tau; // TODO: use tau for single pole. + char type; + double fmax, tmax; + double ripple; + double bandwidth; + double samplingfreq; + double freq_resp[FSTEPS]; + double step_resp[TSTEPS]; + stage st[10]; + void Proto_normalise(void); + double fgain(double f); + double a0; +public: + TFilter( ); +// ~TFilter( ); + void Calculate(void); + void log(string); + void log(string, double); + void log(string, double *); + void log(string, double *, int); + void log(string, std::complex); + void _pole(double a, double w); + void transform(void); + void print_T_q(void); + void ts_and_qs(void); + void show_filter(void); + void show_filter(string title); + void bessel(void); + void sort(void); + void butterworth(void); + void chebyshev(void); + void lowpass(void); + void highpass(void); + void bandpass(void); + void Synth_Rauch(void); + void Synth_SallKey(void); + void step_calc(void); + void bilinear(void); +}; + + +double tq(std::complex p, double &t, double &q); +void bode_calc(TFilter& filter); +void step_calc(TFilter& filter); + + +#endif diff --git a/Debug b/Debug new file mode 100644 index 0000000..f03fd3e --- /dev/null +++ b/Debug @@ -0,0 +1,4 @@ +#! /bin/bash +gdb ./rbfilter +# read + diff --git a/Discrete.cpp b/Discrete.cpp new file mode 100644 index 0000000..e117a98 --- /dev/null +++ b/Discrete.cpp @@ -0,0 +1,152 @@ +/** \file +'Discrete.cpp' holds the code for implementing discrete, i.e. z-transform, filters. +*/ + +#include +#include "math.h" +#include "Calcs.h" +#include +#include +#include +#include +#include "Discrete.h" + + +iir iir1; + + +/// 'iir::step(...)' implements the Direct Form 1 realisation. +double iir::step(double in) +{ + int i; + + for(i=2; i>0; i--) x[i] = x[i-1], y[i] = y[i-1]; + x[0] = in * k; + y[0] = -a1*y[1] - a2*y[2] + b0*x[0] + b1*x[1] + b2*x[2]; + + return(y[0]); +} + + + + +/** Set the iir filter objects coefficients. */ +void iir::setup(double kk, double aa0, double aa1, double aa2, double bb1, double bb2) +{ + k = kk; + a1 = aa1, a2 = aa2; + b1 = bb1, b2 = bb2; +} + + + +void iir::write(int stage) +{ + char str[256]; + std::ofstream out; + if(stage == 0) { + out.open("./out.c", std::ofstream::trunc); + /// Write initial code to 'out.c' + } + else out.open("./out.c", std::ofstream::app); + sprintf(str, "y%1d = -a%1d1*y%1d[1] - a%1d2*y%1d[2] + b%1d0*x%1d[0] + b%1d1*x%1d[1] + b%1d2*x%1d[2];\n", + stage, stage, stage, stage, stage, stage, stage, stage, stage, stage, stage); + out << str; + if(out.is_open( )) { out.close( ); } +} + + + +/** Pre-warp the continuous filter. */ +void prewarp(void) +{ + /// Not yet designed. +} + + + +/** Transform the continuous filter into a discrete one. */ +void iir::transform(filter_class fclass, double Omega_ac, double q) +{ + double ro2 = 1.0 / (Omega_ac * Omega_ac); + double roq = 1.0 / (Omega_ac * q); + b0 = 1.0; + switch(fclass) { + case Lowpass: + b1 = 2.0; + b2 = 1.0; + break; + case Highpass: + b0 = ro2; + b1 = -2.0 * ro2; + b2 = ro2; + break; + case Bandpass: + b0 = 1.0; + b1 = 0.0; + b2 = -1.0; + break; + default: cout << "\nUnknown filter type.\n"; return; + } + a0 = ro2 + roq + 1.0; + std::cout << "a0 =" << a0 << "\n"; +// k = 1.0 / a0; + a1 = 2.0 - 2.0 * ro2; + a2 = ro2 - roq + 1.0; + + a1 /= a0; + a2 /= a0; + b0 /= a0; + b1 /= a0; + b2 /= a0; + std::cout << "(" << b0 << "+(z^-1)*" << b1 << "+(z^-2)*" << b2 << ")/(" << 1.0 << "+(z^-1)*" << a1 << "+(z^-2)*" << a2 << ")\n"; + std::cout << "-->" << (b0 + b1 + b2) / (1.0 + a1 + a2) << "\n"; + + std::cout << "[a0 = 1.0, a1 =" << a1 << ", a2 =" << a2 << "; b0 =" << b0 << ", b1 =" << b1 << ", b2 =" << b2 << "]\n"; + +/* std::cout << "Direct Form 2 realisation.\n--------------------------\n"; + std::cout << "y[n] = b0 * w[n] + b1 * w[n-1] + b2 * w[n-2], w[n] = x[n] - a1 * w[n-1] - a2 * w[n-2]"; +*/ +} + + + +/** 'normalise(...)' sets 'omega' */ +double normalise(double fc, double fs) +{ + double omega = 2.0 * M_PI * fc / fs; + return(omega); +} + + +#if false +int main( ) +{ + int i; + double fc, fs, omega; + std::cout << "cut-off freq: "; + std::cin >> fc; + std::cout << "sampling freq: "; + std::cin >> fs; + if(fc >= fs/2.0) { + std::cout << "That doesn't make sense! Cut-off must be less than sampling freq / 2.\n"; + exit(-1); + } + omega = normalise(fc, fs); + std::cout << "omega =" << omega << "\n"; + double omega_ac = tan(omega/2.0); + std::cout << "omega_ac =" << omega_ac << "\n\n"; + + iir1.transform(omega_ac, 0.7); +// iir1.setup(1.384, 0.1311136, 0.2162924, 0.1311136, -0.829328, 0.307046); + iir1.step(0.0); + std::cout << "\n"; + std::cout << "Direct Form 1 realisation.\n--------------------------\n"; + for(i=0; i<200; i++) std::cout << iir1.step(1.0) << "\n"; + return(0); +} +#endif + + + + diff --git a/Discrete.h b/Discrete.h new file mode 100644 index 0000000..9d5d12f --- /dev/null +++ b/Discrete.h @@ -0,0 +1,21 @@ +#ifndef DISCRETE_H +#define DISCRETE_H + +#include "Enums.h" + + +class iir { + int i; + double a0, a1, a2, b0, b1, b2, k; + double y[3], x[3]; +public: + iir(void) { k = 1.0; for(i=0; i<3; i++) x[i] = y[i] = 0.0; } + void setup(double kk, double aa0, double aa1, double aa2, double bb1, double bb2); + void transform(filter_class fclass, double T, double q); + double step(double in); + void write(int stage); +}; + + +#endif + diff --git a/Document b/Document new file mode 100644 index 0000000..eb6c07f --- /dev/null +++ b/Document @@ -0,0 +1,5 @@ +#! /bin/bash +doxygen Document.conf +echo "*****************" +read + diff --git a/Document.conf b/Document.conf new file mode 100644 index 0000000..bfac9d7 --- /dev/null +++ b/Document.conf @@ -0,0 +1,1417 @@ +# Doxyfile 1.5.6 + +# This file describes the settings to be used by the documentation system +# doxygen (www.doxygen.org) for a project +# +# All text after a hash (#) is considered a comment and will be ignored +# The format is: +# TAG = value [value, ...] +# For lists items can also be appended using: +# TAG += value [value, ...] +# Values that contain spaces should be placed between quotes (" ") + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- + +# This tag specifies the encoding used for all characters in the config file +# that follow. The default is UTF-8 which is also the encoding used for all +# text before the first occurrence of this tag. Doxygen uses libiconv (or the +# iconv built into libc) for the transcoding. See +# http://www.gnu.org/software/libiconv for the list of possible encodings. + +DOXYFILE_ENCODING = UTF-8 + +# The PROJECT_NAME tag is a single word (or a sequence of words surrounded +# by quotes) that should identify the project. + +PROJECT_NAME = FilterCalcs + +# The PROJECT_NUMBER tag can be used to enter a project or revision number. +# This could be handy for archiving the generated documentation or +# if some version control system is used. + +PROJECT_NUMBER = 0.1 + +# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) +# base path where the generated documentation will be put. +# If a relative path is entered, it will be relative to the location +# where doxygen was started. If left blank the current directory will be used. + +OUTPUT_DIRECTORY = + +# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create +# 4096 sub-directories (in 2 levels) under the output directory of each output +# format and will distribute the generated files over these directories. +# Enabling this option can be useful when feeding doxygen a huge amount of +# source files, where putting all generated files in the same directory would +# otherwise cause performance problems for the file system. + +CREATE_SUBDIRS = NO + +# The OUTPUT_LANGUAGE tag is used to specify the language in which all +# documentation generated by doxygen is written. Doxygen will use this +# information to generate all constant output in the proper language. +# The default language is English, other supported languages are: +# Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese-Traditional, +# Croatian, Czech, Danish, Dutch, Farsi, Finnish, French, German, Greek, +# Hungarian, Italian, Japanese, Japanese-en (Japanese with English messages), +# Korean, Korean-en, Lithuanian, Norwegian, Macedonian, Persian, Polish, +# Portuguese, Romanian, Russian, Serbian, Slovak, Slovene, Spanish, Swedish, +# and Ukrainian. + +OUTPUT_LANGUAGE = English + +# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will +# include brief member descriptions after the members that are listed in +# the file and class documentation (similar to JavaDoc). +# Set to NO to disable this. + +BRIEF_MEMBER_DESC = YES + +# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend +# the brief description of a member or function before the detailed description. +# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the +# brief descriptions will be completely suppressed. + +REPEAT_BRIEF = YES + +# This tag implements a quasi-intelligent brief description abbreviator +# that is used to form the text in various listings. Each string +# in this list, if found as the leading text of the brief description, will be +# stripped from the text and the result after processing the whole list, is +# used as the annotated text. Otherwise, the brief description is used as-is. +# If left blank, the following values are used ("$name" is automatically +# replaced with the name of the entity): "The $name class" "The $name widget" +# "The $name file" "is" "provides" "specifies" "contains" +# "represents" "a" "an" "the" + +ABBREVIATE_BRIEF = + +# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then +# Doxygen will generate a detailed section even if there is only a brief +# description. + +ALWAYS_DETAILED_SEC = YES + +# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all +# inherited members of a class in the documentation of that class as if those +# members were ordinary class members. Constructors, destructors and assignment +# operators of the base classes will not be shown. + +INLINE_INHERITED_MEMB = NO + +# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full +# path before files name in the file list and in the header files. If set +# to NO the shortest path that makes the file name unique will be used. + +FULL_PATH_NAMES = YES + +# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag +# can be used to strip a user-defined part of the path. Stripping is +# only done if one of the specified strings matches the left-hand part of +# the path. The tag can be used to show relative paths in the file list. +# If left blank the directory from which doxygen is run is used as the +# path to strip. + +STRIP_FROM_PATH = + +# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of +# the path mentioned in the documentation of a class, which tells +# the reader which header file to include in order to use a class. +# If left blank only the name of the header file containing the class +# definition is used. Otherwise one should specify the include paths that +# are normally passed to the compiler using the -I flag. + +STRIP_FROM_INC_PATH = + +# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter +# (but less readable) file names. This can be useful is your file systems +# doesn't support long names like on DOS, Mac, or CD-ROM. + +SHORT_NAMES = NO + +# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen +# will interpret the first line (until the first dot) of a JavaDoc-style +# comment as the brief description. If set to NO, the JavaDoc +# comments will behave just like regular Qt-style comments +# (thus requiring an explicit @brief command for a brief description.) + +JAVADOC_AUTOBRIEF = NO + +# If the QT_AUTOBRIEF tag is set to YES then Doxygen will +# interpret the first line (until the first dot) of a Qt-style +# comment as the brief description. If set to NO, the comments +# will behave just like regular Qt-style comments (thus requiring +# an explicit \brief command for a brief description.) + +QT_AUTOBRIEF = NO + +# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen +# treat a multi-line C++ special comment block (i.e. a block of //! or /// +# comments) as a brief description. This used to be the default behaviour. +# The new default is to treat a multi-line C++ comment block as a detailed +# description. Set this tag to YES if you prefer the old behaviour instead. + +MULTILINE_CPP_IS_BRIEF = NO + +# If the DETAILS_AT_TOP tag is set to YES then Doxygen +# will output the detailed description near the top, like JavaDoc. +# If set to NO, the detailed description appears after the member +# documentation. + +DETAILS_AT_TOP = NO + +# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented +# member inherits the documentation from any documented member that it +# re-implements. + +INHERIT_DOCS = YES + +# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce +# a new page for each member. If set to NO, the documentation of a member will +# be part of the file/class/namespace that contains it. + +SEPARATE_MEMBER_PAGES = NO + +# The TAB_SIZE tag can be used to set the number of spaces in a tab. +# Doxygen uses this value to replace tabs by spaces in code fragments. + +TAB_SIZE = 8 + +# This tag can be used to specify a number of aliases that acts +# as commands in the documentation. An alias has the form "name=value". +# For example adding "sideeffect=\par Side Effects:\n" will allow you to +# put the command \sideeffect (or @sideeffect) in the documentation, which +# will result in a user-defined paragraph with heading "Side Effects:". +# You can put \n's in the value part of an alias to insert newlines. + +ALIASES = + +# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C +# sources only. Doxygen will then generate output that is more tailored for C. +# For instance, some of the names that are used will be different. The list +# of all members will be omitted, etc. + +OPTIMIZE_OUTPUT_FOR_C = NO + +# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java +# sources only. Doxygen will then generate output that is more tailored for +# Java. For instance, namespaces will be presented as packages, qualified +# scopes will look different, etc. + +OPTIMIZE_OUTPUT_JAVA = NO + +# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran +# sources only. Doxygen will then generate output that is more tailored for +# Fortran. + +OPTIMIZE_FOR_FORTRAN = NO + +# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL +# sources. Doxygen will then generate output that is tailored for +# VHDL. + +OPTIMIZE_OUTPUT_VHDL = NO + +# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want +# to include (a tag file for) the STL sources as input, then you should +# set this tag to YES in order to let doxygen match functions declarations and +# definitions whose arguments contain STL classes (e.g. func(std::string); v.s. +# func(std::string) {}). This also make the inheritance and collaboration +# diagrams that involve STL classes more complete and accurate. + +BUILTIN_STL_SUPPORT = NO + +# If you use Microsoft's C++/CLI language, you should set this option to YES to +# enable parsing support. + +CPP_CLI_SUPPORT = NO + +# Set the SIP_SUPPORT tag to YES if your project consists of sip sources only. +# Doxygen will parse them like normal C++ but will assume all classes use public +# instead of private inheritance when no explicit protection keyword is present. + +SIP_SUPPORT = NO + +# For Microsoft's IDL there are propget and propput attributes to indicate getter +# and setter methods for a property. Setting this option to YES (the default) +# will make doxygen to replace the get and set methods by a property in the +# documentation. This will only work if the methods are indeed getting or +# setting a simple type. If this is not the case, or you want to show the +# methods anyway, you should set this option to NO. + +IDL_PROPERTY_SUPPORT = YES + +# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC +# tag is set to YES, then doxygen will reuse the documentation of the first +# member in the group (if any) for the other members of the group. By default +# all members of a group must be documented explicitly. + +DISTRIBUTE_GROUP_DOC = NO + +# Set the SUBGROUPING tag to YES (the default) to allow class member groups of +# the same type (for instance a group of public functions) to be put as a +# subgroup of that type (e.g. under the Public Functions section). Set it to +# NO to prevent subgrouping. Alternatively, this can be done per class using +# the \nosubgrouping command. + +SUBGROUPING = YES + +# When TYPEDEF_HIDES_STRUCT is enabled, a typedef of a struct, union, or enum +# is documented as struct, union, or enum with the name of the typedef. So +# typedef struct TypeS {} TypeT, will appear in the documentation as a struct +# with name TypeT. When disabled the typedef will appear as a member of a file, +# namespace, or class. And the struct will be named TypeS. This can typically +# be useful for C code in case the coding convention dictates that all compound +# types are typedef'ed and only the typedef is referenced, never the tag name. + +TYPEDEF_HIDES_STRUCT = NO + +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- + +# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in +# documentation are documented, even if no documentation was available. +# Private class members and static file members will be hidden unless +# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES + +EXTRACT_ALL = YES + +# If the EXTRACT_PRIVATE tag is set to YES all private members of a class +# will be included in the documentation. + +EXTRACT_PRIVATE = NO + +# If the EXTRACT_STATIC tag is set to YES all static members of a file +# will be included in the documentation. + +EXTRACT_STATIC = YES + +# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) +# defined locally in source files will be included in the documentation. +# If set to NO only classes defined in header files are included. + +EXTRACT_LOCAL_CLASSES = YES + +# This flag is only useful for Objective-C code. When set to YES local +# methods, which are defined in the implementation section but not in +# the interface are included in the documentation. +# If set to NO (the default) only methods in the interface are included. + +EXTRACT_LOCAL_METHODS = NO + +# If this flag is set to YES, the members of anonymous namespaces will be +# extracted and appear in the documentation as a namespace called +# 'anonymous_namespace{file}', where file will be replaced with the base +# name of the file that contains the anonymous namespace. By default +# anonymous namespace are hidden. + +EXTRACT_ANON_NSPACES = NO + +# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all +# undocumented members of documented classes, files or namespaces. +# If set to NO (the default) these members will be included in the +# various overviews, but no documentation section is generated. +# This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_MEMBERS = NO + +# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all +# undocumented classes that are normally visible in the class hierarchy. +# If set to NO (the default) these classes will be included in the various +# overviews. This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_CLASSES = NO + +# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all +# friend (class|struct|union) declarations. +# If set to NO (the default) these declarations will be included in the +# documentation. + +HIDE_FRIEND_COMPOUNDS = NO + +# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any +# documentation blocks found inside the body of a function. +# If set to NO (the default) these blocks will be appended to the +# function's detailed documentation block. + +HIDE_IN_BODY_DOCS = NO + +# The INTERNAL_DOCS tag determines if documentation +# that is typed after a \internal command is included. If the tag is set +# to NO (the default) then the documentation will be excluded. +# Set it to YES to include the internal documentation. + +INTERNAL_DOCS = NO + +# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate +# file names in lower-case letters. If set to YES upper-case letters are also +# allowed. This is useful if you have classes or files whose names only differ +# in case and if your file system supports case sensitive file names. Windows +# and Mac users are advised to set this option to NO. + +CASE_SENSE_NAMES = YES + +# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen +# will show members with their full class and namespace scopes in the +# documentation. If set to YES the scope will be hidden. + +HIDE_SCOPE_NAMES = NO + +# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen +# will put a list of the files that are included by a file in the documentation +# of that file. + +SHOW_INCLUDE_FILES = YES + +# If the INLINE_INFO tag is set to YES (the default) then a tag [inline] +# is inserted in the documentation for inline members. + +INLINE_INFO = YES + +# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen +# will sort the (detailed) documentation of file and class members +# alphabetically by member name. If set to NO the members will appear in +# declaration order. + +SORT_MEMBER_DOCS = YES + +# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the +# brief documentation of file, namespace and class members alphabetically +# by member name. If set to NO (the default) the members will appear in +# declaration order. + +SORT_BRIEF_DOCS = NO + +# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the +# hierarchy of group names into alphabetical order. If set to NO (the default) +# the group names will appear in their defined order. + +SORT_GROUP_NAMES = NO + +# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be +# sorted by fully-qualified names, including namespaces. If set to +# NO (the default), the class list will be sorted only by class name, +# not including the namespace part. +# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. +# Note: This option applies only to the class list, not to the +# alphabetical list. + +SORT_BY_SCOPE_NAME = NO + +# The GENERATE_TODOLIST tag can be used to enable (YES) or +# disable (NO) the todo list. This list is created by putting \todo +# commands in the documentation. + +GENERATE_TODOLIST = YES + +# The GENERATE_TESTLIST tag can be used to enable (YES) or +# disable (NO) the test list. This list is created by putting \test +# commands in the documentation. + +GENERATE_TESTLIST = YES + +# The GENERATE_BUGLIST tag can be used to enable (YES) or +# disable (NO) the bug list. This list is created by putting \bug +# commands in the documentation. + +GENERATE_BUGLIST = YES + +# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or +# disable (NO) the deprecated list. This list is created by putting +# \deprecated commands in the documentation. + +GENERATE_DEPRECATEDLIST= YES + +# The ENABLED_SECTIONS tag can be used to enable conditional +# documentation sections, marked by \if sectionname ... \endif. + +ENABLED_SECTIONS = + +# The MAX_INITIALIZER_LINES tag determines the maximum number of lines +# the initial value of a variable or define consists of for it to appear in +# the documentation. If the initializer consists of more lines than specified +# here it will be hidden. Use a value of 0 to hide initializers completely. +# The appearance of the initializer of individual variables and defines in the +# documentation can be controlled using \showinitializer or \hideinitializer +# command in the documentation regardless of this setting. + +MAX_INITIALIZER_LINES = 30 + +# Set the SHOW_USED_FILES tag to NO to disable the list of files generated +# at the bottom of the documentation of classes and structs. If set to YES the +# list will mention the files that were used to generate the documentation. + +SHOW_USED_FILES = YES + +# If the sources in your project are distributed over multiple directories +# then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy +# in the documentation. The default is NO. + +SHOW_DIRECTORIES = NO + +# Set the SHOW_FILES tag to NO to disable the generation of the Files page. +# This will remove the Files entry from the Quick Index and from the +# Folder Tree View (if specified). The default is YES. + +SHOW_FILES = YES + +# Set the SHOW_NAMESPACES tag to NO to disable the generation of the +# Namespaces page. This will remove the Namespaces entry from the Quick Index +# and from the Folder Tree View (if specified). The default is YES. + +SHOW_NAMESPACES = YES + +# The FILE_VERSION_FILTER tag can be used to specify a program or script that +# doxygen should invoke to get the current version for each file (typically from +# the version control system). Doxygen will invoke the program by executing (via +# popen()) the command , where is the value of +# the FILE_VERSION_FILTER tag, and is the name of an input file +# provided by doxygen. Whatever the program writes to standard output +# is used as the file version. See the manual for examples. + +FILE_VERSION_FILTER = + +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- + +# The QUIET tag can be used to turn on/off the messages that are generated +# by doxygen. Possible values are YES and NO. If left blank NO is used. + +QUIET = NO + +# The WARNINGS tag can be used to turn on/off the warning messages that are +# generated by doxygen. Possible values are YES and NO. If left blank +# NO is used. + +WARNINGS = YES + +# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings +# for undocumented members. If EXTRACT_ALL is set to YES then this flag will +# automatically be disabled. + +WARN_IF_UNDOCUMENTED = YES + +# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for +# potential errors in the documentation, such as not documenting some +# parameters in a documented function, or documenting parameters that +# don't exist or using markup commands wrongly. + +WARN_IF_DOC_ERROR = YES + +# This WARN_NO_PARAMDOC option can be abled to get warnings for +# functions that are documented, but have no documentation for their parameters +# or return value. If set to NO (the default) doxygen will only warn about +# wrong or incomplete parameter documentation, but not about the absence of +# documentation. + +WARN_NO_PARAMDOC = NO + +# The WARN_FORMAT tag determines the format of the warning messages that +# doxygen can produce. The string should contain the $file, $line, and $text +# tags, which will be replaced by the file and line number from which the +# warning originated and the warning text. Optionally the format may contain +# $version, which will be replaced by the version of the file (if it could +# be obtained via FILE_VERSION_FILTER) + +WARN_FORMAT = "$file:$line: $text" + +# The WARN_LOGFILE tag can be used to specify a file to which warning +# and error messages should be written. If left blank the output is written +# to stderr. + +WARN_LOGFILE = + +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- + +# The INPUT tag can be used to specify the files and/or directories that contain +# documented source files. You may enter file names like "myfile.cpp" or +# directories like "/usr/src/myproject". Separate the files or directories +# with spaces. + +INPUT = . + +# This tag can be used to specify the character encoding of the source files +# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is +# also the default input encoding. Doxygen uses libiconv (or the iconv built +# into libc) for the transcoding. See http://www.gnu.org/software/libiconv for +# the list of possible encodings. + +INPUT_ENCODING = UTF-8 + +# If the value of the INPUT tag contains directories, you can use the +# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank the following patterns are tested: +# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx +# *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.py *.f90 + +FILE_PATTERNS = + +# The RECURSIVE tag can be used to turn specify whether or not subdirectories +# should be searched for input files as well. Possible values are YES and NO. +# If left blank NO is used. + +RECURSIVE = NO + +# The EXCLUDE tag can be used to specify files and/or directories that should +# excluded from the INPUT source files. This way you can easily exclude a +# subdirectory from a directory tree whose root is specified with the INPUT tag. + +EXCLUDE = + +# The EXCLUDE_SYMLINKS tag can be used select whether or not files or +# directories that are symbolic links (a Unix filesystem feature) are excluded +# from the input. + +EXCLUDE_SYMLINKS = NO + +# If the value of the INPUT tag contains directories, you can use the +# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude +# certain files from those directories. Note that the wildcards are matched +# against the file with absolute path, so to exclude all test directories +# for example use the pattern */test/* + +EXCLUDE_PATTERNS = + +# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names +# (namespaces, classes, functions, etc.) that should be excluded from the +# output. The symbol name can be a fully qualified name, a word, or if the +# wildcard * is used, a substring. Examples: ANamespace, AClass, +# AClass::ANamespace, ANamespace::*Test + +EXCLUDE_SYMBOLS = + +# The EXAMPLE_PATH tag can be used to specify one or more files or +# directories that contain example code fragments that are included (see +# the \include command). + +EXAMPLE_PATH = + +# If the value of the EXAMPLE_PATH tag contains directories, you can use the +# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank all files are included. + +EXAMPLE_PATTERNS = + +# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be +# searched for input files to be used with the \include or \dontinclude +# commands irrespective of the value of the RECURSIVE tag. +# Possible values are YES and NO. If left blank NO is used. + +EXAMPLE_RECURSIVE = NO + +# The IMAGE_PATH tag can be used to specify one or more files or +# directories that contain image that are included in the documentation (see +# the \image command). + +IMAGE_PATH = + +# The INPUT_FILTER tag can be used to specify a program that doxygen should +# invoke to filter for each input file. Doxygen will invoke the filter program +# by executing (via popen()) the command , where +# is the value of the INPUT_FILTER tag, and is the name of an +# input file. Doxygen will then use the output that the filter program writes +# to standard output. If FILTER_PATTERNS is specified, this tag will be +# ignored. + +INPUT_FILTER = + +# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern +# basis. Doxygen will compare the file name with each pattern and apply the +# filter if there is a match. The filters are a list of the form: +# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further +# info on how filters are used. If FILTER_PATTERNS is empty, INPUT_FILTER +# is applied to all files. + +FILTER_PATTERNS = + +# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using +# INPUT_FILTER) will be used to filter the input files when producing source +# files to browse (i.e. when SOURCE_BROWSER is set to YES). + +FILTER_SOURCE_FILES = NO + +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- + +# If the SOURCE_BROWSER tag is set to YES then a list of source files will +# be generated. Documented entities will be cross-referenced with these sources. +# Note: To get rid of all source code in the generated output, make sure also +# VERBATIM_HEADERS is set to NO. + +SOURCE_BROWSER = NO + +# Setting the INLINE_SOURCES tag to YES will include the body +# of functions and classes directly in the documentation. + +INLINE_SOURCES = NO + +# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct +# doxygen to hide any special comment blocks from generated source code +# fragments. Normal C and C++ comments will always remain visible. + +STRIP_CODE_COMMENTS = YES + +# If the REFERENCED_BY_RELATION tag is set to YES +# then for each documented function all documented +# functions referencing it will be listed. + +REFERENCED_BY_RELATION = NO + +# If the REFERENCES_RELATION tag is set to YES +# then for each documented function all documented entities +# called/used by that function will be listed. + +REFERENCES_RELATION = NO + +# If the REFERENCES_LINK_SOURCE tag is set to YES (the default) +# and SOURCE_BROWSER tag is set to YES, then the hyperlinks from +# functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will +# link to the source code. Otherwise they will link to the documentstion. + +REFERENCES_LINK_SOURCE = YES + +# If the USE_HTAGS tag is set to YES then the references to source code +# will point to the HTML generated by the htags(1) tool instead of doxygen +# built-in source browser. The htags tool is part of GNU's global source +# tagging system (see http://www.gnu.org/software/global/global.html). You +# will need version 4.8.6 or higher. + +USE_HTAGS = NO + +# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen +# will generate a verbatim copy of the header file for each class for +# which an include is specified. Set to NO to disable this. + +VERBATIM_HEADERS = YES + +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- + +# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index +# of all compounds will be generated. Enable this if the project +# contains a lot of classes, structs, unions or interfaces. + +ALPHABETICAL_INDEX = NO + +# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then +# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns +# in which this list will be split (can be a number in the range [1..20]) + +COLS_IN_ALPHA_INDEX = 5 + +# In case all classes in a project start with a common prefix, all +# classes will be put under the same header in the alphabetical index. +# The IGNORE_PREFIX tag can be used to specify one or more prefixes that +# should be ignored while generating the index headers. + +IGNORE_PREFIX = + +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- + +# If the GENERATE_HTML tag is set to YES (the default) Doxygen will +# generate HTML output. + +GENERATE_HTML = YES + +# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `html' will be used as the default path. + +HTML_OUTPUT = html + +# The HTML_FILE_EXTENSION tag can be used to specify the file extension for +# each generated HTML page (for example: .htm,.php,.asp). If it is left blank +# doxygen will generate files with .html extension. + +HTML_FILE_EXTENSION = .html + +# The HTML_HEADER tag can be used to specify a personal HTML header for +# each generated HTML page. If it is left blank doxygen will generate a +# standard header. + +HTML_HEADER = + +# The HTML_FOOTER tag can be used to specify a personal HTML footer for +# each generated HTML page. If it is left blank doxygen will generate a +# standard footer. + +HTML_FOOTER = + +# The HTML_STYLESHEET tag can be used to specify a user-defined cascading +# style sheet that is used by each HTML page. It can be used to +# fine-tune the look of the HTML output. If the tag is left blank doxygen +# will generate a default style sheet. Note that doxygen will try to copy +# the style sheet file to the HTML output directory, so don't put your own +# stylesheet in the HTML output directory as well, or it will be erased! + +HTML_STYLESHEET = + +# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, +# files or namespaces will be aligned in HTML using tables. If set to +# NO a bullet list will be used. + +HTML_ALIGN_MEMBERS = YES + +# If the GENERATE_HTMLHELP tag is set to YES, additional index files +# will be generated that can be used as input for tools like the +# Microsoft HTML help workshop to generate a compiled HTML help file (.chm) +# of the generated HTML documentation. + +GENERATE_HTMLHELP = NO + +# If the GENERATE_DOCSET tag is set to YES, additional index files +# will be generated that can be used as input for Apple's Xcode 3 +# integrated development environment, introduced with OSX 10.5 (Leopard). +# To create a documentation set, doxygen will generate a Makefile in the +# HTML output directory. Running make will produce the docset in that +# directory and running "make install" will install the docset in +# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find +# it at startup. + +GENERATE_DOCSET = NO + +# When GENERATE_DOCSET tag is set to YES, this tag determines the name of the +# feed. A documentation feed provides an umbrella under which multiple +# documentation sets from a single provider (such as a company or product suite) +# can be grouped. + +DOCSET_FEEDNAME = "Doxygen generated docs" + +# When GENERATE_DOCSET tag is set to YES, this tag specifies a string that +# should uniquely identify the documentation set bundle. This should be a +# reverse domain-name style string, e.g. com.mycompany.MyDocSet. Doxygen +# will append .docset to the name. + +DOCSET_BUNDLE_ID = org.doxygen.Project + +# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML +# documentation will contain sections that can be hidden and shown after the +# page has loaded. For this to work a browser that supports +# JavaScript and DHTML is required (for instance Mozilla 1.0+, Firefox +# Netscape 6.0+, Internet explorer 5.0+, Konqueror, or Safari). + +HTML_DYNAMIC_SECTIONS = NO + +# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can +# be used to specify the file name of the resulting .chm file. You +# can add a path in front of the file if the result should not be +# written to the html output directory. + +CHM_FILE = + +# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can +# be used to specify the location (absolute path including file name) of +# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run +# the HTML help compiler on the generated index.hhp. + +HHC_LOCATION = + +# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag +# controls if a separate .chi index file is generated (YES) or that +# it should be included in the master .chm file (NO). + +GENERATE_CHI = NO + +# If the GENERATE_HTMLHELP tag is set to YES, the CHM_INDEX_ENCODING +# is used to encode HtmlHelp index (hhk), content (hhc) and project file +# content. + +CHM_INDEX_ENCODING = + +# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag +# controls whether a binary table of contents is generated (YES) or a +# normal table of contents (NO) in the .chm file. + +BINARY_TOC = NO + +# The TOC_EXPAND flag can be set to YES to add extra items for group members +# to the contents of the HTML help documentation and to the tree view. + +TOC_EXPAND = NO + +# The DISABLE_INDEX tag can be used to turn on/off the condensed index at +# top of each HTML page. The value NO (the default) enables the index and +# the value YES disables it. + +DISABLE_INDEX = NO + +# This tag can be used to set the number of enum values (range [1..20]) +# that doxygen will group on one line in the generated HTML documentation. + +ENUM_VALUES_PER_LINE = 4 + +# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index +# structure should be generated to display hierarchical information. +# If the tag value is set to FRAME, a side panel will be generated +# containing a tree-like index structure (just like the one that +# is generated for HTML Help). For this to work a browser that supports +# JavaScript, DHTML, CSS and frames is required (for instance Mozilla 1.0+, +# Netscape 6.0+, Internet explorer 5.0+, or Konqueror). Windows users are +# probably better off using the HTML help feature. Other possible values +# for this tag are: HIERARCHIES, which will generate the Groups, Directories, +# and Class Hiererachy pages using a tree view instead of an ordered list; +# ALL, which combines the behavior of FRAME and HIERARCHIES; and NONE, which +# disables this behavior completely. For backwards compatibility with previous +# releases of Doxygen, the values YES and NO are equivalent to FRAME and NONE +# respectively. + +GENERATE_TREEVIEW = FRAME + +# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be +# used to set the initial width (in pixels) of the frame in which the tree +# is shown. + +TREEVIEW_WIDTH = 250 + +# Use this tag to change the font size of Latex formulas included +# as images in the HTML documentation. The default is 10. Note that +# when you change the font size after a successful doxygen run you need +# to manually remove any form_*.png images from the HTML output directory +# to force them to be regenerated. + +FORMULA_FONTSIZE = 10 + +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- + +# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will +# generate Latex output. + +GENERATE_LATEX = NO + +# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `latex' will be used as the default path. + +LATEX_OUTPUT = latex + +# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be +# invoked. If left blank `latex' will be used as the default command name. + +LATEX_CMD_NAME = latex + +# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to +# generate index for LaTeX. If left blank `makeindex' will be used as the +# default command name. + +MAKEINDEX_CMD_NAME = makeindex + +# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact +# LaTeX documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_LATEX = NO + +# The PAPER_TYPE tag can be used to set the paper type that is used +# by the printer. Possible values are: a4, a4wide, letter, legal and +# executive. If left blank a4wide will be used. + +PAPER_TYPE = a4wide + +# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX +# packages that should be included in the LaTeX output. + +EXTRA_PACKAGES = + +# The LATEX_HEADER tag can be used to specify a personal LaTeX header for +# the generated latex document. The header should contain everything until +# the first chapter. If it is left blank doxygen will generate a +# standard header. Notice: only use this tag if you know what you are doing! + +LATEX_HEADER = + +# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated +# is prepared for conversion to pdf (using ps2pdf). The pdf file will +# contain links (just like the HTML output) instead of page references +# This makes the output suitable for online browsing using a pdf viewer. + +PDF_HYPERLINKS = YES + +# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of +# plain latex in the generated Makefile. Set this option to YES to get a +# higher quality PDF documentation. + +USE_PDFLATEX = YES + +# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. +# command to the generated LaTeX files. This will instruct LaTeX to keep +# running if errors occur, instead of asking the user for help. +# This option is also used when generating formulas in HTML. + +LATEX_BATCHMODE = NO + +# If LATEX_HIDE_INDICES is set to YES then doxygen will not +# include the index chapters (such as File Index, Compound Index, etc.) +# in the output. + +LATEX_HIDE_INDICES = NO + +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- + +# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output +# The RTF output is optimized for Word 97 and may not look very pretty with +# other RTF readers or editors. + +GENERATE_RTF = NO + +# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `rtf' will be used as the default path. + +RTF_OUTPUT = rtf + +# If the COMPACT_RTF tag is set to YES Doxygen generates more compact +# RTF documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_RTF = NO + +# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated +# will contain hyperlink fields. The RTF file will +# contain links (just like the HTML output) instead of page references. +# This makes the output suitable for online browsing using WORD or other +# programs which support those fields. +# Note: wordpad (write) and others do not support links. + +RTF_HYPERLINKS = NO + +# Load stylesheet definitions from file. Syntax is similar to doxygen's +# config file, i.e. a series of assignments. You only have to provide +# replacements, missing definitions are set to their default value. + +RTF_STYLESHEET_FILE = + +# Set optional variables used in the generation of an rtf document. +# Syntax is similar to doxygen's config file. + +RTF_EXTENSIONS_FILE = + +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- + +# If the GENERATE_MAN tag is set to YES (the default) Doxygen will +# generate man pages + +GENERATE_MAN = NO + +# The MAN_OUTPUT tag is used to specify where the man pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `man' will be used as the default path. + +MAN_OUTPUT = man + +# The MAN_EXTENSION tag determines the extension that is added to +# the generated man pages (default is the subroutine's section .3) + +MAN_EXTENSION = .3 + +# If the MAN_LINKS tag is set to YES and Doxygen generates man output, +# then it will generate one additional man file for each entity +# documented in the real man page(s). These additional files +# only source the real man page, but without them the man command +# would be unable to find the correct page. The default is NO. + +MAN_LINKS = NO + +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- + +# If the GENERATE_XML tag is set to YES Doxygen will +# generate an XML file that captures the structure of +# the code including all documentation. + +GENERATE_XML = NO + +# The XML_OUTPUT tag is used to specify where the XML pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `xml' will be used as the default path. + +XML_OUTPUT = xml + +# The XML_SCHEMA tag can be used to specify an XML schema, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_SCHEMA = + +# The XML_DTD tag can be used to specify an XML DTD, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_DTD = + +# If the XML_PROGRAMLISTING tag is set to YES Doxygen will +# dump the program listings (including syntax highlighting +# and cross-referencing information) to the XML output. Note that +# enabling this will significantly increase the size of the XML output. + +XML_PROGRAMLISTING = YES + +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- + +# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will +# generate an AutoGen Definitions (see autogen.sf.net) file +# that captures the structure of the code including all +# documentation. Note that this feature is still experimental +# and incomplete at the moment. + +GENERATE_AUTOGEN_DEF = NO + +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- + +# If the GENERATE_PERLMOD tag is set to YES Doxygen will +# generate a Perl module file that captures the structure of +# the code including all documentation. Note that this +# feature is still experimental and incomplete at the +# moment. + +GENERATE_PERLMOD = NO + +# If the PERLMOD_LATEX tag is set to YES Doxygen will generate +# the necessary Makefile rules, Perl scripts and LaTeX code to be able +# to generate PDF and DVI output from the Perl module output. + +PERLMOD_LATEX = NO + +# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be +# nicely formatted so it can be parsed by a human reader. This is useful +# if you want to understand what is going on. On the other hand, if this +# tag is set to NO the size of the Perl module output will be much smaller +# and Perl will parse it just the same. + +PERLMOD_PRETTY = YES + +# The names of the make variables in the generated doxyrules.make file +# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. +# This is useful so different doxyrules.make files included by the same +# Makefile don't overwrite each other's variables. + +PERLMOD_MAKEVAR_PREFIX = + +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- + +# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will +# evaluate all C-preprocessor directives found in the sources and include +# files. + +ENABLE_PREPROCESSING = YES + +# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro +# names in the source code. If set to NO (the default) only conditional +# compilation will be performed. Macro expansion can be done in a controlled +# way by setting EXPAND_ONLY_PREDEF to YES. + +MACRO_EXPANSION = NO + +# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES +# then the macro expansion is limited to the macros specified with the +# PREDEFINED and EXPAND_AS_DEFINED tags. + +EXPAND_ONLY_PREDEF = NO + +# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files +# in the INCLUDE_PATH (see below) will be search if a #include is found. + +SEARCH_INCLUDES = YES + +# The INCLUDE_PATH tag can be used to specify one or more directories that +# contain include files that are not input files but should be processed by +# the preprocessor. + +INCLUDE_PATH = + +# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard +# patterns (like *.h and *.hpp) to filter out the header-files in the +# directories. If left blank, the patterns specified with FILE_PATTERNS will +# be used. + +INCLUDE_FILE_PATTERNS = + +# The PREDEFINED tag can be used to specify one or more macro names that +# are defined before the preprocessor is started (similar to the -D option of +# gcc). The argument of the tag is a list of macros of the form: name +# or name=definition (no spaces). If the definition and the = are +# omitted =1 is assumed. To prevent a macro definition from being +# undefined via #undef or recursively expanded use the := operator +# instead of the = operator. + +PREDEFINED = + +# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then +# this tag can be used to specify a list of macro names that should be expanded. +# The macro definition that is found in the sources will be used. +# Use the PREDEFINED tag if you want to use a different macro definition. + +EXPAND_AS_DEFINED = + +# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then +# doxygen's preprocessor will remove all function-like macros that are alone +# on a line, have an all uppercase name, and do not end with a semicolon. Such +# function macros are typically used for boiler-plate code, and will confuse +# the parser if not removed. + +SKIP_FUNCTION_MACROS = YES + +#--------------------------------------------------------------------------- +# Configuration::additions related to external references +#--------------------------------------------------------------------------- + +# The TAGFILES option can be used to specify one or more tagfiles. +# Optionally an initial location of the external documentation +# can be added for each tagfile. The format of a tag file without +# this location is as follows: +# TAGFILES = file1 file2 ... +# Adding location for the tag files is done as follows: +# TAGFILES = file1=loc1 "file2 = loc2" ... +# where "loc1" and "loc2" can be relative or absolute paths or +# URLs. If a location is present for each tag, the installdox tool +# does not have to be run to correct the links. +# Note that each tag file must have a unique name +# (where the name does NOT include the path) +# If a tag file is not located in the directory in which doxygen +# is run, you must also specify the path to the tagfile here. + +TAGFILES = + +# When a file name is specified after GENERATE_TAGFILE, doxygen will create +# a tag file that is based on the input files it reads. + +GENERATE_TAGFILE = + +# If the ALLEXTERNALS tag is set to YES all external classes will be listed +# in the class index. If set to NO only the inherited external classes +# will be listed. + +ALLEXTERNALS = NO + +# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed +# in the modules index. If set to NO, only the current project's groups will +# be listed. + +EXTERNAL_GROUPS = YES + +# The PERL_PATH should be the absolute path and name of the perl script +# interpreter (i.e. the result of `which perl'). + +PERL_PATH = /usr/bin/perl + +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- + +# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will +# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base +# or super classes. Setting the tag to NO turns the diagrams off. Note that +# this option is superseded by the HAVE_DOT option below. This is only a +# fallback. It is recommended to install and use dot, since it yields more +# powerful graphs. + +CLASS_DIAGRAMS = YES + +# You can define message sequence charts within doxygen comments using the \msc +# command. Doxygen will then run the mscgen tool (see +# http://www.mcternan.me.uk/mscgen/) to produce the chart and insert it in the +# documentation. The MSCGEN_PATH tag allows you to specify the directory where +# the mscgen tool resides. If left empty the tool is assumed to be found in the +# default search path. + +MSCGEN_PATH = + +# If set to YES, the inheritance and collaboration graphs will hide +# inheritance and usage relations if the target is undocumented +# or is not a class. + +HIDE_UNDOC_RELATIONS = YES + +# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is +# available from the path. This tool is part of Graphviz, a graph visualization +# toolkit from AT&T and Lucent Bell Labs. The other options in this section +# have no effect if this option is set to NO (the default) + +HAVE_DOT = NO + +# By default doxygen will write a font called FreeSans.ttf to the output +# directory and reference it in all dot files that doxygen generates. This +# font does not include all possible unicode characters however, so when you need +# these (or just want a differently looking font) you can specify the font name +# using DOT_FONTNAME. You need need to make sure dot is able to find the font, +# which can be done by putting it in a standard location or by setting the +# DOTFONTPATH environment variable or by setting DOT_FONTPATH to the directory +# containing the font. + +DOT_FONTNAME = FreeSans + +# By default doxygen will tell dot to use the output directory to look for the +# FreeSans.ttf font (which doxygen will put there itself). If you specify a +# different font using DOT_FONTNAME you can set the path where dot +# can find it using this tag. + +DOT_FONTPATH = + +# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect inheritance relations. Setting this tag to YES will force the +# the CLASS_DIAGRAMS tag to NO. + +CLASS_GRAPH = YES + +# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect implementation dependencies (inheritance, containment, and +# class references variables) of the class with other documented classes. + +COLLABORATION_GRAPH = YES + +# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for groups, showing the direct groups dependencies + +GROUP_GRAPHS = YES + +# If the UML_LOOK tag is set to YES doxygen will generate inheritance and +# collaboration diagrams in a style similar to the OMG's Unified Modeling +# Language. + +UML_LOOK = NO + +# If set to YES, the inheritance and collaboration graphs will show the +# relations between templates and their instances. + +TEMPLATE_RELATIONS = NO + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT +# tags are set to YES then doxygen will generate a graph for each documented +# file showing the direct and indirect include dependencies of the file with +# other documented files. + +INCLUDE_GRAPH = YES + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and +# HAVE_DOT tags are set to YES then doxygen will generate a graph for each +# documented header file showing the documented files that directly or +# indirectly include this file. + +INCLUDED_BY_GRAPH = YES + +# If the CALL_GRAPH and HAVE_DOT options are set to YES then +# doxygen will generate a call dependency graph for every global function +# or class method. Note that enabling this option will significantly increase +# the time of a run. So in most cases it will be better to enable call graphs +# for selected functions only using the \callgraph command. + +CALL_GRAPH = NO + +# If the CALLER_GRAPH and HAVE_DOT tags are set to YES then +# doxygen will generate a caller dependency graph for every global function +# or class method. Note that enabling this option will significantly increase +# the time of a run. So in most cases it will be better to enable caller +# graphs for selected functions only using the \callergraph command. + +CALLER_GRAPH = NO + +# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen +# will graphical hierarchy of all classes instead of a textual one. + +GRAPHICAL_HIERARCHY = YES + +# If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES +# then doxygen will show the dependencies a directory has on other directories +# in a graphical way. The dependency relations are determined by the #include +# relations between the files in the directories. + +DIRECTORY_GRAPH = YES + +# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images +# generated by dot. Possible values are png, jpg, or gif +# If left blank png will be used. + +DOT_IMAGE_FORMAT = png + +# The tag DOT_PATH can be used to specify the path where the dot tool can be +# found. If left blank, it is assumed the dot tool can be found in the path. + +DOT_PATH = + +# The DOTFILE_DIRS tag can be used to specify one or more directories that +# contain dot files that are included in the documentation (see the +# \dotfile command). + +DOTFILE_DIRS = + +# The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of +# nodes that will be shown in the graph. If the number of nodes in a graph +# becomes larger than this value, doxygen will truncate the graph, which is +# visualized by representing a node as a red box. Note that doxygen if the +# number of direct children of the root node in a graph is already larger than +# DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note +# that the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH. + +DOT_GRAPH_MAX_NODES = 50 + +# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the +# graphs generated by dot. A depth value of 3 means that only nodes reachable +# from the root by following a path via at most 3 edges will be shown. Nodes +# that lay further from the root node will be omitted. Note that setting this +# option to 1 or 2 may greatly reduce the computation time needed for large +# code bases. Also note that the size of a graph can be further restricted by +# DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction. + +MAX_DOT_GRAPH_DEPTH = 0 + +# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent +# background. This is enabled by default, which results in a transparent +# background. Warning: Depending on the platform used, enabling this option +# may lead to badly anti-aliased labels on the edges of a graph (i.e. they +# become hard to read). + +DOT_TRANSPARENT = YES + +# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output +# files in one run (i.e. multiple -o and -T options on the command line). This +# makes dot run faster, but since only newer versions of dot (>1.8.10) +# support this, this feature is disabled by default. + +DOT_MULTI_TARGETS = NO + +# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will +# generate a legend page explaining the meaning of the various boxes and +# arrows in the dot generated graphs. + +GENERATE_LEGEND = YES + +# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will +# remove the intermediate dot files that are used to generate +# the various graphs. + +DOT_CLEANUP = YES + +#--------------------------------------------------------------------------- +# Configuration::additions related to the search engine +#--------------------------------------------------------------------------- + +# The SEARCHENGINE tag specifies whether or not a search engine should be +# used. If set to NO the values of all tags below this one will be ignored. + +SEARCHENGINE = NO diff --git a/Drawing.h b/Drawing.h new file mode 100644 index 0000000..873f4ca --- /dev/null +++ b/Drawing.h @@ -0,0 +1,11 @@ +#ifndef DRAWINGH +#define DRAWINGH + +/*! \file Drawing.h +*/ + +#define SHOW_XY false + +enum DrawMode { Splane, Step, Bode, Realisation } ; + +#endif diff --git a/Enums.h b/Enums.h new file mode 100644 index 0000000..9ec53f3 --- /dev/null +++ b/Enums.h @@ -0,0 +1,10 @@ +#ifndef ENUMSH +#define ENUMSH + +enum filter_class { Lowpass, Highpass, Bandpass }; +enum circuit_class { SallKey, Rauch, ZDomain }; +enum shape_class { Bessel, Butterworth, Chebyshev }; + + +#endif + diff --git a/README b/README new file mode 100644 index 0000000..f09ddfb --- /dev/null +++ b/README @@ -0,0 +1,31 @@ +Copyright (c) 2018 Roger Burghall + +This is a git repository for 'rbfilter'. Copyright is owned by Roger Burghall. + +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 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + +The contents of this repository are subject to the GPLv3.0 ("General Public Licence") + +*** No responsibility is taken for the results obtained using the program contained in or created using these files. *** + +It is strongly recommended that the user should verify and validate the results obtained. Component tolerances and the limitations of real amplifiers will affect the results with actual circuits, and finite time intervals used in circuit simulation software will affect results indicated by circuit simulation software such as SPICE. Similar limitations exist when creating discrete filters. + +'rbfilter' is intended to design, predict and simulate the operation of active and digital filters. As of version 1.0 it can deal with low-, band- and high-pass filters, designed as "Sallen and Key", "Rauch" and Discrete forms of Bessel, Butterworth and Chebyshev types. It does not, in general, comment on the sanity or otherwise of trying to create a particular filter, even if it involves unrealistic "q" values or operates at ridiculous frequencies. + +The original version of this program was written in the early 1970s, using a Digital Equipment Corporation PDP12 computer, in Fortran. The next version dates from the 1980s and was written in BASIC and run on a BBC Model B computer. This version, written in C++, was recreated using a PC running Ubuntu; while it has enhanced functionality in some areas it lacks, as yet, some of the functions of the BBC version, such as the ability to simulate the output of a filter, given a file containing a representation of the input signal. + +Use 'Build' to compile and link the program, 'Run' to run it, 'Debug' to run it under the gdb debugger. (I have not used a makefile as the program isn't big or complicated enough to warrant the effort - yet.) + + diff --git a/Rauch.cpp b/Rauch.cpp new file mode 100644 index 0000000..9f867ea --- /dev/null +++ b/Rauch.cpp @@ -0,0 +1,423 @@ +#include +#include +#include +#include +#include "Calcs.h" + +#if SHOW_FILE_COMPILING +#pragma message "Compiling Rauch.cpp" +#endif + +/*! \file Rauch.cpp + This program calculates the T and q values for a Rauch stage from the component values. +*/ + +using namespace std; + + +stage stage1; + + +double e24[ ] = { 1.0, 1.1, 1.2, 1.3, 1.5, 1.6, 1.8, 2.0, 2.2, 2.4, 2.7, 3.0,\ + 3.3, 3.6, 3.9, 4.3, 4.7, 5.1, 5.6, 6.2, 6.8, 7.5, 8.2, 9.1, 10.0 }; + +double e12[ ] = { 1.0, 1.2, 1.5, 1.8, 2.2, 2.7, 3.3, 3.9, 4.7, 5.6, 6.8, 8.2, 10.0 }; + +double e6[ ] = { 1.0, 1.5, 2.2, 3.3, 4.7, 6.8, 10.0 }; + +enum ee { _e6, _e12, _e24 }; + + +/** +Find the nearest e6, e12 or e24 preferred value to 'v'. +*/ +double nearest(double v, ee e1) +{ + int i, n; + double l = log10(v); + double p = int(l); // Power of ten: i.e. exponent + double f = l - p; + double x = pow10(f+1.0); // Mantissa + double *ep; + switch(e1) { + case _e6: ep = e6; n = 6; break; + case _e12: ep = e12; n = 12; break; + case _e24: ep = e24; n = 24; break; + default: cout << "Don't understand!"; + exit(-1); + }; + for(i=0; i x) break; + } + if(i == 0) { + cout << "Value below 1.0\n"; + return(1.0); + } + return((x/ep[i-1] < ep[i]/x)? ep[i-1] * pow10(p-1.0): ep[i] * pow10(p-1.0)); +} + + + +/** Here comes a clever bit! Design a low-pass stage, choosing e6 values only for the capacitors, keeping sensible values for resistors. +Note: gain = R2 / R1; T = sqrt(C1.C2.R2.R3); q = T / ((1 + R2/R3 + R2/R1).C2.R3) +*/ +void stage::synthesise_R_low(void) +{ +#if false + double R, C, r, r1; + double a, b, c; + R1 = R2 = R3 = 1E4; +// R3 /= 1.1; + r1 = 10.0 / 1.2; + do { + r1 *= 1.2; + /// Choose ideal capacitor values; T^2 = R2*R3*C1*C2 --> C1*C2 = T^2/(R2*R3) + C = sqrt((T * T) / (R2 * R3)); + r = sqrt(r1) * q; + C1 = C * r; + C2 = C / r; + // If R1 = R2 = R3 then q = T/(3*C2*R3) +// R3 *= 1.1; + /// Pick the nearest e6 values for caps. + cout << "Nearest to " << C1 << " is " << nearest(C1, _e6) << "\n"; + cout << "Nearest to " << C2 << " is " << nearest(C2, _e6) << "\n"; + C1 = nearest(C1, _e6); + C2 = nearest(C2, _e6); + /// Restore T to correct value + R = sqrt(T * T / (C1 * C2)); + /// Adjust resistors to get back to desired q, keeping T and gain unchanged + a = C2*R; + b = -T / q; + c = 2.0*C2*R; + } while(b*b <= 4.0 * a * c); + double r = (-b + sqrt(b*b - 4.0 * a * c)) / (2.0 * a); + R1 = R * r; + R2 = R1; + R3 = R / r; +#else + double R, C, r, r1; + double a, b, c; +#if SHOW_CALC + cout << "\nsynthesise_low\n"; +#endif + R1 = R2 = R3 = 1E4; + r1 = 10.0 / 1.2; + do { + r1 *= 1.2; + /// Choose ideal capacitor values; T^2 = R2*R3*C1*C2 --> C1*C2 = T^2/(R2*R3) + C = sqrt((T * T) / (R2 * R3)); + r = sqrt(r1) * q; + C1 = C * r; + C2 = C / r; + // If R1 = R2 = R3 then q = T/(3*C2*R3) + /// Pick the nearest e6 values for caps. +#if SHOW_CALC + cout << "Nearest to " << C1 << " is " << nearest(C1, _e6) << "\n"; + cout << "Nearest to " << C2 << " is " << nearest(C2, _e6) << "\n"; +#endif + C1 = nearest(C1, _e6); + C2 = nearest(C2, _e6); + /// Restore T to correct value + R = sqrt(T * T / (C1 * C2)); + /// Adjust resistors to get back to desired q, keeping T and gain unchanged + a = C2*R; + b = -T / q; + c = 2.0*C2*R; + } while(b*b <= 4.0 * a * c); + r = (-b + sqrt(b*b - 4.0 * a * c)) / (2.0 * a); + R1 = R * r; + R2 = R1; + R3 = R / r; +#if SHOW_CALC + cout << "End synthesise_low\n"; +#endif + +#endif +} + + + +/// Calculate gain, T and q from component values +void stage::R_low_pass(void) +{ + gain = -R2 / R1; + T = sqrt(C1*C2*R2*R3); + q = T / ((1.0 + R2/R3 + R2/R1)*C2*R3); +} + + + +/** Design a band-pass stage, choosing e6 preferred values for the capacitors. Note: +gain = 1 / ((C1.R1)*(2+R1.(C1+C2)/(C1.C2.R1.R2))); T = sqrt(C1.C2.R1.R2); T/q = R1.(C1 + C2); i.e. q = T / (R1.(C1 + C2)) +*/ +void stage::synthesise_R_band(void) +{ + double r; + double a, b, c; + double C; + double R; +#if SHOW_CALC + cout << "\nsynthesise_band\n"; +#endif + R1 = 1.0e4; R2 = 1.0e4/1.5; + do { + /// Choose ideal capacitor values; T^2 = R1*R2*C1*C2 --> C1*C2 = T^2/(R1*R2) + // Let C1 = C.r, C2 = C/r + // If R1 = R2 then q = T/(R1*(C.r+C/r)) + // C.r^2 - T/(q * R1).r + C = 0 + R2 *= 1.5; /// Try progressively increasing ratios of R2:R1 until a solution is possible. + C = T / sqrt(R1*R2); + R = sqrt(R1*R2); + a = C; + b = -T / (q * R1); + c = C; + } while (b*b < 5.0*a*c); + r = (-b + sqrt(b*b - 4.0 * a * c * 1.1)) / (2.0 * a); + C1 = C * r; + C2 = C / r; + + /// Pick the nearest e6 values for caps. +#if SHOW_CALC + cout << "Nearest to " << C1 << " is " << nearest(C1, _e6) << "\n"; + cout << "Nearest to " << C2 << " is " << nearest(C2, _e6) << "\n"; +#endif + C1 = nearest(C1, _e6); + C2 = nearest(C2, _e6); + /// Adjust resistors to get back to desired q, keeping T unchanged + R = sqrt(T * T / (C1 * C2)); + R1 = sqrt(C1*C2*R*R) / (q*(C1+C2)); + R2 = R * R / R1; + +#if SHOW_CALC + cout << "\nEnd synthesise_band\n"; +#endif +} + + + +/** Calculate gain, T and q from component values for a band-pass stage. Note +gain = -C1/C3; T = sqrt(C2.C3.R1.R2); T/q = R1.(C1+C3); i.e. q = T / (R1.(C1+C3)) +*/ +void stage::R_band_pass(void) +{ + gain = -1.0 / ((C1*R1)*(2+R1*(C1+C2)/(C1*C2*R1*R2))); + T = sqrt(R1*R2*C1*C2); + q = T / (R1*(C1 + C2)); +} + + + +/** Design a high pass stage, choosing e6 preferred values for C2 and C3. If the gain is to be -1 +the value of C1 will be identical to C2. +*/ +void stage::synthesise_R_high(void) +{ +#if false + double r; + double a, b, c; + double C; + double R; +#if SHOW_CALC + cout << "\nsynthesise_high\n"; +#endif + R1 = 1.0e4; R2 = 1.0e4/1.5; + do { + R2 *= 1.5; + R = sqrt(R1 * R2); + // T = sqrt(R1*R2*C2*C3) + C = T / sqrt(R1 * R2); + a = -gain * C; + b = -T / (q * R1); + c = C; + } while (b*b <= 4.0 * a * c * 0.9); + r = (-b + sqrt(b*b - 4.0 * a * c)) / (2.0 * a); +// cout << "C =" << C << " r =" << r << "\n"; + C2 = C * r; + C3 = C / r; + C1 = -gain * C * r; +#if SHOW_CALC + cout << "Ideal values: C1 =" << C1 << " C2 =" << C2 << " C3 =" << C3 << "\n"; + cout << "R1 =" << R1 << " R2 =" << R2 << "\n"; +#endif + + /// Pick the nearest e6 values for caps C2 and C3. +#if SHOW_CALC + cout << "Nearest to " << C2 << " is " << nearest(C2, _e6) << "\n"; + cout << "Nearest to " << C3 << " is " << nearest(C3, _e6) << "\n"; +#endif + C2 = nearest(C2, _e6); + C3 = nearest(C3, _e6); + C1 = -gain * C2; + + /// Adjust resistors to get back to desired q, keeping T unchanged + R1 = T / (q * (C1 + C3)); + R2 = T * T / (C2 * C3 * R1); +#endif + double R, C, r, c; +/// Calculate ideal component values + R = 1e4; + C = T / R; + r = 1.0; + c = 1.0; + C2 = C * c; + C3 = C / c; + C1 = C2 / -gain; + R1 = T / (q * (C1 + C2 + C3)); + R2 = R * R / R1; + cout << "\nIdeal values: C1 =" << C1 << " C2 =" << C2 << " C3 =" << C3 << "\n"; + cout << "R1 =" << R1 << " R2 =" << R2 << "\n"; + +/// Convert to more practical components, capacitors at least! + cout << "\nPractical values:\n"; + C2 = nearest(C2, _e6); + C3 = nearest(C3, _e6); + C1 = -gain * C2; + R1 = T / (q * (C1 + C2 + C3)); + R2 = T * T / (R1 * C2 * C3); + + +#if SHOW_CALC + cout << "\nEnd synthesise_high\n"; +#endif +} + + + +/// Calculate gain, T and q from component values for a high-pass filter +void stage::R_high_pass(void) +{ + gain = -C1/C2; + T = sqrt(C3*C2*R1*R2); + q = T / (R1*(C1 + C3)); +} + + + + +void TFilter::Synth_Rauch(void) +{ + int i; + stage *pstage; + ofstream file; + file.open("./Circuit.txt"); + file << "Order = " << poles << "\n"; + for(i=0, pstage=st; ifclass = fclass; + pstage->T = st[i].T; + pstage->q = st[i].q; + pstage->gain = -1.0; + cout << "\n*************************************\nSecond order stage: Rauch\n"; + cout << "Stage " << i+1 << "\n"; + switch(pstage->fclass) { + case Lowpass: pstage->synthesise_R_low( ); file << "Lowpass\n"; break; + case Highpass: pstage->synthesise_R_high( ); file << "Highpass\n";break; + case Bandpass: pstage->synthesise_R_band( ); file << "Bandpass\n";break; + default: cout << "Unknown fclass\n"; exit(-1); + } +// cout << "\n*************************************\nSecond order stage: Rauch\n"; + file << "Stage = " << i << "\n"; + file << "Rauch\n"; + cout << "R1: " << pstage->R1; file << "R1 = " << pstage->R1; + cout << ", R2: " << pstage->R2; file << "\nR2 = " << pstage->R2; + if((pstage->fclass == Lowpass)||(pstage->fclass == Bandpass)) { cout << ", R3: " << pstage->R3; file << "\nR3 = " << pstage->R3;} + cout << "\nC1: " << pstage->C1; file << "\nC1 = " << pstage->C1; + cout << ", C2: " << pstage->C2; file << "\nC2 = " << pstage->C2; + if(pstage->fclass == Highpass) { cout << ", C3: " << pstage->C3; file << "\nC3 = " << pstage->C3; } + cout << "\n"; file << "\n"; + pstage++; + } + // Now for the odd pole if there is one. + if(poles%2) { + pstage->fclass = fclass; + pstage->T = abs(st[i].T); + pstage->R1 = 1E4; + pstage->C1 = pstage->T / pstage->R1; + pstage->C1 = nearest(pstage->C1, _e6); + pstage->R1 = pstage->T / pstage->C1; + switch(pstage->fclass) { + case Lowpass: break; + case Highpass: break; + case Bandpass: cout << "Impossible! order of bandpass filter cannot be odd.\n"; return; + default: cout << "Unknown fclass\n"; exit(-1); + } + cout << "\n*************************************\nFirst order stage:\n"; + file << "First order stage:\n"; + cout << "R1: " << pstage->R1; file << "R1 = " << pstage->R1; + cout << "\nC1: " << pstage->C1 << "\n"; file << "\nC1 = " << pstage->C1; + } + cout << "*************************************\n"; + if(file.is_open( )) file.close( ); +} + + + +#if false +int main( ) +{ + char c; + do { + cout << "Synthesise or Analyse?\n"; cin >> c; + if(c == 'S' || c == 's') { + do { + cout << "Lowpass, Bandpass or Highpass?\n"; cin >> c; + if(c != 'L' && c != 'l' && c != 'B' && c != 'b' && c != 'H' && c != 'h') continue; + } while(false); + do { + cout << "Gain:\n"; cin >> stage1.gain; + if(stage1.gain >= 0.0) cout << "No! Gain must be negative.\n"; + } while(stage1.gain >= 0.0); + cout << "T:\n"; cin >> stage1.T; + cout << "q:\n"; cin >> stage1.q; + + switch(c) { + case 'L': + case 'l': stage1.synthesise_low( ); break; + case 'B': + case 'b': stage1.synthesise_band( ); break; + case 'H': + case 'h': stage1.synthesise_high( ); break; + } + cout << "C1 =" << stage1.C1; + cout << " C2 =" << stage1.C2; + if(c == 'h' || c == 'H') cout << " C3 =" << stage1.C3; + cout << "\n"; + cout << "R1 =" << stage1.R1; + cout << " R2 =" << stage1.R2; + if(c == 'l' || c == 'L') cout << " R3 =" << stage1.R3 << "\n"; + + switch(c) { + case 'L': + case 'l': stage1.low_pass( ); break; + case 'B': + case 'b': stage1.band_pass( ); break; + case 'H': + case 'h': stage1.high_pass( ); break; + } + cout << "Check: gain = " << stage1.gain << " T = " << stage1.T << " q = " << stage1.q << "\n"; + } else { + cout << "Lowpass, Bandpass or Highpass?\n"; cin >> c; + if(c != 'L' && c != 'l' && c != 'B' && c != 'b' && c != 'H' && c != 'h') continue; + cout << "R1: \n"; cin >> stage1.R1; + cout << "R2: \n"; cin >> stage1.R2; + if(c == 'L' || c == 'l') { cout << "R3: \n"; cin >> stage1.R3; } + cout << "C1: \n"; cin >> stage1.C1; + cout << "C2: \n"; cin >> stage1.C2; + if(c == 'H' || c == 'h') { cout << "C3: \n"; cin >> stage1.C3; } + switch(c) { + case 'L': + case 'l': stage1.low_pass( ); break; + case 'B': + case 'b': stage1.band_pass( ); break; + case 'H': + case 'h': stage1.high_pass( ); break; + } + cout << "gain = " << stage1.gain << " T = " << stage1.T << " q = " << stage1.q << "\n"; + } + cout << "Again?\n"; + cin >> c; + } while(c == 'y' || c == 'Y'); +} +#endif + + + diff --git a/Run b/Run new file mode 100644 index 0000000..e9569e3 --- /dev/null +++ b/Run @@ -0,0 +1,5 @@ +#! /bin/bash +./rbfilter +echo "********************" +read + diff --git a/Sallen_and_Key.cpp b/Sallen_and_Key.cpp new file mode 100644 index 0000000..e57eb9e --- /dev/null +++ b/Sallen_and_Key.cpp @@ -0,0 +1,325 @@ +#include +#include +#include +#include +#include +#include "Calcs.h" + +#if SHOW_FILE_COMPILING +#pragma message "Compiling Sallen_and_Key.cpp" +#endif + +/*! \file Sallen_and_Key.cpp + This program calculates the component values for a Sallen and Key stage to give a specified T and q. +*/ + +using namespace std; + + +/* +class stage { +public: + double T, q; + double R1, R2, R3, C1, C2; + double gain; + char type; + circuit_class cct; + void low_pass(void); + void high_pass(void); + void band_pass(void); + void synthesise_SK_low(void); + void synthesise_SK_high(void); + void synthesise_SK_band(void); +}; +*/ + +extern double e24[ ]; +extern double e12[ ]; +extern double e6[ ]; +enum ee { _e6, _e12, _e24 }; + +extern double nearest(double v, ee e1); + +double Fn_e6(double c) +{ + int i = 0; + double temp; + float e6[] = { 10.0, 6.8, 4.7, 3.3, 2.2, 1.5, 1.0, 0.68 }; + double exponent = pow10(int(log10(c))); + double mantissa = c / exponent; + cout << "mantissa = " << mantissa << " exponent = " << exponent << "\n"; + do { + temp = sqrt(e6[i] * e6[i+1]) / 10.0; + if(temp <= mantissa) break; + i++; + if(i > 7) { cout << "i Error!\n"; return(0); } + } while(1); + return(e6[i] * exponent); +} + + + +double Fn_e12(double c) +{ + int i = 0; + double temp; + float e12[] = { 10.0, 8.2, 6.8, 5.6, 4.7, 3.9, 3.3, 2.7, 2.2, 1.8, 1.5, 1.2, 1.0, 0.82 }; + double exponent = pow10(int(log10(c))); + double mantissa = c / exponent; + do { + temp = sqrt(e12[i] * e12[i+1]) / 10.0; + if(temp <= mantissa) break; + i++; + if(i > 13) { cout << "i Error!\n"; return(0); } + } while(1); + return(e12[i] * exponent); +} + + + +void low( ) +{ + +} + + + +void stage::synthesise_SK_low(void) +{ +#if SHOW_CALC + cout << "stage::synthesise_SK_low\n"; +#endif +#if true + double aa, bb, cc; + double r = 1e4; + double c = T / r; + // q = T / (C1 * R1 + C1 * R2 + (1.0 - gain) * C2 * R1); + double d = sqrt(2.0)/1.25; + do { + d *= 1.25; + C1 = c / d; + C2 = c * d; +#if SHOW_CALC + cout << "C1 = " << C1 << ", C2 = " << C2 << "\n"; +#endif + // R1 = r / s; + // R2 = r * s; + // c / d * r * s^2 + c / d * r + (1.0 - gain) * c * d * r - s * T / q = 0 + aa = c / d * r; + bb = -T / q; + cc = c / d * r + (1.0 - gain) * c * d * r; + } while(bb * bb < 5.0 * aa * cc); + double sq = sqrt(bb * bb - 4.0 * aa * cc); +#if SHOW_CALC + cout << "-bb = " << -bb << ", sq = " << sq << ", aa = " << aa << "\n"; +#endif + double s1 = (-bb + sq) / (2.0 * aa); + double s2 = (-bb - sq) / (2.0 * aa); + + // Now choose e6 preferred values of capacitor + C1 = nearest(C1, _e6); + C2 = nearest(C2, _e6); + c = sqrt(C1 * C2); + d = sqrt(C2 / C1); + r = sqrt(T*T / (C1 * C2)); + aa = c / d * r; + bb = -T / q; + cc = c / d * r + (1.0 - gain) * c * d * r; + sq = sqrt(bb * bb - 4.0 * aa * cc); + s1 = (-bb + sq) / (2.0 * aa); + s2 = (-bb - sq) / (2.0 * aa); + + R1 = r / s1; + R2 = r * s1; +#if SHOW_CALC + cout << "C1 = " << C1 << ", C2 = " << C2 << ", R1 = " << R1 << ", R2 = " << R2 << "\n"; + cout << "T =" << sqrt(R1 * R2 * C1 * C2) << ", q =" << sqrt(R1 * R2 * C1 * C2) / (C1 * R1 + C1 * R2 + (1.0 - gain) * C2 * R1) << "\n"; +#endif + R1 = r / s2; + R2 = r * s2; +#if SHOW_CALC + cout << "C1 = " << C1 << ", C2 = " << C2 << ", R1 = " << R1 << ", R2 = " << R2 << "\n"; + cout << "T =" << sqrt(R1 * R2 * C1 * C2) << ", q =" << sqrt(R1 * R2 * C1 * C2) / (C1 * R1 + C1 * R2 + (1.0 - gain) * C2 * R1) << "\n"; +#endif + +#else +// double k = 1.0; + double aa, bb, cc; + double r = 1e4; + double c = T / r; + // q = T / (C1 * R1 + C1 * R2 + (1.0 - gain) * C2 * R1); + double d = sqrt(2.0)/1.25; + do { + d *= 1.25; + C1 = c / d; + C2 = c * d; + cout << "C1 = " << C1 << ", C2 = " << C2 << "\n"; + // R1 = r / s; + // R2 = r * s; + // c / d * r * s^2 + c / d * r + (1.0 - gain) * c * d * r - s * T / q = 0 + aa = c / d * r; + bb = -T / q; + cc = c / d * r + (1.0 - gain) * c * d * r; + } while(bb * bb < 5.0 * aa * cc); + double sq = sqrt(bb * bb - 4.0 * aa * cc); + cout << "-bb = " << -bb << ", sq = " << sq << ", aa = " << aa << "\n"; + double s1 = (-bb + sq) / (2.0 * aa); + double s2 = (-bb - sq) / (2.0 * aa); + + R1 = r / s1; + R2 = r * s1; + cout << "C1 = " << C1 << ", C2 = " << C2 << ", R1 = " << R1 << ", R2 = " << R2 << "\n"; +// R1 = R1, R2 = R2, C1 = C1, C2 = C2, R3 = 0.0; + + R1 = r / s2; + R2 = r * s2; + cout << "C1 = " << C1 << ", C2 = " << C2 << ", R1 = " << R1 << ", R2 = " << R2 << "\n"; +#endif + +#if SHOW_CALC + cout << "End stage::synthesise_SK_low\n"; +#endif +} + + + +void stage::synthesise_SK_high(void) +{ + double cf; + R1 = 47.0E3; + R2 = R1 * (1.0 / (4.0 * q * q) + (gain - 1.0) * R1); + C1 = T / (2.0 * R2 * q); + cf = Fn_e6(C1) / C1; + C1 = C1 * cf; C2 = C1; + R1 = R1 / cf; R2 = R2 / cf; +} + + + +/** Synthesize Sallen and Key bandpass stage. +Let R1 = R3 = R, R2 = 2R, C1 = C2 = C. +Then set q = 1 / (3 - k) i.e. k = 3.0 - 1/q +w0 = 1 / (R * C) +[The maximum gain of the filter stage will be k / (3 - k)] +*/ +void stage::synthesise_SK_band(void) +{ + double c, r; + gain = 3.0 - 1.0 / q; + r = 1e4; + c = T / r; + C1 = C2 = nearest(c, _e6); + r = T / C1; + R1 = R3 = r; + R2 = 2.0 * r; + +/* cout << "Gain = " << gain; + cout << "\nR1 = " << R1 << ", R2 = " << R2 << ", R3 = " << R3 << "\n"; + cout << "C1 =" << C1 << ", C2 =" << C2 /* << "v =" << v << " b =" << b* / << "\n"; +*/ +} + + + +void TFilter::Synth_SallKey(void) +{ + int i; + ofstream file; + file.open("./Circuit.txt"); + file << "Order = " << poles << "\n"; + for(i=0; i " << Fn_e12(123.0) << "\n"; + cout << "99.0 -> " << Fn_e12(99.0) << "\n"; + cout << "3000.0 -> " << Fn_e12(3000.0) << "\n"; + cout << "1800000.0 -> " << Fn_e12(1800000.0) << "\n"; +*/ + +/* s1.T = 1e-3; + s1.q = 0.691; + s1.gain = 2.0; +*/ + cout << "L, H or B:\n"; cin >> s1.type; + if(s1.type != 'L' && s1.type != 'H' && s1.type != 'B' && s1.type != 'l' && s1.type != 'h' && s1.type != 'b') { + cout << "Not a valid option!\n"; return(-1); + } + cout << "Gain: \n"; cin >> s1.gain; + cout << "T: \n"; cin >> s1.T; + cout << "q: \n"; cin >> s1.q; + switch(s1.type) { + case 'L': + case 'l': s1.synthesise_SK_low( ); break; + case 'H': + case 'h': s1.synthesise_SK_lowh( ); break; + case 'B': + case 'b': s1.synthesise_SK_lowb( ); break; + default: cout << "\nThat shouldn't happen!\n"; exit(-1); + } + cout << "R1: " << s1.R1 << "\n"; + cout << "R2: " << s1.R2 << "\n"; + cout << "C1: " << s1.C1 << "\n"; + cout << "C2: " << s1.C2 << "\n"; +} +#endif + + + + + diff --git a/ToDo list.odt b/ToDo list.odt new file mode 100644 index 0000000..7f6bbd2 Binary files /dev/null and b/ToDo list.odt differ diff --git a/bilinear.cpp b/bilinear.cpp new file mode 100644 index 0000000..281c1e1 --- /dev/null +++ b/bilinear.cpp @@ -0,0 +1,17 @@ +#include "math.h" +#include +#include "Calcs.h" +#include +#include +#include + + + +std::complex _bilinear(std::complex s, double Ts) +{ + std::complex z = (1.0 + s*Ts/2.0) / (1.0 - s*Ts/2.0); + return(z); +} + + + diff --git a/filter.h b/filter.h new file mode 100644 index 0000000..4ab705a --- /dev/null +++ b/filter.h @@ -0,0 +1,26 @@ +#ifndef FILTER_H +#define FILTER_H + + +#include +#include "calcs.h" + +#define SHOW_FILE_COMPILING 0 + +class TFilter { +public: + complex pole[40]; + void log(string); + void log(string, double); + void log(string, complex); + int poles; + char type; + int zeroes; + double fmax, tmax; + double step_resp[IMAX]; +}; + + +#endif + + diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..a9dde7b --- /dev/null +++ b/main.cpp @@ -0,0 +1,44 @@ +//********************************************************* + +#include "math.h" +#include +#include "calcs.h" +#include "SandK.h" +#include "preferred.h" +#include +#include +#include + +#if SHOW_FILE_COMPILING +#pragma message "Compiling " __FILE__ +#endif + +using std::cout; + +extern TFilter filter; + +void SallenAndKey1(double Tau, double q); + +int main(int argc, char **argv) +{ + cout << nearest(e_12, 1025.4) << "\n"; + cout << nearest(e_12, 1175.4) << "\n"; + filter.poles = 5; + filter.fmax = 10.0; + butterworth(filter); + lowpass(filter, 10.0); + bode_calc(filter); + cout << "\n"; + bessel(filter); + cout << "\n"; + chebyshev(filter); + cout << "\n"; + bode_calc(filter); + + SandK cct1; + cct1.SallenAndKey(t_lowpass, 1.0, 1.0e4, 1.0e4, 0.0, 1.0e-7, 2.0e-7); + cct1.SallenAndKey1(0.001, 0.707); +} + + + diff --git a/rbfilter b/rbfilter new file mode 100644 index 0000000..5902a45 Binary files /dev/null and b/rbfilter differ diff --git a/rbfilter.cpp b/rbfilter.cpp new file mode 100644 index 0000000..59cc81f --- /dev/null +++ b/rbfilter.cpp @@ -0,0 +1,1236 @@ +/*! \mainpage FilterCalcs +(c) 1971 .. 2016 Roger Burghall +The original of this code was written in Fortran for the Digital +Equipment Corporation PDP-12, beginning in the early 1970s, and then +ported to the BBC Model B, and extended to provide more of the +functions described below. This port took place in the late 1980s. A second +port to Windows in the 1990's was abandoned in favour of a third port, +to a Linux PC, only begun in 2013. + +No responsibility is accepted for the consequences of using this software, +and no guarantee is given for its correctness. It is necessary for the user +to understand what they are doing! + +Copyright (C) 2013 Free Software Foundation, Inc. +License GPLv3+: GNU GPL version 3 or later . +This is free software: you are free to change and redistribute it. +There is NO WARRANTY, to the extent permitted by law. + + +This program is intended to enable the user to design active or digital +filters, first in terms of T and q values and zero or one simple lag, +before carrying out circuit design to realise these stages as +either Sallen and Key or Rauch circuits, or as digital filters. + +The intention is to permit the frequency and step responses to be +computed, the response to an arbitrary waveform (eventually; not implemented +in version 1.0), and to design Sallen and Key or Rauch circuits, or transform +the filter to the z-domain. These functions were already implemented in the +BBC Model B version of the suite. + +Thanks are due to Graham Watts for help with the mathematics of impulse +and step response functions. + + +Versions 0.1 to 0.51 RB +Developing code to design filters, compute frequency and time responses etc. +Takes specification via control window; returns information on graphics window and terminal window. + +Version 0.6 June 2016 RB +Added circuit diagram window and code to show and hide diagrams. + +Version 0.7 August 2016 RB +Normalise the cut-off frequency of the prototype filter (0.71: actually works!) + +Version 0.8 August 2016 RB +Added a slider at the top of the graphics window. + +Version 1.0 September 2016 RB +First usable version of this port. + +*/ + +/*! \file rbfilter.cpp +rbfilter.cpp contains code to display windows to provide +a GUI for controlling the calculation of active filters +and in order to display results. + +If porting to another OS this file is expected to need considerable modification. +It is intended that operating system dependant code should be kept in this file only. +*/ + + +#include +#include +#include +#include +#include +#include "Drawing.h" +#include "Calcs.h" +#include +#include + + +#define VERSION 1.0 + +#if SHOW_FILE_COMPILING +#pragma message "Compiling Drawing.cpp" +// or #warning "Compiling Drawing.cpp"? +#endif + +#define XSIZE 800 +#define YSIZE 300 + +#pragma GCC diagnostic ignored "-Wwrite-strings" +#pragma GCC diagnostic ignored "-Wformat-security" + + +static int slider_position; +extern TFilter filter; +GtkWidget *app, /* *window, */ *cct_diagram; +GtkWidget *image; +double xyscale; +gchar str[256]; +GtkWidget *Window1, *Area1; +GtkWidget *scale1; +GtkObject *scale_adj1; +static GdkPixmap *pixmap = NULL; + +bool square = FALSE; +GdkColor TriColour; +// Combi boxes +GtkWidget *Ripple = NULL, *Bandwidth, *Type, *Type2, *Circuit, *Freq, *Atten, *SamplingFreq, *Order; +GtkWidget *LabelR, *LabelB, *LabelS; +// Buttons. +static GtkWidget *vbox1, *vbox2, *sp_button, *t_button, *f_button, *s_button /*, *z_button*/ ; +DrawMode Draw_mode; + +class callback { + public: + static void clicked(GtkWidget *button, gpointer data); + static gint quit(GtkWidget *Widget, GdkEvent *event, gpointer data); +}; + + +/** +Define a method to be called if a button is clicked. +Read all the combo-boxes and correct the filter object in +case calculations have already been done. + +Currently we do not check for valid entries. +*/ +void callback::clicked(GtkWidget *button, gpointer data) +{ +void DrawMap(GtkWidget *, gdouble, gdouble); +void Draw_poles(GtkWidget *widget, gdouble x, gdouble y); +void DrawStep(GtkWidget *widget, gdouble x, gdouble y); +void DrawBode(GtkWidget *widget, gdouble x, gdouble y); +double scale(TFilter); + gchar *text; + int w, h; + int n; + char *string = (char *)data; + // OK button clicked. + g_print("\n"); + g_print(string); + text = (gchar *)gtk_combo_box_get_active_text(GTK_COMBO_BOX(Type)); + if(strncmp(text, "L", 1) == 0) filter.fclass = Lowpass; + else if(strncmp(text, "H", 1) == 0) filter.fclass = Highpass; + else if(strncmp(text, "B", 1) == 0) filter.fclass = Bandpass; + + text = (gchar *)gtk_combo_box_get_active_text(GTK_COMBO_BOX(Type2)); + if(strncmp(text, "Be", 2) == 0) filter.sclass = Bessel; + else if(strncmp(text, "Bu", 2) == 0) filter.sclass = Butterworth; + else if(strncmp(text, "C", 1) == 0) filter.sclass = Chebyshev; + + text = (gchar *)gtk_combo_box_get_active_text(GTK_COMBO_BOX(Circuit)); + if(strncmp(text, "S", 1) == 0) filter.cclass = SallKey; + else if(strncmp(text, "R", 1) == 0) filter.cclass = Rauch; + else if(strncmp(text, "Z", 1) == 0) filter.cclass = ZDomain; + + text = (gchar *)gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(Freq)->entry)); + if(strlen(text)) n = sscanf(text, "%lf", &filter.frequency); + if((n == 0) || (filter.frequency <= 0.0)) { + filter.frequency = 1.0; + gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(Freq)->entry), "?"); + } + + text = (gchar *)gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(Order)->entry)); + if(strlen(text)) sscanf(text, "%d", &filter.poles); + if((n == 0) || (filter.poles < 2) || ((filter.poles < 3) && (filter.fclass != Bandpass))) { + filter.poles = 3; + gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(Order)->entry), "?"); + } + + text = (gchar *)gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(Ripple)->entry)); + if(strlen(text)) sscanf(text, "%lf", &filter.ripple); + if((n == 0) || (filter.ripple < 0.0)) { + filter.ripple = 1.0; + gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(Ripple)->entry), "?"); + } + + text = (gchar *)gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(Bandwidth)->entry)); + if(strlen(text)) sscanf(text, "%lf", &filter.bandwidth); + if((n == 0) || (filter.bandwidth <= 2)) { + filter.bandwidth = filter.frequency/2.0; + gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(Bandwidth)->entry), "?"); + } + + text = (gchar *)gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(SamplingFreq)->entry)); + if(strlen(text)) sscanf(text, "%lf", &filter.samplingfreq); + + filter.Calculate( ); + bode_calc(filter); + filter.step_calc( ); + xyscale = scale(filter); + gdk_window_get_size(Window1->window, &w, &h); + + if(strncmp(string, "Syn", 3) == 0) { + switch(filter.cclass) { + case Rauch: filter.gain = -1.0; filter.Synth_Rauch( ); + switch(filter.fclass) { + case Lowpass: gtk_image_set_from_file ((GtkImage *)image, "./Circuit_diagrams/low_pass_MF.png"); break; + case Bandpass: gtk_image_set_from_file ((GtkImage *)image, "./Circuit_diagrams/band_pass_MF.png"); break; + case Highpass: gtk_image_set_from_file ((GtkImage *)image, "./Circuit_diagrams/high_pass_MF.png"); break; + } + gtk_widget_show(image); + gtk_widget_show(cct_diagram); + break; + case SallKey: filter.gain = 1.0; filter.Synth_SallKey( ); + switch(filter.fclass) { + case Lowpass: gtk_image_set_from_file ((GtkImage *)image, "./Circuit_diagrams/low_pass_SK.png"); break; + case Bandpass: gtk_image_set_from_file ((GtkImage *)image, "./Circuit_diagrams/band_pass_SK.png"); break; + case Highpass: gtk_image_set_from_file ((GtkImage *)image, "./Circuit_diagrams/high_pass_SK.png"); break; + } + gtk_widget_show(image); + gtk_widget_show(cct_diagram); + break; + case ZDomain: filter.gain = 1.0; filter.bilinear( ); + gtk_image_set_from_file ((GtkImage *)image, "./Circuit_diagrams/DirectForm1.png"); + gtk_widget_show(image); + gtk_widget_show(cct_diagram); + break; + default: cout << "Unknown cclass!\n"; exit(-1); + } + } + + if(strncmp(string, "S-p", 2) == 0) { + gtk_widget_hide(scale1); + Draw_mode = Splane; + Draw_poles(Area1, 250, 250); + } + if(strncmp(string, "T-d", 2) == 0) { + gtk_adjustment_set_value (GTK_ADJUSTMENT(scale_adj1), 0.0); + gtk_widget_show(scale1); + Draw_mode = Step; + DrawStep(Area1, 250, 250); + } + if(strncmp(string, "F-d", 2) == 0) { + gtk_adjustment_set_value (GTK_ADJUSTMENT(scale_adj1), (double)FSTEPS/2.0); + gtk_widget_show(scale1); + Draw_mode = Bode; + DrawBode(Area1, 250, 250); + } + + g_print("\n"); +} + + + +/// Define a method to be called if the close icon is clicked. +gint callback::quit(GtkWidget *Widget, GdkEvent *event, gpointer data) +{ + g_print("'Quit' callback\n"); + + gtk_main_quit( ); + return FALSE; +} + + + +/// I would like to make the application ignore the second window 'quit' event, but since I can't I'll quit the application. +gint pseudo_quit(GtkWidget *Widget, GdkEvent *event, gpointer data) +{ + g_print("Second window 'Quit' callback\n"); + gtk_main_quit( ); + return FALSE; +} + + + +/// Draw the Bode diagram. +void DrawBode(GtkWidget *widget, gdouble x, gdouble y) +{ + extern double n_to_freq(int n, double f1, int nmax=FSTEPS, int decades=2); + char str[80]; + gint i, w, h; + gint xx, yy; + gint xx1, yy1, xx2, yy2; + gint width, height; + double a, f; + GdkFont* Font1; + GdkColor Colour1, Colour2; + GdkGC *gc1= gdk_gc_new(widget->window); + GdkGC *gc2= gdk_gc_new(widget->window); + +#if VERBOSE + g_print("\n"); +#endif + + gtk_window_set_title ((GtkWindow *)Window1, (gchar *)"Bode diagram"); + +// Let's colour 'gc1' blue and set the foreground colour to it. + Colour1.red=32000; + Colour1.green=32000; + Colour1.blue=62000; + gdk_gc_set_rgb_fg_color(gc1, &Colour1); + + Colour2.red=32000; + Colour2.green=62000; + Colour2.blue=32000; + gdk_gc_set_rgb_fg_color(gc2, &Colour2); + +// g_print("draw brush\n"); + Font1 = gdk_font_load("*trebuchet*12*"); + if(Font1 == NULL) Font1 = gdk_font_load("*arial*"); + if(Font1 == NULL) Font1 = gdk_font_load("*sans*"); + if(Font1 == NULL) Font1 = gdk_font_load("*helvetica*--14*"); + if(Font1 == NULL) Font1 = gdk_font_load("*helvetica*"); + if(Font1 == NULL) Font1 = gdk_font_load("-misc-fixed-*"); + if(Font1 == NULL) Font1 = gdk_font_load("-bitstream-bitstream charter-*"); + if(Font1 == NULL) Font1 = gdk_font_load("*clean*"); + if(Font1 == NULL) g_print("Failed to find font\n"); + + gdk_window_get_size(widget->window, &w, &h); +// OR gdk_drawable_get_size(widget->window, &width, &height); + + GdkRectangle update_rect; + + update_rect.x = (gint)1; + update_rect.y = (gint)1; + update_rect.width = (gint)w - 2; + update_rect.height = (gint)h - 2; + + gdk_draw_rectangle(widget->window, widget->style->white_gc, TRUE, 0, 0, w, h); + gdk_draw_line(widget->window, gc1, 10, h/5, w-10, h/5); + gdk_draw_line(widget->window, gc1, (w)/10, h, (w)/10, 1); + gdk_draw_string(widget->window, Font1, widget->style->black_gc, (w)/10, h/5, "0,0"); + + yy = h/5 - 0.5*log10(0.708) * 3*h/5; + gdk_draw_line(widget->window, gc2, w/10, yy, 9*w/10, yy); + gdk_draw_string(widget->window, Font1, gc2, (w)/10, yy, "-3dB"); + yy = h/5 - 0.5*log10(0.708*0.708) * 3*h/5; + gdk_draw_line(widget->window, gc2, w/10, yy, 9*w/10, yy); + gdk_draw_string(widget->window, Font1, gc2, (w)/10, yy, "-6dB"); + yy = h/5 - 0.5*log10(0.708*0.708*0.708) * 3*h/5; + gdk_draw_line(widget->window, gc2, w/10, yy, 9*w/10, yy); + gdk_draw_string(widget->window, Font1, gc2, (w)/10, yy, "-9dB"); + if(filter.fclass == Bandpass) gdk_draw_string(widget->window, Font1, widget->style->black_gc, (w)/10, yy/10, "Gain normalised to 1.0"); + +/// Draw the frequency response curve. + for(i=1; iwindow, gc1, xx1, yy1, xx2, yy2); + } + +/// Draw line at measurement frequency + f = n_to_freq(slider_position, filter.fmax); + xx1 = w/10 + (slider_position-1) * 8*w/10 / FSTEPS; + gdk_draw_line(widget->window, gc1, xx1, h, xx1, 1); + sprintf(str, "f = %0.2f Hz", f); + gdk_draw_string(widget->window, Font1, widget->style->black_gc, (7*w)/10, h/10, str); +// a = log10(filter.freq_resp[slider_position-1]); + a = filter.freq_resp[slider_position-1]; + sprintf(str, "Gain = %0.2f ", a); + gdk_draw_string(widget->window, Font1, widget->style->black_gc, (7*w)/10, h/8, str); + +#if VERBOSE + g_print("\n"); +#endif +} + + + +/// Draw the s-plane diagram. +void Draw_poles(GtkWidget *widget, gdouble x, gdouble y) +{ + double scale(TFilter); + + char str[80]; + gint i, w, h; + gint xx, yy; + gint width, height; + GdkFont* Font1; + GdkColor Colour1; + GdkGC *gc1= gdk_gc_new(widget->window); + +#if VERBOSE + g_print("\n"); +#endif + + gtk_window_set_title ((GtkWindow *)Window1, (gchar *)"'s' plane"); + +// Let's colour 'gc1' blue and set the foreground colour to it. + Colour1.red=32000; + Colour1.green=32000; + Colour1.blue=62000; + gdk_gc_set_rgb_fg_color(gc1, &Colour1); + +// g_print("draw brush\n"); + Font1 = gdk_font_load("*trebuchet*12*"); + if(Font1 == NULL) Font1 = gdk_font_load("*arial*"); + if(Font1 == NULL) Font1 = gdk_font_load("*sans*"); + if(Font1 == NULL) Font1 = gdk_font_load("*helvetica*--14*"); + if(Font1 == NULL) Font1 = gdk_font_load("*helvetica*"); + if(Font1 == NULL) Font1 = gdk_font_load("-misc-fixed-*"); + if(Font1 == NULL) Font1 = gdk_font_load("-bitstream-bitstream charter-*"); + if(Font1 == NULL) Font1 = gdk_font_load("*clean*"); + if(Font1 == NULL) g_print("Failed to find font\n"); + + gdk_window_get_size(widget->window, &w, &h); +// OR gdk_drawable_get_size(widget->window, &width, &height); + + GdkRectangle update_rect; + + update_rect.x = (gint)1; + update_rect.y = (gint)1; + update_rect.width = (gint)w - 2; + update_rect.height = (gint)h - 2; + + gdk_draw_rectangle(widget->window, widget->style->white_gc, TRUE, 0, 0, w, h); + gdk_draw_line(widget->window, gc1, 10, h/2, w-10, h/2); + gdk_draw_line(widget->window, gc1, (4*w)/5, h, (4*w)/5, 1); + gdk_draw_string(widget->window, Font1, widget->style->black_gc, (4*w)/5+5, h/2-5, "0,0"); + + xyscale = scale(filter); + + for(i=0; iwindow, widget->style->black_gc, xx-10, h/2 + yy, xx+10, h/2 + yy); + gdk_draw_line(widget->window, widget->style->black_gc, xx, h/2 + yy - 10, xx, h/2 + yy + 10); + sprintf(str, "%1.3lf, %1.2lf", filter.st[i].pole.real(), filter.st[i].pole.imag()); + gdk_draw_string(widget->window, Font1, gc1, xx - 80, h/2 + yy - 15, str); + } + if(filter.type != '0') for(i=0; iwindow, Font1, widget->style->black_gc, w / 10, 20 + i * 15, str); + } + if(filter.zeroes) { + gdk_draw_arc(widget->window, widget->style->black_gc, false, (4*w)/5 - 10, h/2 - 10, 20, 20, 0, 360*64); + sprintf(str, "* %1d", filter.zeroes); + gdk_draw_string(widget->window, Font1, gc1, (4*w)/5 - 20, h/2 + 20, str); + } +#if VERBOSE + g_print("\n"); +#endif +} + + + +/// Draw the filter's step response. +void DrawStep(GtkWidget *widget, gdouble x, gdouble y) +{ + char str[80]; + gint i, w, h; + gint xx1, yy1, xx2, yy2; + gint width, height; + double t, v; + GdkFont* Font1; + GdkColor Colour1; + GdkGC *gc1= gdk_gc_new(widget->window); + +#if VERBOSE + g_print("\n"); +#endif + + gtk_window_set_title ((GtkWindow *)Window1, (gchar *)"Time domain"); + +/// Let's colour 'gc1' blue and set the foreground colour to it. + Colour1.red=32000; + Colour1.green=32000; + Colour1.blue=62000; + gdk_gc_set_rgb_fg_color(gc1, &Colour1); + +/// Select a suitable font. +// g_print("draw brush\n"); + Font1 = gdk_font_load("*trebuchet*12*"); + if(Font1 == NULL) Font1 = gdk_font_load("*arial*"); + if(Font1 == NULL) Font1 = gdk_font_load("*sans*"); + if(Font1 == NULL) Font1 = gdk_font_load("*helvetica*--14*"); + if(Font1 == NULL) Font1 = gdk_font_load("*helvetica*"); + if(Font1 == NULL) Font1 = gdk_font_load("-misc-fixed-*"); + if(Font1 == NULL) Font1 = gdk_font_load("-bitstream-bitstream charter-*"); + if(Font1 == NULL) Font1 = gdk_font_load("*clean*"); + if(Font1 == NULL) g_print("Failed to find font\n"); + +/// Check the size of the window then define an update rectangle. + gdk_window_get_size(widget->window, &w, &h); +// OR gdk_drawable_get_size(widget->window, &width, &height); + + GdkRectangle update_rect; + update_rect.x = (gint)1; + update_rect.y = (gint)1; + update_rect.width = (gint)w - 2; + update_rect.height = (gint)h - 2; + + filter.step_calc( ); + +/// Draw suitable axes. + gdk_draw_rectangle(widget->window, widget->style->white_gc, TRUE, 0, 0, w, h); + switch(filter.fclass) { + case Lowpass: gdk_draw_line(widget->window, gc1, 10, 4*h/5, w-10, 4*h/5); break; + case Bandpass: gdk_draw_line(widget->window, gc1, 10, h/2, w-10, h/2); break; + case Highpass: gdk_draw_line(widget->window, gc1, 10, 3*h/5, w-10, 3*h/5); break; + } + gdk_draw_line(widget->window, gc1, w/10, h, w/10, 1); + +/// Draw the step response curve. + for(i=1; iwindow, gc1, xx1, yy1, xx2, yy2); + } + +/// Draw line at measurement time + t = filter.tmax * slider_position / TSTEPS; + xx1 = w/10 + (slider_position-1) * 8*w/10 / FSTEPS; + gdk_draw_line(widget->window, gc1, xx1, h, xx1, 1); + sprintf(str, "t = %0.2f ", t); + gdk_draw_string(widget->window, Font1, widget->style->black_gc, (7*w)/10, h/8, str); + v = filter.step_resp[slider_position-1]; + sprintf(str, "v = %0.2f at ", v); + gdk_draw_string(widget->window, Font1, widget->style->black_gc, (7*w)/10, h/10, str); + +/// List the stage Ts and qs etc. + if(filter.type != '0') for(i=0; iwindow, Font1, widget->style->black_gc, w / 10, 20 + i * 15, str); + } +#if VERBOSE + g_print("\n"); +#endif +} + + + +/** Draw a rectangle on the screen, and add the axes, poles and +the Ts and qs. */ +void +DrawMap(GtkWidget *widget, gdouble x, gdouble y) +{ +#if VERBOSE + g_print("\n"); +#endif + + switch(Draw_mode) { + case Splane: Draw_poles(widget, 250, 250); + break; + case Step: DrawStep(widget, 250, 250); + break; + case Bode: DrawBode(widget, 250, 250); + break; + default: cout << "\n\n***UNKNOWN DRAW MODE!***\n\n"; + break; + } +#if VERBOSE + g_print("\n"); +#endif +} + + + +/** Define a function to be called if the window is re-exposed. */ +static gboolean expose_event(GtkWidget *widget, GdkEventExpose *event) +{ +#if VERBOSE + g_print("\n"); +#endif + + DrawMap(widget, 0, 0); + +#if VERBOSE + g_print("\n"); +#endif + + return(TRUE); +} + + + +/** If a button is pressed, do what? */ +static gboolean +button_press_event( GtkWidget *widget, GdkEventButton *event ) +{ + gint w, h; + +#if VERBOSE + g_print("\n"); +#endif + + gdk_window_get_size(widget->window, &w, &h); + g_print("button press callback\n"); + + gdk_draw_rectangle(widget->window, widget->style->white_gc, TRUE, 0, 0, w, h); + gdk_draw_rectangle(widget->window, widget->style->black_gc, FALSE, (w/2)-4, (h/2)-4, 8, 8); + if (event->button == 1) DrawMap (widget, event->x, event->y); + +#if VERBOSE + g_print("\n"); +#endif + + return TRUE; +} + + + +/** Redraw the diagram if pointer moves. */ +static gboolean +motion_notify_event( GtkWidget *widget, GdkEventMotion *event ) +{ + int x, y; + GdkModifierType state; + +#if VERBOSE + g_print("\n"); +#endif + + if (event->is_hint) gdk_window_get_pointer (event->window, &x, &y, &state); + else { + x = (gint)event->x; + y = (gint)event->y; + state = (GdkModifierType)event->state; + } + +// if (state & GDK_BUTTON1_MASK) DrawMap (window, x, y); + DrawMap(widget, x, y); + +#if VERBOSE + g_print("\n"); +#endif + + return TRUE; +} + + + +/*! +'configure_event( )' redraws the window during resizing. +*/ +static gboolean +configure_event( GtkWidget *widget, GdkEventConfigure *event ) +{ + gint x, y; +#if VERBOSE + g_print("\n"); +#endif + + if(pixmap) g_object_unref(pixmap); + + pixmap = gdk_pixmap_new(widget->window, + widget->allocation.width, widget->allocation.height, -1); + gdk_draw_rectangle (widget->window, widget->style->white_gc, + TRUE, 0, 0, x = widget->allocation.width, y = widget->allocation.height); + DrawMap(widget, x, y); +#if VERBOSE + g_print("\n"); +#endif + + return TRUE; +} + + + +bool Check_band(void) +{ +const gchar *txt = "Impossible request"; +// Buttons are:- sp_button, t_button, f_button, s_button + if(filter.fclass == Bandpass && filter.poles % 2) { + gtk_widget_set_sensitive(sp_button, false); + gtk_widget_set_sensitive(t_button, false); + gtk_widget_set_sensitive(f_button, false); + gtk_widget_set_sensitive(s_button, false); +/* GtkWidget* msg = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_NONE, txt); + gtk_widget_show(GTK_WIDGET(msg)); */ + } else { + gtk_widget_set_sensitive(sp_button, true); + gtk_widget_set_sensitive(t_button, true); + gtk_widget_set_sensitive(f_button, true); + gtk_widget_set_sensitive(s_button, true); + } +} + + + +/*! +'Type_event' call-back function to process changed data in filter class combo-box. +*/ +void Type_event(GtkComboBox *widget, gpointer data) +{ + gchar *entry_text; + gtk_widget_hide(cct_diagram); + + /// Get the text box contents. + entry_text = gtk_combo_box_get_active_text(widget); + if(strncmp(entry_text, "L", 1) == 0) filter.fclass = Lowpass; + else if(strncmp(entry_text, "H", 1) == 0) filter.fclass = Highpass; + else if(strncmp(entry_text, "B", 1) == 0) { + filter.fclass = Bandpass; + gtk_widget_show(GTK_WIDGET(LabelB)); + gtk_widget_show(GTK_WIDGET(Bandwidth)); + } else { + gtk_widget_hide(GTK_WIDGET(LabelB)); + gtk_widget_hide(GTK_WIDGET(Bandwidth)); + } +// Check_band( ); + printf("Class: <%s>\n", entry_text); +} + + + +/*! +'Type2_event' call-back function to process changed data in filter class combo-box. +*/ +void Type2_event(GtkComboBox *widget, gpointer data) +{ + gchar *entry_text; + gtk_widget_hide(image); + + // Get the text box contents. + entry_text = gtk_combo_box_get_active_text(widget); + if(strncmp(entry_text, "Be", 2) == 0) filter.sclass = Bessel; + else if(strncmp(entry_text, "Bu", 2) == 0) filter.sclass = Butterworth; + else if(strncmp(entry_text, "C", 1) == 0) { + filter.sclass = Chebyshev; + gtk_widget_show(GTK_WIDGET(LabelR)); + gtk_widget_show(GTK_WIDGET(Ripple)); + } else { + gtk_widget_hide(GTK_WIDGET(LabelR)); + gtk_widget_hide(GTK_WIDGET(Ripple)); + } + +// Check_band( ); + printf("Type: <%s>\n", entry_text); +} + + + + +/*! +'Circuit_event' call-back function to process changed data in filter class combo-box. +*/ +void Circuit_event(GtkComboBox *widget, gpointer data) +{ + gchar *entry_text; + gtk_widget_hide(cct_diagram); + + // Get the text box contents. + entry_text = gtk_combo_box_get_active_text(widget); + if(strncmp(entry_text, "S", 1) == 0) filter.cclass = SallKey; + else if(strncmp(entry_text, "R", 1) == 0) filter.cclass = Rauch; + else if(strncmp(entry_text, "D", 1) == 0) { + filter.cclass = ZDomain; + gtk_widget_show(GTK_WIDGET(LabelS)); + gtk_widget_show(GTK_WIDGET(SamplingFreq)); + } else { + gtk_widget_hide(GTK_WIDGET(LabelS)); + gtk_widget_hide(GTK_WIDGET(SamplingFreq)); + } +// if(strncmp(entry_text, "B", 1) == 0) filter.cclass = ????; +// Check_band( ); + printf("Type: <%s>\n", entry_text); +} + + + +/*! +'Freq_callback' call-back function to process changed data in frequency combo-box. +*/ +void Freq_callback(GtkWidget *widget, GtkWidget *textbox) +{ + int n; + gchar *entry_text; + gtk_widget_hide(cct_diagram); + + double T1; +// Get the text box contents. + entry_text = (gchar *)gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(textbox)->entry)); + if(strlen(entry_text)) n = sscanf(entry_text, "%lf", &filter.frequency); +// Check_band( ); + printf("Entry contents 1: <%s>\n", entry_text); + +// Clear box by writing empty string? May cause a problem when you type text! +/* if((n == 0) || (filter.frequency <= 0.0)) { + gtk_entry_set_text (GTK_ENTRY(widget), "1.0"); + filter.frequency = 1.0; + } +*/ +} + + + +/*! +'Atten_callback' call-back function to process changed data in attenuation combo-box. +*/ +void Atten_callback(GtkWidget *widget, GtkWidget *textbox) +{ + int n; + double a; + gchar *entry_text; + gtk_widget_hide(cct_diagram); + + double T1; +// Get the text box contents. + entry_text = (gchar *)gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(textbox)->entry)); + if(strlen(entry_text)) n = sscanf(entry_text, "%lf", &a); + +// Clear box by writing empty string? May cause a problem when you type text! +// if((n == 0) || (a > 0.0)) { gtk_entry_set_text (GTK_ENTRY(widget), "-3.0"); a = -3.0; } + +/** dB = 20 * log10(ratio) +e.g. if ratio = 0.707, dB = 3.01 +Thus, if we have the value in dB: +ratio = pow10(dB / 20) +*/ + filter.a0 = pow10(-abs(a) / 20.0); + +// Check_band( ); + printf("Entry contents 1a: <%s>\n", entry_text); +} + + + +/*! +'SFreq_callback' call-back function to process changed data in frequency combo-box. +*/ +void SFreq_callback(GtkWidget *widget, GtkWidget *textbox) +{ + int n; + gchar *entry_text; + gtk_widget_hide(cct_diagram); + + double T1; + // Get the text box contents. + entry_text = (gchar *)gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(textbox)->entry)); + if(strlen(entry_text)) n = sscanf(entry_text, "%lf", &filter.frequency); +/* Check_band( ); */ + printf("Entry contents 1a: <%s>\n", entry_text); + // Clear box by writing empty string? May cause a problem when you type text! +/* if(n == 0) { + gtk_entry_set_text (GTK_ENTRY(widget), "1.0"); + filter.frequency = 1.0; + } +*/ +} + + + +/*! +'q_callback' call-back function to process changed data in filter 'q' combo-box. +*/ +void q_callback(GtkWidget *widget, GtkWidget *textbox) +{ + int n; + gchar *entry_text; + gtk_widget_hide(cct_diagram); + + // Get the text box contents. + entry_text = (gchar *)gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(textbox)->entry)); +// if(strlen(entry_text)) n = sscanf(entry_text, "%lf", &filter.q); +// Check_band( ); + printf("Entry contents 2: <%s>\n", entry_text); + // Clear box by writing empty string? May cause a problem when you type text! +// if(n == 0) gtk_entry_set_text (GTK_ENTRY(widget), "?"); +} + + + +/*! +'order_callback' call-back function to process changed data in filter 'order' combo-box. +*/ +void order_callback(GtkWidget *widget, GtkWidget *textbox) +{ + int n; + gchar *entry_text; + gtk_widget_hide(cct_diagram); + + // Get the text box contents. + entry_text = (gchar *)gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(textbox)->entry)); + if(strlen(entry_text)) n = sscanf(entry_text, "%d", &filter.poles); +// Check_band( ); + printf("Entry contents 3: <%s>\n", entry_text); + // Clear box by writing empty string? May cause a problem when you type text! +// if(n == 0) gtk_entry_set_text (GTK_ENTRY(widget), "?"); +} + + + +/*! +'ripple_callback' call-back function to process changed data in filter 'ripple' combo-box. +*/ +void ripple_callback(GtkWidget *widget, GtkWidget *textbox) +{ + int n; + gchar *entry_text; + gtk_widget_hide(cct_diagram); + + // Get the text box contents. + entry_text = (gchar *)gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(textbox)->entry)); + if(strlen(entry_text)) n = sscanf(entry_text, "%lf", &filter.ripple); +// Check_band( ); + printf("Entry contents 4: <%s>\n", entry_text); + // Clear box by writing empty string? May cause a problem when you type text! +// if(n == 0) gtk_entry_set_text(GTK_ENTRY(widget), "?"); +} + + + +/*! +'bandwidth_callback' call-back function to process changed data in filter 'ripple' combo-box. +*/ +void bandwidth_callback(GtkWidget *widget, GtkWidget *textbox) +{ + int n; + gchar *entry_text; + gtk_widget_hide(cct_diagram); + + // Get the text box contents. + entry_text = (gchar *)gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(textbox)->entry)); + if(strlen(entry_text)) n = sscanf(entry_text, "%lf", &filter.bandwidth); +// Check_band( ); + printf("Entry contents 5: <%s>\n", entry_text); + // Clear box by writing empty string? May cause a problem when you type text! +// if(n == 0) gtk_entry_set_text (GTK_ENTRY(widget), "?"); +} + + + + +/** 'time_event' reads slider value at regular intervals. This avoids large +numbers of redrawings as the slider is moved. +*/ +gboolean time_event(GtkWidget *widget) +{ + static int last_value = -1; + + if (widget->window == NULL) return FALSE; + + GDateTime *now = g_date_time_new_now_local(); + gchar *my_time = g_date_time_format(now, "%H:%M:%S"); + + slider_position = gtk_adjustment_get_value(GTK_ADJUSTMENT(scale_adj1)); + if(slider_position != last_value) { + sprintf(str, "Scale position = %d\n", slider_position); + last_value = slider_position; +#if VERBOSE + g_print(str); +#endif + gtk_widget_queue_draw (widget); + } + + g_free(my_time); + g_date_time_unref(now); + + return TRUE; +} + + + + +int main(int argc, char *argv[ ]) +{ + std::cout << "'rbfilter' version " << VERSION << "\n"; + std::cout << "Copyright (c) Roger Burghall 2013..2016\n"; + + ofstream logfile; + logfile.open("./rbfilter.log", ios::trunc); + logfile << "rbfilter log file.\n******************\n"; + logfile.close( ); + + GtkWidget *hbox, *vbox_draw, *vbox_main; + GList *glist, *glist1; + + GtkWidget *vbox_cct; + +//* Initialise Gnome; similar to gtk_init(). */ + gnome_init("Filter-designer", "3.01", argc, argv); +/// First window, for controls. + app = gnome_app_new("drawing-example", "Control"); + assert(app != NULL); +/// Draw a second window for graphs etc. + Window1 = gtk_window_new(GTK_WINDOW_TOPLEVEL); + assert(Window1 != NULL); + /// Centre the graphics window. + gtk_window_set_position ((GtkWindow *)Window1, GTK_WIN_POS_CENTER); + gtk_widget_set_size_request(GTK_WIDGET(Window1), 600, 650); + gtk_window_set_title ((GtkWindow *)Window1, (gchar *)"Graphics"); + + vbox_draw = gtk_vbox_new(FALSE, 5); + + scale_adj1 = gtk_adjustment_new (FSTEPS/2.0, 0.0, (double)FSTEPS, 10.0, 10.0, 10.0); + scale1 = gtk_hscale_new (GTK_ADJUSTMENT(scale_adj1)); + gtk_scale_set_draw_value ((GtkScale*)scale1, FALSE); + +/// Put a vbox in the window and the slider in the vbox. + gtk_container_add(GTK_CONTAINER(Window1), vbox_draw); + gtk_box_pack_start(GTK_BOX(vbox_draw), scale1, FALSE, FALSE, 0); + + gtk_window_set_default_size (GTK_WINDOW(Window1), 400, 300); + +/// Create a drawing area which must receive extra space when window is enlarged. + Area1 = gtk_drawing_area_new( ); + gtk_widget_set_size_request(GTK_WIDGET(Area1), XSIZE, YSIZE); + gtk_box_pack_start(GTK_BOX(vbox_draw), Area1, TRUE, TRUE, 0); + + gtk_widget_show(vbox_draw); + gtk_widget_show(Area1); + gtk_widget_hide(scale1); + +/// Draw a third window, for showing the circuit diagrams + cct_diagram = gtk_window_new(GTK_WINDOW_TOPLEVEL); + assert(cct_diagram != NULL); + gtk_window_set_position ((GtkWindow *)cct_diagram, GTK_WIN_POS_NONE); + gtk_widget_set_size_request(GTK_WIDGET(cct_diagram), 650, 365); + gtk_window_set_title ((GtkWindow *)cct_diagram, (gchar *)"Realisation"); + GtkWidget *cct_box = gtk_hbox_new(false, 0); + image = gtk_image_new( ); + gtk_container_add(GTK_CONTAINER(cct_diagram), cct_box); + gtk_box_pack_start(GTK_BOX(cct_box), image, false, false, 3); +/// Remove close icon from the realisation window. + gtk_window_set_deletable((GtkWindow *)cct_diagram, false); + gtk_widget_show(image); + gtk_widget_show(cct_box); + gtk_widget_hide(cct_diagram); + + Draw_mode = Splane; + +/// Create a 'vbox' and place it in the application. + vbox_main = gtk_vbox_new(FALSE, 5); + gnome_app_set_contents(GNOME_APP(app), vbox_main); + gtk_widget_show(vbox_main); + +/// Position the control window to the left of the screen. + /// Check size of screen. + gint scr_w = gdk_screen_width( ); + gint scr_h = gdk_screen_height( ); + /// Place the window. + gtk_window_move ((GtkWindow *)app, scr_w/10, scr_h/5); + +/// Create an 'hbox' and put it in the 'vbox' + hbox = gtk_hbox_new(FALSE, 5); + gtk_container_add (GTK_CONTAINER (vbox_main), hbox); + gtk_widget_show(hbox); + +/// Create button 'vbox'es and place them in the 'hbox'. + vbox1 = gtk_vbox_new(FALSE, 5); + vbox2 = gtk_vbox_new(FALSE, 5); + gtk_box_pack_start (GTK_BOX (hbox), vbox1, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (hbox), vbox2, TRUE, TRUE, 0); + gtk_widget_show(vbox1); + gtk_widget_show(vbox2); + +/// Put data entry boxes in 'vbox1':- +/// Combobox permitting only preset entries for filter class + GtkWidget *Label = gtk_label_new ("Class"); + gtk_box_pack_start(GTK_BOX(vbox1), GTK_WIDGET(Label), TRUE, FALSE, 0); + gtk_widget_show(GTK_WIDGET(Label)); + Type = /* GTK_COMBO_BOX */ (gtk_combo_box_new_text( )); + gtk_combo_box_append_text(GTK_COMBO_BOX(Type), "Low-pass"); + gtk_combo_box_append_text(GTK_COMBO_BOX(Type), "High-pass"); + gtk_combo_box_append_text(GTK_COMBO_BOX(Type), "Band-pass"); + gtk_combo_box_set_active(GTK_COMBO_BOX(Type), 0); + gtk_box_pack_start(GTK_BOX(vbox1), GTK_WIDGET(Type), TRUE, TRUE, 5); + g_signal_connect(GTK_OBJECT(Type), "changed", GTK_SIGNAL_FUNC(Type_event), Type); + gtk_widget_show(GTK_WIDGET(Type)); + + Type2 = /* GTK_COMBO_BOX */ (gtk_combo_box_new_text( )); + gtk_combo_box_append_text(GTK_COMBO_BOX(Type2), "Bessel"); + gtk_combo_box_append_text(GTK_COMBO_BOX(Type2), "Butterworth"); + gtk_combo_box_append_text(GTK_COMBO_BOX(Type2), "Chebyshev"); + gtk_combo_box_set_active(GTK_COMBO_BOX(Type2), 0); + gtk_box_pack_start(GTK_BOX(vbox1), GTK_WIDGET(Type2), TRUE, TRUE, 5); + g_signal_connect(GTK_OBJECT(Type2), "changed", GTK_SIGNAL_FUNC(Type2_event), Type2); + gtk_widget_show(GTK_WIDGET(Type2)); + +/// Combobox permitting only preset entries for filter class + Label = gtk_label_new ("Circuit"); + gtk_box_pack_start(GTK_BOX(vbox1), GTK_WIDGET(Label), TRUE, FALSE, 0); + gtk_widget_show(GTK_WIDGET(Label)); + Circuit = /* GTK_COMBO_BOX */ (gtk_combo_box_new_text( )); + gtk_combo_box_append_text(GTK_COMBO_BOX(Circuit), "Sallen and Key"); + gtk_combo_box_append_text(GTK_COMBO_BOX(Circuit), "Rauch"); + gtk_combo_box_append_text(GTK_COMBO_BOX(Circuit), "Discrete"); + gtk_combo_box_set_active(GTK_COMBO_BOX(Circuit), 0); + gtk_box_pack_start(GTK_BOX(vbox1), GTK_WIDGET(Circuit), TRUE, TRUE, 5); + g_signal_connect(GTK_OBJECT(Circuit), "changed", GTK_SIGNAL_FUNC(Circuit_event), Circuit); + gtk_widget_show(GTK_WIDGET(Circuit)); + +/// Combobox permitting non-standard entries for cut-off frequency + Label = gtk_label_new ("Freq"); + gtk_box_pack_start(GTK_BOX(vbox1), GTK_WIDGET(Label), TRUE, FALSE, 0); + gtk_widget_show(GTK_WIDGET(Label)); + Freq = gtk_combo_new( ); + gtk_box_pack_start(GTK_BOX(vbox1), GTK_WIDGET(Freq), TRUE, FALSE, 0); + glist = NULL; + glist = g_list_append(glist, (gpointer)"1.0"); + glist = g_list_append(glist, (gpointer)"10.0"); + glist = g_list_append(glist, (gpointer)"100.0"); + gtk_combo_set_popdown_strings(GTK_COMBO(Freq), glist); + g_signal_connect(GTK_COMBO(Freq)->entry, "changed", G_CALLBACK(Freq_callback), Freq); + gtk_widget_show(GTK_WIDGET(Freq)); + +/// Combobox permitting non-standard entries for cut-off attenuation + Label = gtk_label_new ("Atten (dB)"); + gtk_box_pack_start(GTK_BOX(vbox1), GTK_WIDGET(Label), TRUE, FALSE, 0); + gtk_widget_show(GTK_WIDGET(Label)); + Atten = gtk_combo_new( ); + gtk_box_pack_start(GTK_BOX(vbox1), GTK_WIDGET(Atten), TRUE, FALSE, 0); + glist = NULL; + glist = g_list_append(glist, (gpointer)"-3.0"); + glist = g_list_append(glist, (gpointer)"-6.0"); + glist = g_list_append(glist, (gpointer)"-9.0"); + gtk_combo_set_popdown_strings(GTK_COMBO(Atten), glist); + g_signal_connect(GTK_COMBO(Atten)->entry, "changed", G_CALLBACK(Atten_callback), Atten); + gtk_widget_show(GTK_WIDGET(Atten)); + +/// Combobox permitting non-standard entries for sampling frequency + LabelS = gtk_label_new ("Sampling Freq"); + gtk_box_pack_start(GTK_BOX(vbox1), GTK_WIDGET(LabelS), TRUE, FALSE, 0); +// gtk_widget_show(GTK_WIDGET(Label)); + SamplingFreq = gtk_combo_new( ); + gtk_box_pack_start(GTK_BOX(vbox1), GTK_WIDGET(SamplingFreq), TRUE, FALSE, 0); + glist = NULL; + glist = g_list_append(glist, (gpointer)"100.0"); + glist = g_list_append(glist, (gpointer)"1000.0"); + glist = g_list_append(glist, (gpointer)"100000.0"); + gtk_combo_set_popdown_strings(GTK_COMBO(SamplingFreq), glist); + g_signal_connect(GTK_COMBO(Freq)->entry, "changed", G_CALLBACK(SFreq_callback), SamplingFreq); +// gtk_widget_show(GTK_WIDGET(SamplingFreq)); + +/// Combobox permitting non-standard entries for filter order + Label = gtk_label_new ("Prototype order"); + gtk_box_pack_start(GTK_BOX(vbox1), GTK_WIDGET(Label), TRUE, FALSE, 0); + gtk_widget_show(GTK_WIDGET(Label)); + Order = gtk_combo_new( ); + gtk_box_pack_start(GTK_BOX(vbox1), GTK_WIDGET(Order), TRUE, FALSE, 0); + glist = NULL; + glist = g_list_append(glist, (gpointer)"3"); + glist = g_list_append(glist, (gpointer)"4"); + glist = g_list_append(glist, (gpointer)"5"); + gtk_combo_set_popdown_strings(GTK_COMBO(Order), glist); + g_signal_connect(GTK_COMBO(Order)->entry, "changed", G_CALLBACK(order_callback), Order); + gtk_widget_show(GTK_WIDGET(Order)); + +/// Combobox permitting non-standard entries for filter ripple (Chebyshev only) + LabelR = gtk_label_new ("ripple"); + gtk_box_pack_start(GTK_BOX(vbox1), GTK_WIDGET(LabelR), TRUE, FALSE, 0); + Ripple = gtk_combo_new( ); + gtk_box_pack_start(GTK_BOX(vbox1), GTK_WIDGET(Ripple), TRUE, FALSE, 0); + glist1 = NULL; + glist1 = g_list_append(glist1, (gpointer)"0.5"); + glist1 = g_list_append(glist1, (gpointer)"1.0"); + glist1 = g_list_append(glist1, (gpointer)"2.0"); + gtk_combo_set_popdown_strings(GTK_COMBO(Ripple), glist1); + g_signal_connect(GTK_COMBO(Ripple)->entry, "changed", G_CALLBACK(ripple_callback), Ripple); + +/// Combobox permitting non-standard entries for filter bandwidth (Bandpass only) + LabelB = gtk_label_new ("bandwidth"); + gtk_box_pack_start(GTK_BOX(vbox1), GTK_WIDGET(LabelB), TRUE, FALSE, 0); + Bandwidth = gtk_combo_new( ); + gtk_box_pack_start(GTK_BOX(vbox1), GTK_WIDGET(Bandwidth), TRUE, FALSE, 0); + glist1 = NULL; + glist1 = g_list_append(glist1, (gpointer)"0.25"); + glist1 = g_list_append(glist1, (gpointer)"0.125"); + glist1 = g_list_append(glist1, (gpointer)"0.0625"); + gtk_combo_set_popdown_strings(GTK_COMBO(Bandwidth), glist1); + g_signal_connect(GTK_COMBO(Bandwidth)->entry, "changed", G_CALLBACK(bandwidth_callback), Bandwidth); + +/// Create "S-p", "T-d" and "F-d" buttons and place them in 'vbox2'. + sp_button = gtk_button_new_with_label ("s-plane"); + t_button = gtk_button_new_with_label ("Time"); + f_button = gtk_button_new_with_label ("Freq"); + s_button = gtk_button_new_with_label ("Synth"); +// z_button = gtk_button_new_with_label ("Bilinear"); + gtk_box_pack_start (GTK_BOX (vbox2), sp_button, TRUE, FALSE, 20); + gtk_box_pack_start (GTK_BOX (vbox2), t_button, TRUE, FALSE, 20); + gtk_box_pack_start (GTK_BOX (vbox2), f_button, TRUE, FALSE, 20); + gtk_box_pack_start (GTK_BOX (vbox2), s_button, TRUE, FALSE, 20); +// gtk_box_pack_start (GTK_BOX (vbox2), z_button, TRUE, FALSE, 20); + gtk_widget_show(sp_button); + gtk_widget_show(t_button); + gtk_widget_show(f_button); + gtk_widget_show(s_button); +// gtk_widget_show(z_button); + +/// Connect button signals + gchar *Event2 = (gchar *)"clicked"; + gchar *Ctrl1 = (gchar *)"S-p\n"; + gchar *Ctrl2 = (gchar *)"T-d\n"; + gchar *Ctrl3 = (gchar *)"F-d\n"; + gchar *Ctrl4 = (gchar *)"Syn\n"; + gchar *Ctrl5 = (gchar *)"Z-t\n"; + gtk_signal_connect(GTK_OBJECT (sp_button), Event2, GTK_SIGNAL_FUNC (callback::clicked), Ctrl1); + gtk_signal_connect(GTK_OBJECT (t_button), Event2, GTK_SIGNAL_FUNC (callback::clicked), Ctrl2); + gtk_signal_connect(GTK_OBJECT (f_button), Event2, GTK_SIGNAL_FUNC (callback::clicked), Ctrl3); + gtk_signal_connect(GTK_OBJECT (s_button), Event2, GTK_SIGNAL_FUNC (callback::clicked), Ctrl4); +// gtk_signal_connect(GTK_OBJECT (z_button), Event2, GTK_SIGNAL_FUNC (callback::clicked), Ctrl5); + +//* Bind "destroy" event to gtk_main_quit. */ + gchar *Event1 = "destroy"; + gtk_signal_connect(GTK_OBJECT (app), Event1, + GTK_SIGNAL_FUNC (callback::quit), NULL); + gtk_signal_connect(GTK_OBJECT (Window1), Event1, + GTK_SIGNAL_FUNC (pseudo_quit), NULL); + + gtk_signal_connect(GTK_OBJECT(Area1), "expose_event", GTK_SIGNAL_FUNC(expose_event), NULL); + gtk_signal_connect (GTK_OBJECT(Area1),"configure_event", + (GtkSignalFunc) configure_event, NULL); + gtk_signal_connect (GTK_OBJECT (Area1), "motion_notify_event", + (GtkSignalFunc) motion_notify_event, NULL); + gtk_signal_connect (GTK_OBJECT (Area1), "button_press_event", + GTK_SIGNAL_FUNC(button_press_event), NULL); + + g_timeout_add(500, (GSourceFunc) time_event, (gpointer) Window1); + time_event(Window1); + + gtk_widget_set_events (Window1, GDK_EXPOSURE_MASK + | GDK_LEAVE_NOTIFY_MASK + | GDK_BUTTON_PRESS_MASK + | GDK_POINTER_MOTION_MASK + | GDK_POINTER_MOTION_HINT_MASK); + gtk_drawing_area_size((GtkDrawingArea*)Area1, XSIZE, YSIZE); + + gtk_widget_show(app); + gtk_widget_show(Area1); + gtk_widget_show(Area1); + gtk_widget_show(Window1); + + gtk_main( ); + + return 0; +} + + + diff --git a/using_rbfilter.odt b/using_rbfilter.odt new file mode 100644 index 0000000..74cd311 Binary files /dev/null and b/using_rbfilter.odt differ