attempt to improve FFT zoom resolution

This commit is contained in:
Charles J. Cliffe 2015-01-30 19:31:32 -05:00
parent f87ee8dc6f
commit fb5a7e5b8f
2 changed files with 103 additions and 65 deletions

View File

@ -36,7 +36,7 @@ wxEND_EVENT_TABLE()
WaterfallCanvas::WaterfallCanvas(wxWindow *parent, int *attribList) : WaterfallCanvas::WaterfallCanvas(wxWindow *parent, int *attribList) :
InteractiveCanvas(parent, attribList), spectrumCanvas(NULL), dragState(WF_DRAG_NONE), nextDragState(WF_DRAG_NONE), fft_size(0), waterfall_lines( InteractiveCanvas(parent, attribList), spectrumCanvas(NULL), dragState(WF_DRAG_NONE), nextDragState(WF_DRAG_NONE), fft_size(0), waterfall_lines(
0), plan( 0), plan(
NULL), in(NULL), out(NULL), resampler(NULL), resamplerRatio(0), lastInputBandwidth(0), zoom(1), mouseZoom(1), otherWaterfallCanvas(NULL), polling(true) { NULL), in(NULL), out(NULL), resampler(NULL), resamplerRatio(0), lastInputBandwidth(0), zoom(1), mouseZoom(1), otherWaterfallCanvas(NULL), polling(true), last_data_size(0), fft_in_data(NULL), fft_last_data(NULL) {
glContext = new WaterfallContext(this, &wxGetApp().GetContext(this)); glContext = new WaterfallContext(this, &wxGetApp().GetContext(this));
@ -64,6 +64,14 @@ void WaterfallCanvas::setup(int fft_size_in, int waterfall_lines_in) {
free(in); free(in);
} }
in = (fftwf_complex*) fftwf_malloc(sizeof(fftwf_complex) * fft_size); in = (fftwf_complex*) fftwf_malloc(sizeof(fftwf_complex) * fft_size);
if (fft_in_data) {
free(fft_in_data);
}
fft_in_data = (fftwf_complex*) fftwf_malloc(sizeof(fftwf_complex) * fft_size);
if (fft_last_data) {
free(fft_last_data);
}
fft_last_data = (fftwf_complex*) fftwf_malloc(sizeof(fftwf_complex) * fft_size);
if (out) { if (out) {
free(out); free(out);
} }
@ -394,6 +402,8 @@ void WaterfallCanvas::setData(DemodulatorThreadIQData *input) {
spectrum_points.resize(fft_size * 2); spectrum_points.resize(fft_size * 2);
} }
unsigned int num_written;
if (isView) { if (isView) {
if (!input->frequency || !input->sampleRate) { if (!input->frequency || !input->sampleRate) {
return; return;
@ -447,45 +457,69 @@ void WaterfallCanvas::setData(DemodulatorThreadIQData *input) {
resampleBuffer.resize(out_size); resampleBuffer.resize(out_size);
} }
unsigned int num_written;
msresamp_crcf_execute(resampler, &shiftBuffer[0], input->data.size(), &resampleBuffer[0], &num_written); msresamp_crcf_execute(resampler, &shiftBuffer[0], input->data.size(), &resampleBuffer[0], &num_written);
resampleBuffer.resize(fft_size); resampleBuffer.resize(fft_size);
if (num_written < fft_size) { if (num_written < fft_size) {
for (int i = 0; i < num_written; i++) { for (int i = 0; i < num_written; i++) {
in[i][0] = resampleBuffer[i].real; fft_in_data[i][0] = resampleBuffer[i].real;
in[i][1] = resampleBuffer[i].imag; fft_in_data[i][1] = resampleBuffer[i].imag;
} }
for (int i = num_written; i < fft_size; i++) { for (int i = num_written; i < fft_size; i++) {
in[i][0] = 0; fft_in_data[i][0] = 0;
in[i][1] = 0; fft_in_data[i][1] = 0;
} }
} else { } else {
for (int i = 0; i < fft_size; i++) { for (int i = 0; i < fft_size; i++) {
in[i][0] = resampleBuffer[i].real; fft_in_data[i][0] = resampleBuffer[i].real;
in[i][1] = resampleBuffer[i].imag; fft_in_data[i][1] = resampleBuffer[i].imag;
} }
} }
} else { } else {
num_written = data->size();
if (data->size() < fft_size) { if (data->size() < fft_size) {
for (int i = 0, iMax = data->size(); i < iMax; i++) { for (int i = 0, iMax = data->size(); i < iMax; i++) {
in[i][0] = (*data)[i].real; fft_in_data[i][0] = (*data)[i].real;
in[i][1] = (*data)[i].imag; fft_in_data[i][1] = (*data)[i].imag;
} }
for (int i = data->size(); i < fft_size; i++) { for (int i = data->size(); i < fft_size; i++) {
in[i][0] = 0; fft_in_data[i][0] = 0;
in[i][1] = 0; fft_in_data[i][1] = 0;
} }
} else { } else {
for (int i = 0; i < fft_size; i++) { for (int i = 0; i < fft_size; i++) {
in[i][0] = (*data)[i].real; fft_in_data[i][0] = (*data)[i].real;
in[i][1] = (*data)[i].imag; fft_in_data[i][1] = (*data)[i].imag;
} }
} }
} }
bool execute = false;
if (num_written >= fft_size) {
execute = true;
memcpy(in, fft_in_data, sizeof(fftwf_complex) * fft_size * sizeof(fftwf_complex));
memcpy(fft_last_data, in, fft_size * sizeof(fftwf_complex));
} else {
if (last_data_size + num_written < fft_size) { // priming
unsigned int num_copy = fft_size;
num_copy = fft_size - last_data_size;
if (num_written > num_copy) {
num_copy = num_written;
}
memcpy(fft_last_data, fft_in_data, num_copy * sizeof(fftwf_complex));
last_data_size += num_copy;
} else {
unsigned int num_last = (fft_size - num_written);
memcpy(in, fft_last_data + (last_data_size - num_last), num_last * sizeof(fftwf_complex));
memcpy(in + num_last, fft_in_data, num_written * sizeof(fftwf_complex));
memcpy(fft_last_data, in, fft_size * sizeof(fftwf_complex));
}
}
if (execute) {
fftwf_execute(plan); fftwf_execute(plan);
float fft_ceil = 0, fft_floor = 1; float fft_ceil = 0, fft_floor = 1;
@ -548,6 +582,7 @@ void WaterfallCanvas::setData(DemodulatorThreadIQData *input) {
} }
} }
} }
}
void WaterfallCanvas::OnIdle(wxIdleEvent &event) { void WaterfallCanvas::OnIdle(wxIdleEvent &event) {
Refresh(false); Refresh(false);

View File

@ -56,7 +56,8 @@ private:
WaterfallCanvas *otherWaterfallCanvas; WaterfallCanvas *otherWaterfallCanvas;
bool polling; bool polling;
fftwf_complex *in, *out; fftwf_complex *in, *out, *fft_in_data, *fft_last_data;
unsigned int last_data_size;
fftwf_plan plan; fftwf_plan plan;
float fft_ceil_ma, fft_ceil_maa; float fft_ceil_ma, fft_ceil_maa;
@ -84,6 +85,8 @@ private:
std::vector<liquid_float_complex> shiftBuffer; std::vector<liquid_float_complex> shiftBuffer;
std::vector<liquid_float_complex> resampleBuffer; std::vector<liquid_float_complex> resampleBuffer;
// event table // event table
wxDECLARE_EVENT_TABLE(); wxDECLARE_EVENT_TABLE();
}; };