testing fm demodulation

This commit is contained in:
Charles J. Cliffe 2014-11-04 23:05:04 -05:00
parent f22a929828
commit 39afec2172
3 changed files with 67 additions and 33 deletions

View File

@ -18,6 +18,8 @@
static int *atan_lut = NULL;
static int atan_lut_size = 131072; /* 512 KB */
static int atan_lut_coef = 8;
static uint32_t MINIMUM_RATE = 1000000;
// rewrite as dynamic and thread-safe for multi demod/dongle
#define SHARED_SIZE 6
int16_t shared_samples[SHARED_SIZE][MAXIMUM_BUF_LENGTH];
@ -540,30 +542,51 @@ Demodulate::Demodulate() {
dc_avg = 0;
output_target = &output.results[0];
lowpassed = NULL;
/*
int capture_freq, capture_rate;
struct dongle_state *d = &dongle;
struct demod_state *dm = &demod;
struct controller_state *cs = &controller;
dm->downsample = (MINIMUM_RATE / dm->rate_in) + 1;
if (dm->downsample_passes) {
dm->downsample_passes = (int)log2(dm->downsample) + 1;
dm->downsample = 1 << dm->downsample_passes;
}
capture_freq = freq;
capture_rate = dm->downsample * dm->rate_in;
if (d->pre_rotate) {
capture_freq = freq + capture_rate/4;}
capture_freq += cs->edge * dm->rate_in / 2;
dm->output_scale = (1<<15) / (128 * dm->downsample);
if (dm->output_scale < 1) {
dm->output_scale = 1;}
if (dm->mode_demod == &fm_demod) {
dm->output_scale = 1;}
d->freq = (uint32_t)capture_freq;
d->rate = (uint32_t)capture_rate;
*/
mode_demod = &fm_demod;
rate_in = SRATE;
rate_out = 170000;
rate_out2 = 32000;
output.rate = 32000;
custom_atan = 1;
//demod.post_downsample = 4;
deemph = 1;
squelch_level = 0;
int capture_freq;
downsample = (MINIMUM_RATE / rate_in) + 1;
if (downsample_passes) {
downsample_passes = (int) log2(downsample) + 1;
downsample = 1 << downsample_passes;
}
if (deemph) {
deemph_a = (int)round(1.0/((1.0-exp(-1.0/(rate_out * 75e-6)))));
}
capture_freq=DEFAULT_FREQ;
//capture_freq = freq;
//capture_rate = downsample * rate_in;
int edge = 0;
// if (d->pre_rotate) {
// capture_freq = freq + capture_rate/4;}
capture_freq += edge * rate_in / 2;
output_scale = (1 << 15) / (128 * downsample);
if (output_scale < 1) {
output_scale = 1;
}
if (mode_demod == &fm_demod) {
output_scale = 1;
}
custom_atan = 1;
//demod.post_downsample = 4;
deemph = 1;
squelch_level = 0;
int r, opt;
int dev_given = 0;
@ -596,15 +619,7 @@ Demodulate::Demodulate() {
// }
// if (strcmp("wbfm", optarg) == 0) {
// controller.wb_mode = 1;
mode_demod = &fm_demod;
rate_in = SRATE; //170000
rate_out = SRATE; //170000
rate_out2 = 32000;
output.rate = 32000;
custom_atan = 1;
//demod.post_downsample = 4;
deemph = 1;
squelch_level = 0;
// }
// break;

View File

@ -157,6 +157,21 @@ void TestGLCanvas::setData(std::vector<signed char> *data) {
if (data && data->size()) {
std::vector<int16_t> tmp(data->begin(),data->end());
demod.demod(tmp);
std::cout << demod.lp_len << std::endl;
if (points.size() < demod.lp_len*2) {
points.resize(demod.lp_len*2);
}
for (int i = 0, iMax= demod.lp_len; i < iMax; i++) {
points[i * 2 + 1] = (float)demod.lowpassed[i]/32767.0+0.5;
points[i * 2] = ((double) i / (double) iMax);
}
/*
if (points.size() < FFT_SIZE * 2) {
points.resize(FFT_SIZE * 2);
}
@ -215,7 +230,7 @@ void TestGLCanvas::setData(std::vector<signed char> *data) {
for (int i = 0, iMax = FFT_SIZE; i < iMax; i++) {
points[i * 2 + 1] = fft_result_maa[i] / fft_ceil_maa;
points[i * 2] = ((double) i / (double) iMax);
}
}*/
}
}

View File

@ -7,6 +7,8 @@
#include "CubicSDRDefs.h"
#include "fftw3.h"
#include "Demodulate.h"
class PrimaryGLContext: public wxGLContext {
public:
PrimaryGLContext(wxGLCanvas *canvas);
@ -42,5 +44,7 @@ private:
std::vector<float> fft_result_ma;
std::vector<float> fft_result_maa;
Demodulate demod;
wxDECLARE_EVENT_TABLE();
};