示例#1
0
int dspau_spectrum(double* in, double* out, int dims, int *sizes, int conversion)
{
	int i = 0, d;
	int len = sizes[0];
	int ret = 0;
	fftw_complex *fft_in, *fft_out;
	fftw_plan p;
	for(d = 1; d < dims; d++)
	{
		len *= sizes[d];
	}
	fft_in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * len);
	fft_out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * len);
	for(i = 0; i < len; i++) {
		fft_in[i][0] = in[i];
		fft_in[i][1] = in[i];
	}
	p = fftw_plan_dft(dims, sizes, fft_in, fft_out, FFTW_FORWARD, FFTW_ESTIMATE);
	fftw_execute(p);
	switch (conversion) {
	case magnitude:
		complex2mag(fft_out, out, len);
		break;
	case magnitude_dbv:
		complex2magdbv(fft_out, out, len);
		break;
	case magnitude_rooted:
		complex2magsqrt(fft_out, out, len);
		break;
	case magnitude_squared:
		complex2magpow(fft_out, out, len);
		break;
	case phase_degrees:
		complex2phideg(fft_out, out, len);
		break;
	case phase_radians:
		complex2phirad(fft_out, out, len);
		break;
	default:
		ret = -1;
		break;
	}
	fftw_destroy_plan(p);
	fftw_free(fft_in);
	fftw_free(fft_out);
	return ret;
}
示例#2
0
dspau_t* dspau_fft_dft(dspau_stream_p stream, int sign, int conversion)
{
    dspau_t* out = (dspau_t*)calloc(sizeof(dspau_t), stream->len);
    int* sizes = (int*)calloc(sizeof(int), stream->dims);
    memcpy(sizes, stream->sizes, stream->dims * sizeof(int));
    fftw_plan p;
    fftw_complex *fft_in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * stream->len);
    fftw_complex *fft_out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * stream->len);
    for(int i = 0; i < stream->len; i++) {
        fft_in[i][0] = stream->in[i];
        fft_in[i][1] = 0;
    }
    dspau_buffer_reverse(sizes, int, stream->dims);
    p = fftw_plan_dft(stream->dims, sizes, fft_in, fft_out, sign, FFTW_ESTIMATE);
    fftw_execute(p);
    switch (conversion) {
        case magnitude:
            complex2mag(fft_out, out, stream->len);
            break;
        case magnitude_dbv:
            complex2magdbv(fft_out, out, stream->len);
            break;
        case magnitude_root:
            complex2magsqrt(fft_out, out, stream->len);
            break;
        case magnitude_square:
            complex2magpow(fft_out, out, stream->len);
            break;
        case phase_degrees:
            complex2phideg(fft_out, out, stream->len);
            break;
        case phase_radians:
            complex2phirad(fft_out, out, stream->len);
            break;
        default:
            break;
    }
    fftw_destroy_plan(p);
    fftw_free(fft_in);
    fftw_free(fft_out);
    dspau_t *ret = dspau_fft_shift(out, stream->dims, stream->sizes);
    free(out);
    return ret;
}