3 #include <gsl/gsl_errno.h>
4 #include <gsl/gsl_spline.h>
12 MtuFilter::~MtuFilter()
16 void MtuFilter::GetData(
const std::string filename)
20 ttsdata rawimag, rawreal;
21 double currfreq, currreal, currimag, dummy;
23 double *imag, *real, *freqs;
26 filterfile.open(filename.c_str());
32 while (filterfile.good())
34 filterfile >> currfreq;
35 filterfile.ignore(256,
',');
36 filterfile >> currreal;
37 filterfile.ignore(256,
',');
38 filterfile >> currimag;
39 if (filterfile.good())
41 rawfreqs.push_back(currfreq);
42 rawreal.push_back(currreal);
43 rawimag.push_back(currimag);
46 assert(rawreal.size() == rawimag.size());
47 assert(rawreal.size() == rawfreqs.size());
50 real =
new double[rawreal.size()];
51 imag =
new double[rawimag.size()];
52 freqs =
new double[rawfreqs.size()];
54 for (
unsigned int i = 0; i < rawreal.size(); ++i)
56 real[rawreal.size() - 1 - i] = rawreal.at(i);
57 imag[rawreal.size() - 1 - i] = rawimag.at(i);
58 freqs[rawreal.size() - 1 - i] = rawfreqs.at(i);
61 gsl_interp_accel *accreal = gsl_interp_accel_alloc();
62 gsl_interp_accel *accimag = gsl_interp_accel_alloc();
64 gsl_spline *realspline = gsl_spline_alloc(gsl_interp_cspline,
66 gsl_spline *imagspline = gsl_spline_alloc(gsl_interp_cspline,
69 gsl_spline_init(realspline, freqs, real, rawreal.size());
70 gsl_spline_init(imagspline, freqs, imag, rawimag.size());
72 for (
int i = 0; i < seglength / 2 + 1; ++i)
74 currreal = gsl_spline_eval(realspline, i * freqstep, accreal);
75 currimag = gsl_spline_eval(imagspline, i * freqstep, accimag);
76 FilterCoeff.push_back(currreal + I * currimag);
81 gsl_spline_free(realspline);
82 gsl_spline_free(imagspline);
83 gsl_interp_accel_free(accreal);
84 gsl_interp_accel_free(accimag);
87 void MtuFilter::WriteData(
const std::string filename)
90 rawout.open((filename +
".raw").c_str());
91 for (
unsigned int i = 0; i < FilterCoeff.size(); ++i)
93 rawout << i * freqstep <<
" " << abs(FilterCoeff.at(i)) <<
" "
94 << arg(FilterCoeff.at(i)) << endl;
The basic exception class for all errors that arise in gplib.