28 #define SAMPLE_RATE 48000 39 #include <boost/format.hpp> 49 gettimeofday(&tp, NULL);
50 ret = ((double) tp.tv_sec) + 1e-6*((double)tp.tv_usec);
62 filter_map[0] =
new SoDa::OSFilter(300.0, 400.0, 500.0, 600.0, 512, 1.0, 48000.0, inbuflen);
64 filter_map[1] =
new SoDa::OSFilter(300.0, 400.0, 900.0, 1000.0, 512, 1.0, 48000.0, inbuflen);
65 filter_map[2] =
new SoDa::OSFilter(200.0, 300.0, 2300.0, 2400.0, 512, 1.0, 48000.0, inbuflen);
66 filter_map[3] =
new SoDa::OSFilter(100.0, 200.0, 6200.0, 6300.0, 512, 1.0, 48000.0, inbuflen);
67 filter_map[4] =
new SoDa::OSFilter(100.0, 200.0, 18000.0, 19000.0, 512, 1.0, 48000.0, inbuflen);
68 std::ofstream f100(
"filt100.dat");
69 std::ofstream f500(
"filt500.dat");
70 std::ofstream f2000(
"filt_fd2000.dat");
71 std::ofstream f6000(
"filt_fd6000.dat");
72 std::ofstream fspec(
"filt_pass.dat");
74 filter_map[0]->
dump(f100);
75 filter_map[1]->
dump(f500);
76 filter_map[2]->
dump(f2000);
77 filter_map[3]->
dump(f6000);
78 filter_map[4]->
dump(fspec);
89 void add_sig(complex<float> * in,
float freq,
int len,
float acc)
92 float phase_step = 2.0 * M_PI * freq / ((float)
SAMPLE_RATE);
94 for(i = 0; i < len; i++) {
95 in[i] = acc * in[i] + complex<float>(cos(ang),sin(ang));
97 if(ang > M_PI) ang = ang - (2.0 * M_PI);
104 int main(
int argc,
char * argv[])
106 (void) argc; (void) argv;
109 const int samp_len = 65536;
112 double sample_rate = 48000.0;
114 SoDa::OSFilter SSBFilter(200.0, 300.0, 2300.0, 2400.0, 512, 1.0, sample_rate, inbuflen);
116 SoDa::OSFilter CWFilter(300.0, 400.0, 900.0, 1000.0, 512, 1.0, 48000.0, inbuflen);
118 complex<float> in[samp_len];
119 complex<float> ssb_out[samp_len];
120 complex<float> cw_out[samp_len];
125 for(freq = -22e3; freq < 22e3; freq += 5.0) {
126 double phase_step = 2.0 * M_PI * freq / ((double) sample_rate);
128 for(i = 0; i < samp_len; i++) {
129 in[i] = complex<float>(cos(ang), sin(ang));
131 if(ang > M_PI) ang = ang - 2.0 * M_PI;
132 if(ang < -M_PI) ang = ang + 2.0 * M_PI;
134 for(i = 0; i < (samp_len - inbuflen); i += inbuflen) {
135 SSBFilter.
apply(&(in[i]), &(ssb_out[i]));
136 CWFilter.
apply(&(in[i]), &(cw_out[i]));
142 double ssb_gain, ssb_phase, cw_gain, cw_phase;
143 for(i = 4000, j = 0; j < 5; i += 1000, j++) {
144 ssb_gain = std::abs(ssb_out[i]) / std::abs(in[i]);
145 ssb_phase = std::arg(ssb_out[i]) - std::arg(in[i]);
146 cw_gain = std::abs(cw_out[i]) / std::abs(in[i]);
147 cw_phase = std::arg(cw_out[i]) - std::arg(in[i]);
148 if(ssb_phase > M_PI) ssb_phase -= 2.0*M_PI;
149 if(ssb_phase < -M_PI) ssb_phase += 2.0*M_PI;
150 if(cw_phase > M_PI) cw_phase -= 2.0*M_PI;
151 if(cw_phase < -M_PI) cw_phase += 2.0*M_PI;
152 std::cout << boost::format(
"%12.8f %6g %6g %6g %6g\n") % freq % ssb_gain % ssb_phase % cw_gain % cw_phase;
This is an overlap-and-save frequency domain implementation of a general FIR filter widget...
void add_sig(complex< float > *in, float freq, int len, float acc)
void dump(std::ostream &os)
dump the filter FFT to the output stream
int main(int argc, char *argv[])
Overlap-and-save filter class.
unsigned int apply(std::complex< float > *inbuf, std::complex< float > *outbuf, float outgain=1.0)
run the filter on a complex input stream
SoDa::OSFilter ** buildFilterMap(int inbuflen)