Example #1
0
int main(int argc,char* argv[]){
	// Read the parameters in from the command line
	cmdLineString In;
	char* paramNames[]={"in"};
	cmdLineReadable* params[]={&In};
	cmdLineParse(argc-1,&argv[1],paramNames,sizeof(paramNames)/sizeof(char*),params);
	if(!In.set){
		fprintf(stderr,"You must specify an input file\n");
		return EXIT_FAILURE;
	}

	int res;
	float l2;
	CircularArray<> cIn,cOut;
	Complex<>* coeffs;

	// Read in the array
	cIn.read(In.value);
	res=cIn.resolution();

	// Allocate space for the Fourier coefficients
	coeffs=new Complex<>[res];

	// Run the forward and inverse Fourier transforms
	cOut.resize(res);
	ForwardFFT(cIn,coeffs);
	InverseFFT(coeffs,cOut);
	// Correct for the scaling term

	for(int i=0;i<res;i++){cOut(i)/=res;}

	// Test that the Fourier coefficients satisfy the conjugacy relations (difference should be zero)
	l2=0;
	for(int i=0;i<res;i++){l2+=(coeffs[i]-coeffs[(res-i)%res].conjugate()).squareNorm();}
	printf("Conjugate Test: %f\n",l2);



	// Compare the input and output (the difference should be zero)
	printf("Forward-Inverse Test: %f\n",CircularArray<>::SquareDifference(cIn,cOut));

	// Now compare the values of the Fourier coefficients (difference should be zero)
	FourierKey1D<> key;
	FourierTransform<> xForm;

	xForm.ForwardFourier(cIn,key);

	l2=0;
	float n=float(1.0/(2.0*PI))*key.resolution();

	// for(int i=0;i<32;i++){
	// for(int i=0;i<key.size();i++){
		// printf("%d kr: %-15f ki: %-15f cr: %-15f ci: %-15f diff: %f\n", i, key(i).r*n, key(i).i*n, coeffs[i].r, coeffs[i].i, key(i)*n - coeffs[i]);
	// } 

	for(int i=0;i<key.size();i++){l2+=(key(i)*n-coeffs[i]).squareNorm();}
	printf("Coefficient test: %f\n",l2);

	return EXIT_SUCCESS;
}
Example #2
0
float RunOneForwardTest(int fft_log_size, int signal_type, float signal_value,
                        struct SnrResult* snr) {
    OMX_FC32* x;
    OMX_FC32* y;
    struct AlignedPtr* x_aligned;
    struct AlignedPtr* y_aligned;

    OMX_FC32* y_true;

    OMX_INT n, fft_spec_buffer_size;
    OMXResult status;
    OMXFFTSpec_C_FC32 * fft_fwd_spec = NULL;
    int fft_size;

    fft_size = 1 << fft_log_size;

    status = omxSP_FFTGetBufSize_C_FC32(fft_log_size, &fft_spec_buffer_size);
    if (verbose > 63) {
        printf("fft_spec_buffer_size = %d\n", fft_spec_buffer_size);
    }

    fft_fwd_spec = (OMXFFTSpec_C_FC32*) malloc(fft_spec_buffer_size);
    status = omxSP_FFTInit_C_FC32(fft_fwd_spec, fft_log_size);
    if (status) {
        fprintf(stderr,
                "Failed to init forward FFT:  status = %d, order %d \n",
                status, fft_log_size);
        exit(1);
    }

    x_aligned = AllocAlignedPointer(32, sizeof(*x) * fft_size);
    y_aligned = AllocAlignedPointer(32, sizeof(*y) * (fft_size + 2));
    y_true = (OMX_FC32*) malloc(sizeof(*y_true) * fft_size);

    x = x_aligned->aligned_pointer_;
    y = y_aligned->aligned_pointer_;

    GenerateSignal(x, y_true, fft_size, signal_type, signal_value);

    if (verbose > 255) {
        printf("&x      = %p\n", (void*) x);
        printf("&y      = %p\n", (void*) y);
        printf("&buffer = %p\n", (void*) ((ARMsFFTSpec_R_FC32*)fft_fwd_spec)->pBuf);
    }

    if (verbose > 63) {
        printf("Signal\n");
        DumpArrayComplexFloat("x", fft_size, x);

        printf("Expected FFT output\n");
        DumpArrayComplexFloat("y", fft_size, y_true);
    }

    status = ForwardFFT(x, y, fft_fwd_spec);

    if (status) {
        fprintf(stderr, "Forward FFT failed: status = %d\n", status);
        exit(1);
    }

    if (verbose > 63) {
        printf("FFT Output\n");
        DumpArrayComplexFloat("y", fft_size, y);
    }

    CompareComplexFloat(snr, y, y_true, fft_size);

    FreeAlignedPointer(x_aligned);
    FreeAlignedPointer(y_aligned);
    free(fft_fwd_spec);

    return snr->complex_snr_;
}