test_cfft.c

来自「Blackfin C FFT code example」· C语言 代码 · 共 69 行

C
69
字号
/*	test_cfft.c
 *
 *	Example of the FFT routine from the Blackfin DSP library
 *
 *	Results in the output buffer "out"
 *
 *	See the documentation for more info on the DSP routines
 *
 */

#include <fract.h>
#include <complex.h>
#include <filter.h>
#include <flt2fr.h>
#include <stdio.h>

#define VEC_SIZE 64	// length of the input vector

// input

float infile[VEC_SIZE] = 
{
	#include "in.dat"
};

#pragma align 256 
complex_fract16 in[VEC_SIZE];

//output
#pragma align 4 
complex_fract16 out[VEC_SIZE]; 

//twiddle factors
#pragma align 4 
complex_fract16 twid[(3*VEC_SIZE)/4]; 

void main(void) {

	int i;
	FILE *fp;
	
	if((fp = fopen("out.dat", "w")) == NULL)
	{
		printf("Cannot open output file.\n");
		exit(1);
	}
	
	for(i=0;i<VEC_SIZE;i++)
	{
		in[i].re = float_to_fract16(infile[i]);
		in[i].im = 0;
	}

	// calculate twiddle factors
	twidfftf_fr16(twid,VEC_SIZE);
	
	// call to the DSP library
	cfftf_fr16(in, out, twid, 1, VEC_SIZE); 

	for(i=0;i<VEC_SIZE;i++)
		fprintf(fp, "%f\t+\t%f i\n", fract16_to_float(out[i].re), fract16_to_float(out[i].im));
	
	fclose(fp);
	
	printf("FFT completed successfully.");
}


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?