Skip to content

Commit

Permalink
Updated main to be a VFO speed test
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreRouma committed Jun 16, 2022
1 parent c43d58c commit 4012e16
Showing 1 changed file with 36 additions and 43 deletions.
79 changes: 36 additions & 43 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
#include <stdio.h>
#include <dsp/bench/speed_tester.h>

#include <dsp/multirate/rational_resampler.h>
#include <dsp/taps/low_pass.h>
#include <dsp/taps/high_pass.h>
#include <dsp/taps/band_pass.h>

#include <dsp/channel/rx_vfo.h>

#define TEST_BUFFER_SIZE STREAM_BUFFER_SIZE
Expand All @@ -19,55 +13,54 @@ int main() {
// ============= DSP Under Test =============
input = new dsp::stream<dsp::complex_t>;

dsp::tap<dsp::complex_t> taps = dsp::taps::bandPass<dsp::complex_t>(0.0, 0.25, 0.1, 1.0);
dsp::filter::FIR<dsp::complex_t, dsp::complex_t> dut(input, taps);
dsp::channel::RxVFO dut(input, 20000000.0, 250000.0, 200000.0, 1000000.0);

output = &dut.out;
// ==========================================

// dut.setInSamplerate(2400000.0);
// dut.setOutSamplerate(24000.0);

// // Run benchmark
// dsp::bench::SpeedTester<dsp::complex_t, dsp::complex_t> st(input, output);
// dut.start();
// for (int i = 0; i < TEST_COUNT; i++) {
// dut.reset();
// printf("%lf MS/s\n", st.benchmark(TEST_DURATION, TEST_BUFFER_SIZE) / 1000000.0);
// }
// dut.stop();
// Run benchmark
dsp::bench::SpeedTester<dsp::complex_t, dsp::complex_t> st(input, output);
dut.start();
for (int i = 0; i < TEST_COUNT; i++) {
dut.reset();
printf("%lf MS/s\n", st.benchmark(TEST_DURATION, TEST_BUFFER_SIZE) / 1000000.0);
}
dut.stop();

for (double f = -0.5; f <= 0.5; f += 0.001) {
// Generate signal
double phase = 0;
for (int i = 0; i < TEST_BUFFER_SIZE; i++) {
dsp::complex_t cplx = { cosf(phase), sinf(phase) };
input->readBuf[i] = cplx * dsp::window::nuttall(i,TEST_BUFFER_SIZE);
phase += 2.0 * DB_M_PI * f;
// for (double f = -0.5; f <= 0.5; f += 0.001) {
// // Generate signal
// double phase = 0;
// for (int i = 0; i < TEST_BUFFER_SIZE; i++) {
// dsp::complex_t cplx = { cosf(phase), sinf(phase) };
// input->readBuf[i] = cplx * dsp::window::nuttall(i,TEST_BUFFER_SIZE);
// phase += 2.0 * DB_M_PI * f;

if (phase > 2.0 * DB_M_PI) {
phase -= 2.0 * DB_M_PI;
}
else if (phase < 2.0 * DB_M_PI) {
phase += 2.0 * DB_M_PI;
}
}
// if (phase > 2.0 * DB_M_PI) {
// phase -= 2.0 * DB_M_PI;
// }
// else if (phase < 2.0 * DB_M_PI) {
// phase += 2.0 * DB_M_PI;
// }
// }

// Process through resampler
dut.reset();
int outc = dut.process(TEST_BUFFER_SIZE, input->readBuf, dut.out.writeBuf);
// // Process through resampler
// dut.reset();
// int outc = dut.process(TEST_BUFFER_SIZE, input->readBuf, dut.out.writeBuf);

// Measure amplitude
double maxAmp = 0.0;
for (int i = 0; i < outc; i++) {
double amp = dut.out.writeBuf[i].amplitude();
if (amp > maxAmp) {
maxAmp = amp;
}
}
// // Measure amplitude
// double maxAmp = 0.0;
// for (int i = 0; i < outc; i++) {
// double amp = dut.out.writeBuf[i].amplitude();
// if (amp > maxAmp) {
// maxAmp = amp;
// }
// }

printf("%lf %lf\n", f, 20.0 * log10(maxAmp));
}
// printf("%lf %lf\n", f, 20.0 * log10(maxAmp));
// }

return 0;
}

0 comments on commit 4012e16

Please sign in to comment.