#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "fft_soft.h"
#define PI 3.14159265358979323846
complex add(complex a, complex b)
{
complex ret = {a.real + b.real, a.imag + b.imag};
return ret;
}
complex sub(complex a, complex b)
{
complex ret = {a.real - b.real, a.imag - b.imag};
return ret;
}
complex mul(complex a, complex b)
{
complex ret = {a.real * b.real - a.imag * b.imag, a.real * b.imag + a.imag * b.real};
return ret;
}
void bitrev(complex *data, int n)
{
int j = 0;
int m = 0;
for (int i = 0; i < n; i++)
{
if (j > i)
SWAP(data[i], data[j]);
m = n / 2;
while (j >= m && m != 0)
{
j -= m;
m >>= 1;
}
j += m;
}
}
void fft_soft(complex *data, int n)
{
int M = 0;
for (int i = n; i > 1; i = i >> 1, M++);
bitrev(data, n);
for (int m = 0; m < M; m++)
{
int K = n >> (m + 1);
for (int k = 0; k < K; k++)
{
int J = 2 << m;
int base = k * J;
for (int j = 0; j < J / 2; j++)
{
int t = base + j;
complex w = {cos(-2 * PI * j * K / n), sin(-2 * PI * j * K / n)};
complex wn = mul(data[t + J / 2], w);
complex temp = data[t];
data[t] = add(data[t], wn);
data[t + J / 2] = sub(temp, wn);
}
}
}
}
void ifft_soft(complex *data, int n)
{
int M = 0;
for (int i = n; i > 1; i = i >> 1, M++);
bitrev(data, n);
for (int m = 0; m < M; m++)
{
int K = n >> (m + 1);
for (int k = 0; k < K; k++)
{
int J = 2 << m;
int base = k * J;
for (int j = 0; j < J / 2; j++)
{
int t = base + j;
complex w = {cos(2 * PI * j * K / n), sin(2 * PI * j * K / n)};
complex wn = mul(data[t + J / 2], w);
complex temp = data[t];
data[t] = add(data[t], wn);
data[t + J / 2] = sub(temp, wn);
}
}
}
for (int i = 0; i < n; i++)
{
data[i].real /= n;
data[i].imag /= n;
}
}
c语言的fft和ifft
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- Cooley-Tukey算法以发明者J. W. Cooley和John Tukey命名。Cooley-Tukey算...
- 记录问题: 如果不初始化arm_cfft_instance_f32FFT算出数据无效 小容量产品 用DSP官方库方...
- 如题: .h 文件 #include <vector>#include <complex>#include ".....
- C语言视频,C语言速成,C语言拼图游戏 完整源码: #include #include #include #def...
- C语言是面向过程的,而C++是面向对象的 一般来说,和其他编程语言相比,C/C++语言学起来会比较累,如果想达到项...