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:
parent
895bc20409
commit
646de8b258
4 changed files with 88 additions and 24 deletions
11
csdr.c
11
csdr.c
|
@ -452,6 +452,7 @@ int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
FEOF_CHECK;
|
FEOF_CHECK;
|
||||||
if(!FREAD_C) break;
|
if(!FREAD_C) break;
|
||||||
|
starting_phase=shift_math_cc((complexf*)input_buffer, (complexf*)output_buffer, the_bufsize, rate, starting_phase);
|
||||||
FWRITE_C;
|
FWRITE_C;
|
||||||
TRY_YIELD;
|
TRY_YIELD;
|
||||||
}
|
}
|
||||||
|
@ -1295,7 +1296,7 @@ int main(int argc, char *argv[])
|
||||||
if (fft_size-taps_length<200) fft_size<<=1;
|
if (fft_size-taps_length<200) fft_size<<=1;
|
||||||
int input_size = fft_size - taps_length + 1;
|
int input_size = fft_size - taps_length + 1;
|
||||||
int overlap_length = 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 (fft_size<=2) return badsyntax("FFT size error.");
|
||||||
|
|
||||||
if(!sendbufsize(getbufsize())) return -2;
|
if(!sendbufsize(getbufsize())) return -2;
|
||||||
|
@ -1663,7 +1664,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
fastddc_t ddc;
|
fastddc_t ddc;
|
||||||
if(fastddc_init(&ddc, transition_bw, decimation, 0)) { badsyntax("error in fastddc_init()"); return 1; }
|
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;
|
if(!initialize_buffers()) return -2;
|
||||||
sendbufsize(ddc.fft_size);
|
sendbufsize(ddc.fft_size);
|
||||||
|
@ -1686,8 +1687,8 @@ int main(int argc, char *argv[])
|
||||||
//overlapped FFT
|
//overlapped FFT
|
||||||
for(int i=0;i<ddc.overlap_length;i++) input[i]=input[i+ddc.input_size];
|
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);
|
fread(input+ddc.overlap_length, sizeof(complexf), ddc.input_size, stdin);
|
||||||
apply_window_c(input,windowed,ddc.fft_size,window);
|
//apply_window_c(input,windowed,ddc.fft_size,window);
|
||||||
//memcpy(windowed, input, ddc.fft_size*sizeof(complexf)); //we can switch off windows
|
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);
|
fft_execute(plan);
|
||||||
fwrite(output, sizeof(complexf), ddc.fft_size, stdout);
|
fwrite(output, sizeof(complexf), ddc.fft_size, stdout);
|
||||||
TRY_YIELD;
|
TRY_YIELD;
|
||||||
|
@ -1712,7 +1713,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
fastddc_t ddc;
|
fastddc_t ddc;
|
||||||
if(fastddc_init(&ddc, transition_bw, decimation, shift_rate)) { badsyntax("error in fastddc_init()"); return 1; }
|
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;
|
if(!initialize_buffers()) return -2;
|
||||||
sendbufsize(ddc.post_input_size/ddc.post_decimation); //TODO not exactly correct
|
sendbufsize(ddc.post_input_size/ddc.post_decimation); //TODO not exactly correct
|
||||||
|
|
31
fastddc.c
31
fastddc.c
|
@ -55,34 +55,37 @@ int fastddc_init(fastddc_t* ddc, float transition_bw, int decimation, float shif
|
||||||
//Shift operation in the frequency domain: we can shift by a multiple of v.
|
//Shift operation in the frequency domain: we can shift by a multiple of v.
|
||||||
ddc->v = ddc->fft_size/ddc->overlap_length; //+-1 ? (or maybe ceil() this?) //TODO: why?
|
ddc->v = ddc->fft_size/ddc->overlap_length; //+-1 ? (or maybe ceil() this?) //TODO: why?
|
||||||
int middlebin=ddc->fft_size / 2;
|
int middlebin=ddc->fft_size / 2;
|
||||||
ddc->startbin = middlebin + middlebin * shift_rate * 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 );
|
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->offsetbin = ddc->startbin - middlebin;
|
||||||
ddc->post_shift = shift_rate-((float)ddc->offsetbin/ddc->fft_size);
|
ddc->post_shift = shift_rate-((float)ddc->offsetbin/ddc->fft_size);
|
||||||
ddc->pre_shift = ddc->offsetbin/(float)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
|
//Overlap is scrapd, not added
|
||||||
ddc->scrape=ddc->overlap_length/ddc->pre_decimation;
|
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->scrape;
|
ddc->post_input_size=ddc->fft_inv_size-ddc->scrap;
|
||||||
|
|
||||||
return ddc->fft_size<=2; //returns true on error
|
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,
|
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"
|
" 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"
|
" 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"
|
" 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->overlap_length, ddc->taps_real_length,
|
||||||
ddc->pre_decimation, ddc->post_decimation, ddc->fft_inv_size,
|
ddc->pre_decimation, ddc->post_decimation, ddc->fft_inv_size,
|
||||||
ddc->startbin, ddc->offsetbin, ddc->v, ddc->pre_shift, ddc->post_shift,
|
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)
|
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)
|
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
|
//TODO: +/-1s on overlap_size et al
|
||||||
//input shoud have ddc->fft_size number of elements
|
//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;
|
qof(inv_output,i)/=plan_inverse->size;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Overlap is scraped, not added
|
//Overlap is scrapped, not added
|
||||||
//Shift correction
|
//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->scrap, output, ddc->post_input_size, ddc->dsadata, ddc->post_decimation, shift_stat);
|
||||||
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->scrap, output
|
||||||
|
|
||||||
//memcpy(inv_output+ddc->scrape,
|
|
||||||
return shift_stat;
|
return shift_stat;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,9 +19,10 @@ typedef struct fastddc_s
|
||||||
int offsetbin;
|
int offsetbin;
|
||||||
float post_shift;
|
float post_shift;
|
||||||
int output_scrape;
|
int output_scrape;
|
||||||
int scrape;
|
int scrap;
|
||||||
|
shift_addition_data_t dsadata;
|
||||||
} fastddc_t;
|
} fastddc_t;
|
||||||
|
|
||||||
int fastddc_init(fastddc_t* ddc, float transition_bw, int decimation, float shift_rate);
|
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);
|
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);
|
||||||
|
|
|
@ -155,6 +155,61 @@
|
||||||
<value>24e3</value>
|
<value>24e3</value>
|
||||||
</param>
|
</param>
|
||||||
</block>
|
</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>
|
<block>
|
||||||
<key>analog_sig_source_x</key>
|
<key>analog_sig_source_x</key>
|
||||||
<param>
|
<param>
|
||||||
|
@ -175,7 +230,7 @@
|
||||||
</param>
|
</param>
|
||||||
<param>
|
<param>
|
||||||
<key>_enabled</key>
|
<key>_enabled</key>
|
||||||
<value>True</value>
|
<value>1</value>
|
||||||
</param>
|
</param>
|
||||||
<param>
|
<param>
|
||||||
<key>freq</key>
|
<key>freq</key>
|
||||||
|
@ -281,7 +336,7 @@
|
||||||
</param>
|
</param>
|
||||||
<param>
|
<param>
|
||||||
<key>commandline</key>
|
<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>
|
||||||
<param>
|
<param>
|
||||||
<key>comment</key>
|
<key>comment</key>
|
||||||
|
@ -786,6 +841,12 @@
|
||||||
<value>Counts</value>
|
<value>Counts</value>
|
||||||
</param>
|
</param>
|
||||||
</block>
|
</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>
|
<connection>
|
||||||
<source_block_id>analog_sig_source_x_0</source_block_id>
|
<source_block_id>analog_sig_source_x_0</source_block_id>
|
||||||
<sink_block_id>blocks_throttle_0</sink_block_id>
|
<sink_block_id>blocks_throttle_0</sink_block_id>
|
||||||
|
|
Loading…
Reference in a new issue