Matlab FFT函数交换索引 [英] Matlab fft function swapping indices

查看:94
本文介绍了Matlab FFT函数交换索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了一个简单且很小的Matlab代码,用于计算给定数组(或向量)的离散傅立叶变换.

I've written a simple and very small Matlab code that calculates the Discrete Fourier Transfrom of a given array (or vector).

我手动解决了这个问题,得到了答案,我的Matlab代码也给出了相同的答案.但是fft通过交换索引给出了与此不同的答案.这是我完成的人工计算:

I worked it out manually and got an answer and my Matlab code also giving the same answer. But fft is giving an answer different from this by swapping indices. Here are the mannual calculations that I've done:

这是第二张图片:

这是第三张图片:

通过这些计算,很明显我的答案将是{12, -3-3j, -2, -3+3j}

From those calculations it is clear that my answer would be {12, -3-3j, -2, -3+3j}

这是我使用过的Matlab代码:

Here is the Matlab code that I've used:

clc;
clear all;
close all;
inp=[1,2,3,4];
j=sqrt(-1);
op=zeros(1,length(inp));
for k=1:length(inp)
    sigma=0;
    for n=1:length(inp)
        sigma=sigma+inp(n)*exp((j*2*pi*(k-1)*(n-1))/length(inp));
    end
    op(k)=sigma;
end
% Checking with fft
fft(inp)

现在,我得到这样的输出:

Now I'm getting output as this:

我正在交换价值,这是非常出乎意料的.它正在交换索引2和4.

It is very much unexpected that I'm getting values swapped. It is swapping the indices 2 and 4.

推荐答案

看来您的权重符号有误(这意味着您可能正在执行逆FFT而不是正向FFT-请记住,正向FFT转换权重为exp(-j * theta) ).

It looks like you have the wrong sign for your weights (which means you're probably doing an inverse FFT instead of a forward FFT - remember that for the forward transform the weights are exp(-j * theta)).

更改:

    sigma=sigma+inp(n)*exp((j*2*pi*(k-1)*(n-1))/length(inp));

收件人:

    sigma=sigma+inp(n)*exp(-(j*2*pi*(k-1)*(n-1))/length(inp));

这篇关于Matlab FFT函数交换索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆