Verified that fastddc_fwd_cc works.

This commit is contained in:
ha7ilm 2015-11-17 21:54:06 +01:00
parent c7e363d5cf
commit 175c700cc9
3 changed files with 51 additions and 8 deletions

35
csdr.c
View file

@ -697,7 +697,7 @@ int main(int argc, char *argv[])
{
FEOF_CHECK;
FREAD_R;
for(int i=0; i<the_bufsize;i++) fprintf(stderr, "%g ",input_buffer[i]);
for(int i=0; i<the_bufsize;i++) printf("%g ",input_buffer[i]);
TRY_YIELD;
}
@ -1658,7 +1658,7 @@ int main(int argc, char *argv[])
if(argc>3) sscanf(argv[3],"%g",&transition_bw);
window_t window = WINDOW_DEFAULT;
if(argc>4) window=firdes_get_window_from_string(argv[5]);
if(argc>4) window=firdes_get_window_from_string(argv[4]);
else fprintf(stderr,"fastddc_fwd_cc: window = %s\n",firdes_get_string_from_window(window));
fastddc_t ddc;
@ -1693,7 +1693,7 @@ int main(int argc, char *argv[])
}
}
if( !strcmp(argv[1],"fastddc_apply_cc") ) //<decimation> <shift_rate> [transition_bw [window]]
if( !strcmp(argv[1],"fastddc_inv_cc") ) //<decimation> <shift_rate> [transition_bw [window]]
{
int decimation;
if(argc<=2) return badsyntax("need required parameter (decimation)");
@ -1743,12 +1743,39 @@ int main(int argc, char *argv[])
{
FEOF_CHECK;
fread(input, sizeof(complexf), ddc.fft_size, stdin);
shift_stat = fastddc_apply_cc(input, output, &ddc, plan_inverse, taps_fft, shift_stat);
shift_stat = fastddc_inv_cc(input, output, &ddc, plan_inverse, taps_fft, shift_stat);
fwrite(output, sizeof(complexf), ddc.output_size, stdout);
TRY_YIELD;
}
}
if( !strcmp(argv[1], "_fft2octave") )
{
int fft_size;
if(argc<=2) return badsyntax("need required parameter (fft_size)");
sscanf(argv[2],"%d",&fft_size);
complexf* fft_input=(complexf*)malloc(sizeof(complexf)*fft_size);
initialize_buffers();
if(!sendbufsize(fft_size)) return -2;
printf("setenv(\"GNUTERM\",\"X11 noraise\");y=zeros(1,%d);semilogy(y,\"ydatasource\",\"y\");\n",fft_size);
for(;;)
{
FEOF_CHECK;
fread(fft_input, sizeof(complexf), fft_size, stdin);
printf("fftdata=[");
//we have to swap the two parts of the array to get a valid spectrum
for(int i=fft_size/2;i<fft_size;i++) printf("(%g)+(%g)*i ",iof(fft_input,i),qof(fft_input,i));
for(int i=0;i<fft_size/2;i++) printf("(%g)+(%g)*i ",iof(fft_input,i),qof(fft_input,i));
printf(
"];\n"
"y=abs(fftdata);\n"
"refreshdata;\n"
);
}
}
if(!strcmp(argv[1],"none"))
{
return 0;

View file

@ -85,7 +85,22 @@ void fastddc_print(fastddc_t* ddc)
ddc->output_size, ddc->scrape );
}
decimating_shift_addition_status_t fastddc_apply_cc(complexf* input, complexf* output, fastddc_t* ddc, FFT_PLAN_T* plan_inverse, complexf* taps_fft, decimating_shift_addition_status_t shift_stat)
void fft_swap_sides(complexf* io, int fft_size)
{
int middle=fft_size/2;
complexf temp;
for(int i=0;i<middle;i++)
{
iof(&temp,0)=iof(io,i);
qof(&temp,0)=qof(io,i);
iof(io,i)=iof(io,i+middle);
qof(io,i)=qof(io,i+middle);
iof(io,i+middle)=iof(&temp,0);
qof(io,i+middle)=qof(&temp,0);
}
}
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
//TODO: +/-1s on overlap_size et al
@ -102,7 +117,7 @@ decimating_shift_addition_status_t fastddc_apply_cc(complexf* input, complexf* o
}
//Alias & shift & filter at once
// * no, we won't break this algorithm to parts that are easier to understand: now we go for speed
fft_swap_sides(input, ddc->fft_size); //this is not very optimal, but now we stick with this slow solution until we got the algorithm working
for(int i=0;i<ddc->fft_size;i++)
{
int output_index = (ddc->startbin+i)%plan_inverse->size;
@ -111,9 +126,10 @@ decimating_shift_addition_status_t fastddc_apply_cc(complexf* input, complexf* o
}
fft_execute(plan_inverse);
fft_swap_sides(inv_output,plan_inverse->size);
//Normalize data
for(int i=0;i<plan_inverse->size;i++) //@apply_ddc_fft_cc: normalize by size
for(int i=0;i<plan_inverse->size;i++) //@fastddc_inv_cc: normalize by size
{
iof(inv_output,i)/=plan_inverse->size;
qof(inv_output,i)/=plan_inverse->size;

View file

@ -23,5 +23,5 @@ typedef struct fastddc_s
} fastddc_t;
int fastddc_init(fastddc_t* ddc, float transition_bw, int decimation, float shift_rate);
decimating_shift_addition_status_t fastddc_apply_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);