matlab中的xcorr函数的c语言转写,与matlab运算结果完全一致

本文介绍了如何将MATLAB中的xcorr函数转换为C语言实现,详细阐述了互相关运算的步骤,包括补零操作、FFT与IFFT的运用,以及同步定位结果的获取,确保运算结果与MATLAB完全一致。
摘要由CSDN通过智能技术生成
#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函数,计
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值