@@ -1314,6 +1314,97 @@ int main(int argc, char *argv[])
1314
1314
TRY_YIELD ;
1315
1315
}
1316
1316
}
1317
+
1318
+ if (!strcmp (argv [1 ],"fft_fc" ))
1319
+ {
1320
+ /* For real FFT, the parameter is the number of output complex bins
1321
+ instead of the actual FFT size.
1322
+ Thus, the number of input samples used for each FFT is twice the given parameter
1323
+ and for this reason, out_of_every_n_samples is also doubled
1324
+ to get correct amount of overlap.
1325
+ This is not very neat but makes it easier to replace fft_cc by fft_fc
1326
+ in some applications. */
1327
+ if (argc <=3 ) return badsyntax ("need required parameters (fft_out_size, out_of_every_n_samples)" );
1328
+ int fft_in_size = 0 , fft_out_size = 0 ;
1329
+ sscanf (argv [2 ],"%d" ,& fft_out_size );
1330
+ if (log2n (fft_out_size )== -1 ) return badsyntax ("fft_out_size should be power of 2" );
1331
+ fft_in_size = 2 * fft_out_size ;
1332
+ int every_n_samples ;
1333
+ sscanf (argv [3 ],"%d" ,& every_n_samples );
1334
+ every_n_samples *= 2 ;
1335
+ int benchmark = 0 ;
1336
+ int octave = 0 ;
1337
+ window_t window = WINDOW_DEFAULT ;
1338
+ if (argc >=5 )
1339
+ {
1340
+ window = firdes_get_window_from_string (argv [4 ]);
1341
+ }
1342
+ if (argc >=6 )
1343
+ {
1344
+ benchmark |=!strcmp ("--benchmark" ,argv [5 ]);
1345
+ octave |=!strcmp ("--octave" ,argv [5 ]);
1346
+ }
1347
+ if (argc >=7 )
1348
+ {
1349
+ benchmark |=!strcmp ("--benchmark" ,argv [6 ]);
1350
+ octave |=!strcmp ("--octave" ,argv [6 ]);
1351
+ }
1352
+
1353
+ if (!initialize_buffers ()) return -2 ;
1354
+ sendbufsize (fft_out_size );
1355
+
1356
+ //make FFT plan
1357
+ float * input = (float * )fft_malloc (sizeof (float )* fft_in_size );
1358
+ float * windowed = (float * )fft_malloc (sizeof (float )* fft_in_size );
1359
+ complexf * output = (complexf * )fft_malloc (sizeof (complexf )* fft_out_size );
1360
+ if (benchmark ) fprintf (stderr ,"fft_cc: benchmarking..." );
1361
+ FFT_PLAN_T * plan = make_fft_r2c (fft_in_size , windowed , output , benchmark );
1362
+ if (benchmark ) fprintf (stderr ," done\n" );
1363
+ //if(octave) printf("setenv(\"GNUTERM\",\"X11 noraise\");y=zeros(1,%d);semilogy(y,\"ydatasource\",\"y\");\n",fft_size); // TODO
1364
+ float * windowt ;
1365
+ windowt = precalculate_window (fft_in_size , window );
1366
+ for (;;)
1367
+ {
1368
+ FEOF_CHECK ;
1369
+ if (every_n_samples > fft_in_size )
1370
+ {
1371
+ fread (input , sizeof (float ), fft_in_size , stdin );
1372
+ //skipping samples before next FFT (but fseek doesn't work for pipes)
1373
+ for (int seek_remain = every_n_samples - fft_in_size ;seek_remain > 0 ;seek_remain -= the_bufsize )
1374
+ {
1375
+ fread (temp_f , sizeof (complexf ), MIN_M (the_bufsize ,seek_remain ), stdin );
1376
+ }
1377
+ }
1378
+ else
1379
+ {
1380
+ //overlapped FFT
1381
+ for (int i = 0 ;i < fft_in_size - every_n_samples ;i ++ ) input [i ]= input [i + every_n_samples ];
1382
+ fread (input + fft_in_size - every_n_samples , sizeof (float ), every_n_samples , stdin );
1383
+ }
1384
+ //apply_window_c(input,windowed,fft_size,window);
1385
+ apply_precalculated_window_f (input ,windowed ,fft_in_size ,windowt );
1386
+ fft_execute (plan );
1387
+ if (octave )
1388
+ {
1389
+ #if 0
1390
+ // TODO
1391
+ printf ("fftdata=[" );
1392
+ //we have to swap the two parts of the array to get a valid spectrum
1393
+ for (int i = fft_size /2 ;i < fft_size ;i ++ ) printf ("(%g)+(%g)*i " ,iof (output ,i ),qof (output ,i ));
1394
+ for (int i = 0 ;i < fft_size /2 ;i ++ ) printf ("(%g)+(%g)*i " ,iof (output ,i ),qof (output ,i ));
1395
+ printf (
1396
+ "];\n"
1397
+ "y=abs(fftdata);\n"
1398
+ "refreshdata;\n"
1399
+ );
1400
+ #endif
1401
+ }
1402
+ else fwrite (output , sizeof (complexf ), fft_out_size , stdout );
1403
+ TRY_YIELD ;
1404
+ }
1405
+ }
1406
+
1407
+
1317
1408
#define LOGPOWERCF_BUFSIZE 64
1318
1409
if (!strcmp (argv [1 ],"logpower_cf" ))
1319
1410
{
0 commit comments