小编dig*_*phd的帖子

用C中的fftw.h计算fft和ifft

大家好我正在使用fftw C库来计算嵌入式系统上某些信号处理应用的频谱.但是,在我的项目中,我遇到了轻微的阻碍.

下面是我编写的一个简单程序,以确保我正确实现fftw函数.基本上我想计算12个数字序列的fft,然后做ifft并再次获得相同的数字序列.如果你安装了fftw3和gcc,那么如果用以下代码编译,这个程序应该可行:

gcc -g -lfftw3 -lm fftw_test.c -o fftw_test
Run Code Online (Sandbox Code Playgroud)

目前我的fft长度与输入数组的大小相同.

#include <stdio.h>
#include <stdlib.h>
#include <sndfile.h>
#include <stdint.h>
#include <math.h>
#include <fftw3.h>

int main(void)
{
double array[] = {0.1, 0.6, 0.1, 0.4, 0.5, 0, 0.8, 0.7, 0.8, 0.6, 0.1,0};
//double array2[] = {1, 6, 1, 4, 5, 0, 8, 7, 8, 6, 1,0};
double *out;
double *err;
int i,size = 12;

fftw_complex *out_cpx;

fftw_plan fft;
fftw_plan ifft;
out_cpx = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*size);
out = (double *) malloc(size*sizeof(double));
err = (double …
Run Code Online (Sandbox Code Playgroud)

c signal-processing fft fftw

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

c ×1

fft ×1

fftw ×1

signal-processing ×1