scrape -> scrap, fixed shift_math_cc, found a bug at fastddc.c line 68 which still waits to be fixed

This commit is contained in:
ha7ilm 2015-11-21 19:52:35 +01:00
parent 895bc20409
commit 646de8b258
4 changed files with 88 additions and 24 deletions

11
csdr.c
View file

@ -452,6 +452,7 @@ int main(int argc, char *argv[])
{
FEOF_CHECK;
if(!FREAD_C) break;
starting_phase=shift_math_cc((complexf*)input_buffer, (complexf*)output_buffer, the_bufsize, rate, starting_phase);
FWRITE_C;
TRY_YIELD;
}
@ -1295,7 +1296,7 @@ int main(int argc, char *argv[])
if (fft_size-taps_length<200) fft_size<<=1;
int input_size = fft_size - taps_length + 1;
int overlap_length = taps_length - 1;
fprintf(stderr,"bandpass_fir_fft_cc: (fft_size = %d) = (taps_length = %d) + (input_size = %d) - 1\n(overlap_length = %d) = taps_length - 1\n", fft_size, taps_length, input_size, overlap_length);
fprintf(stderr,"bandpass_fir_fft_cc: (fft_size = %d) = (taps_length = %d) + (input_size = %d) - 1\n(overlap_length = %d) = taps_length - 1\n", fft_size, taps_length, input_size, overlap_length );
if (fft_size<=2) return badsyntax("FFT size error.");
if(!sendbufsize(getbufsize())) return -2;
@ -1663,7 +1664,7 @@ int main(int argc, char *argv[])
fastddc_t ddc;
if(fastddc_init(&ddc, transition_bw, decimation, 0)) { badsyntax("error in fastddc_init()"); return 1; }
fastddc_print(&ddc);
fastddc_print(&ddc,"fastddc_fwd_cc");
if(!initialize_buffers()) return -2;
sendbufsize(ddc.fft_size);
@ -1686,8 +1687,8 @@ int main(int argc, char *argv[])
//overlapped FFT
for(int i=0;i<ddc.overlap_length;i++) input[i]=input[i+ddc.input_size];
fread(input+ddc.overlap_length, sizeof(complexf), ddc.input_size, stdin);
apply_window_c(input,windowed,ddc.fft_size,window);
//memcpy(windowed, input, ddc.fft_size*sizeof(complexf)); //we can switch off windows
//apply_window_c(input,windowed,ddc.fft_size,window);
memcpy(windowed, input, ddc.fft_size*sizeof(complexf)); //we can switch off windows; TODO: it is likely that we shouldn't apply a window to both the FFT and the filter.
fft_execute(plan);
fwrite(output, sizeof(complexf), ddc.fft_size, stdout);
TRY_YIELD;
@ -1712,7 +1713,7 @@ int main(int argc, char *argv[])
fastddc_t ddc;
if(fastddc_init(&ddc, transition_bw, decimation, shift_rate)) { badsyntax("error in fastddc_init()"); return 1; }
fastddc_print(&ddc);
fastddc_print(&ddc,"fastddc_inv_cc");
if(!initialize_buffers()) return -2;
sendbufsize(ddc.post_input_size/ddc.post_decimation); //TODO not exactly correct

View file

@ -56,33 +56,36 @@ int fastddc_init(fastddc_t* ddc, float transition_bw, int decimation, float shif
ddc->v = ddc->fft_size/ddc->overlap_length; //+-1 ? (or maybe ceil() this?) //TODO: why?
int middlebin=ddc->fft_size / 2;
ddc->startbin = middlebin + middlebin * shift_rate * 2;
//fprintf(stderr, "ddc->startbin=%g\n",(float)ddc->startbin);
ddc->startbin = ddc->v * round( ddc->startbin / (float)ddc->v );
//fprintf(stderr, "ddc->startbin=%g\n",(float)ddc->startbin);
ddc->offsetbin = ddc->startbin - middlebin;
ddc->post_shift = shift_rate-((float)ddc->offsetbin/ddc->fft_size);
ddc->pre_shift = ddc->offsetbin/(float)ddc->fft_size;
ddc->dsadata = decimating_shift_addition_init(ddc->post_shift, ddc->post_decimation);
//Overlap is scraped, not added
ddc->scrape=ddc->overlap_length/ddc->pre_decimation;
ddc->post_input_size=ddc->fft_inv_size-ddc->scrape;
//Overlap is scrapd, not added
ddc->scrap=ddc->overlap_length/ddc->pre_decimation; //TODO this is problematic sometimes! overlap_length = 401 :: scrap = 200
ddc->post_input_size=ddc->fft_inv_size-ddc->scrap;
return ddc->fft_size<=2; //returns true on error
}
void fastddc_print(fastddc_t* ddc)
void fastddc_print(fastddc_t* ddc, char* source)
{
fprintf(stderr,
"fastddc_print_sizes(): (fft_size = %d) = (taps_length = %d) + (input_size = %d) - 1\n"
"%s: fastddc_print_sizes(): (fft_size = %d) = (taps_length = %d) + (input_size = %d) - 1\n"
" overlap :: (overlap_length = %d) = taps_length - 1, taps_real_length = %d\n"
" decimation :: decimation = (pre_decimation = %d) * (post_decimation = %d), fft_inv_size = %d\n"
" shift :: startbin = %d, offsetbin = %d, v = %d, pre_shift = %g, post_shift = %g\n"
" o&s :: post_input_size = %d, scrape = %d\n"
" o&s :: post_input_size = %d, scrap = %d\n"
,
ddc->fft_size, ddc->taps_length, ddc->input_size,
source, ddc->fft_size, ddc->taps_length, ddc->input_size,
ddc->overlap_length, ddc->taps_real_length,
ddc->pre_decimation, ddc->post_decimation, ddc->fft_inv_size,
ddc->startbin, ddc->offsetbin, ddc->v, ddc->pre_shift, ddc->post_shift,
ddc->post_input_size, ddc->scrape );
ddc->post_input_size, ddc->scrap );
}
void fft_swap_sides(complexf* io, int fft_size)
@ -102,7 +105,7 @@ void fft_swap_sides(complexf* io, int fft_size)
decimating_shift_addition_status_t fastddc_inv_cc(complexf* input, complexf* output, fastddc_t* ddc, FFT_PLAN_T* plan_inverse, complexf* taps_fft, decimating_shift_addition_status_t shift_stat)
{
//implements DDC by using the overlap & scrape method
//implements DDC by using the overlap & scrap method
//TODO: +/-1s on overlap_size et al
//input shoud have ddc->fft_size number of elements
@ -135,11 +138,9 @@ decimating_shift_addition_status_t fastddc_inv_cc(complexf* input, complexf* out
qof(inv_output,i)/=plan_inverse->size;
}
//Overlap is scraped, not added
//Overlap is scrapped, not added
//Shift correction
shift_addition_data_t dsadata=decimating_shift_addition_init(ddc->post_shift, ddc->post_decimation); //this could be optimized (passed as parameter), but we would not win too much at all
shift_stat=decimating_shift_addition_cc(inv_output+ddc->scrape, output, ddc->post_input_size, dsadata, ddc->post_decimation, shift_stat);
//memcpy(inv_output+ddc->scrape,
shift_stat=decimating_shift_addition_cc(inv_output+ddc->scrap, output, ddc->post_input_size, ddc->dsadata, ddc->post_decimation, shift_stat);
//memcpy(inv_output+ddc->scrap, output
return shift_stat;
}

View file

@ -19,9 +19,10 @@ typedef struct fastddc_s
int offsetbin;
float post_shift;
int output_scrape;
int scrape;
int scrap;
shift_addition_data_t dsadata;
} fastddc_t;
int fastddc_init(fastddc_t* ddc, float transition_bw, int decimation, float shift_rate);
decimating_shift_addition_status_t fastddc_inv_cc(complexf* input, complexf* output, fastddc_t* ddc, FFT_PLAN_T* plan_inverse, complexf* taps_fft, decimating_shift_addition_status_t shift_stat);
void fastddc_print(fastddc_t* ddc);
void fastddc_print(fastddc_t* ddc, char* source);

View file

@ -155,6 +155,61 @@
<value>24e3</value>
</param>
</block>
<block>
<key>analog_noise_source_x</key>
<param>
<key>amp</key>
<value>1</value>
</param>
<param>
<key>alias</key>
<value></value>
</param>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>affinity</key>
<value></value>
</param>
<param>
<key>_enabled</key>
<value>0</value>
</param>
<param>
<key>_coordinate</key>
<value>(112, 219)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
<key>id</key>
<value>analog_noise_source_x_0</value>
</param>
<param>
<key>maxoutbuf</key>
<value>0</value>
</param>
<param>
<key>minoutbuf</key>
<value>0</value>
</param>
<param>
<key>noise_type</key>
<value>analog.GR_GAUSSIAN</value>
</param>
<param>
<key>type</key>
<value>complex</value>
</param>
<param>
<key>seed</key>
<value>0</value>
</param>
</block>
<block>
<key>analog_sig_source_x</key>
<param>
@ -175,7 +230,7 @@
</param>
<param>
<key>_enabled</key>
<value>True</value>
<value>1</value>
</param>
<param>
<key>freq</key>
@ -281,7 +336,7 @@
</param>
<param>
<key>commandline</key>
<value>csdr bandpass_fir_fft_cc 0.1 0.5 0.05 HAMMING</value>
<value>csdr bandpass_fir_fft_cc 0.1 0.3 0.05 HAMMING</value>
</param>
<param>
<key>comment</key>
@ -786,6 +841,12 @@
<value>Counts</value>
</param>
</block>
<connection>
<source_block_id>analog_noise_source_x_0</source_block_id>
<sink_block_id>blocks_throttle_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
<connection>
<source_block_id>analog_sig_source_x_0</source_block_id>
<sink_block_id>blocks_throttle_0</sink_block_id>