#include "xcorr.h"
void mul(CPLX a[], CPLX b[], CPLX c[], int N)
{
//复数乘法函数
//输入:两个复数数组a[]和b[]和它们的长度N
//输出:得到一个复数数组c[]
int n = 0;
for (n = 0; n < N; n++)
{
c[n].real = a[n].real * b[n].real - a[n].image * b[n].image;
c[n].image = a[n].real * b[n].image + a[n].image * b[n].real;
}
}
void conjugate_complex(int n, CPLX in[], CPLX out[])
{
//求复数数组in[n]的共轭out[n]
int i = 0;
for (i = 0; i < n; i++)
{
out[i].image = -in[i].image;
out[i].real = in[i].real;
}
}
void _fft1(CPLX A[], CPLX out[], int n, int step)
{
// fft的迭代子函数
int i;
CPLX t;
double a, b, c, d, theta;
if (step < n)
{
_fft1(out, A, n, step * 2);
_fft1(out + step, A + step, n, step * 2);
for (i = 0; i < n; i += 2 * step)
{
theta = -PI * i / n;
a = cos(theta);
b = sin(theta);
c = out[i + step].real;
d = out[i + step].image;
t.real = a * c - b * d;
t.image = b * c + a * d;
A[i / 2].real = out[i].real + t.real;
A[i / 2].image = out[i].image + t.image;
A[(i + n) / 2].real = out[i].real - t.real;
A[(i + n) / 2].image = out[i].image - t.image;
}
}
}
int fft1(CPLX A[], int n)
{
// fft函数,计
matlab中的xcorr函数的c语言转写,与matlab运算结果完全一致
于 2022-12-09 00:08:23 首次发布
本文介绍了如何将MATLAB中的xcorr函数转换为C语言实现,详细阐述了互相关运算的步骤,包括补零操作、FFT与IFFT的运用,以及同步定位结果的获取,确保运算结果与MATLAB完全一致。
摘要由CSDN通过智能技术生成