T process(gsl::span<T const, N_in> input) noexcept { input_buffer.append(input); compute_fft(); compute_magnitudes(); return estimate_power_rise(); }
void build_image_fft () { int i, x, y; double length = cvts.xmax * cvts.ymax; double fft_scale = 1. / sqrt (length); fprintf (stderr, "Computing image FFT\n"); image_fft = (zomplex*) calloc (length, sizeof (zomplex)); for (y = 0; y < cvts.ymax; y++) for (x = 0; x < cvts.xmax; x++) image_fft[y*cvts.xmax + x].re = luminance[y][x]; compute_fft (image_fft, cvts.xmax, cvts.ymax); for (i = 0; i < length; i++) { image_fft[i].re *= fft_scale; image_fft[i].im *= fft_scale; } }
void build_gaussian_fft () { int i; double length = cvts.xmax * cvts.ymax; double fft_scale = 1. / sqrt (length); filter_fft = (zomplex**) calloc (range, sizeof (zomplex*)); for (scale = 0; scale < range; scale++) { fprintf (stderr, "Computing FFT of Gaussian at scale %i (size %i x %i)%c", scale, cvts.xmax, cvts.ymax, (char)13); filter_fft[scale] = (zomplex*) calloc (length, sizeof (zomplex)); gaussian_filter (filter_fft[scale], S_I(scale), k); compute_fft (filter_fft[scale], cvts.xmax, cvts.ymax); for (i = 0; i < length; i++) { filter_fft[scale][i].re *= fft_scale; filter_fft[scale][i].im *= fft_scale; } } fprintf (stderr, "\n"); }
void cfft(int trnsfrm_dir, int npnt, int window, SAMPLE *source_buf, int source_form, int source_scale, SAMPLE *result_buf, int result_form, int result_scale, int debug) /* modifies: result_buf effects: Computes npnt FFT specified by form, scale, and dir parameters. Source samples (single precision float) are taken from soure_buf and the transfrmd representation is stored in result_buf (single precision float). The parameters are defined as follows: trnsfrm_dir = FORWARD | INVERSE npnt = 2^k for some any positive integer k window = HANNING | RECTANGULAR (RECT = real and imag parts, POLAR = magnitude and phase) source_form = REAL | IMAG | RECT | POLAR result_form = REAL | IMAG | RECT | MAG | PHASE | POLAR xxxxxx_scale= LINEAR | DB ( 20log10 |mag| ) The input/output buffers are stored in a form appropriate to the type. For example: REAL => {real, real, real ...}, MAG => {mag, mag, mag, ... }, RECT => {real, imag, real, imag, ... }, POLAR => {mag, phase, mag, phase, ... }. To look at the magnitude (in db) of a 1024 point FFT of a real time signal we have: fft(FORWARD, 1024, RECTANGULAR, input, REAL, LINEAR, output, MAG, DB) All possible input and output combinations are possible given the choice of type and scale parameters. */ { FFT_NET *thisnet = (FFT_NET *)0; FFT_NET *lastnet = (FFT_NET *)0; /* A linked list of fft networks of different sizes is maintained to avoid building with every call. The network is built on the first call but reused for subsequent calls requesting the same size transformation. */ thisnet=firstnet; while (thisnet) { if (!(thisnet->n == npnt) || !(thisnet->window_type == window)) { /* current net doesn't match size or window type */ lastnet=thisnet; thisnet=thisnet->next; continue; /* keep looking */ } else { /* network matches desired size */ load_registers(thisnet, source_buf, source_form, source_scale, trnsfrm_dir); compute_fft(thisnet); /* do transformation */ store_registers(thisnet, result_buf, result_form, result_scale,debug); return; } } /* none of existing networks match required size*/ if (lastnet) { /* add new network to end of list */ thisnet = (FFT_NET *)malloc(sizeof(FFT_NET)); /* allocate */ thisnet->next = 0; lastnet->next = thisnet; /* add to end of list */ } else { /* first network to be created */ thisnet=firstnet=(FFT_NET *)malloc(sizeof(FFT_NET)); /* alloc. */ thisnet->next = 0; } /* build new network and compute transformation */ build_fft_network(thisnet, npnt, window); load_registers(thisnet, source_buf, source_form, source_scale, trnsfrm_dir); compute_fft(thisnet); store_registers(thisnet, result_buf, result_form, result_scale,debug); return; }