【问题标题】:Convert std::vector<complex<double>> to complex<double>[N] for FFT将 std::vector<complex<double>> 转换为 complex<double>[N] 以进行 FFT
【发布时间】:2022-01-07 11:34:26
【问题描述】:

我正在处理基于 FFT 的 wav 文件处理。我已经开发/复制了用于 wav 读取和 fft 处理的功能。 问题是我的wav读取函数返回一个vector,而我的FFT需要complex&lt;double&gt;[N],我不知道如何将vector&lt;double&gt;vector&lt;complex&lt;double&gt;&gt;连接到complex&lt;double&gt;[N]。如何转换我的数据? 我很抱歉我的菜鸟,这是我关于 SO 的第一个问题。

void FFT(Complex f[], Complex ftilde[], int log2N);

vector<double> amplitudes;
WavReader("../Projects/Project4/input.wav", amplitudes);

size_t size = amplitudes.size();                        
const int new_size = resize(size);        // Finding nearest number power of 2
int log2N = log2(new_size);

using Complex = complex<double>;
amplitudes.resize(new_size);
std::vector<double> imag{ 0.0 };
imag.resize(new_size);
vector<complex<double>> cvec(amplitudes.size());

transform(amplitudes.begin(), amplitudes.end(), imag.begin(), cvec.begin(), [](double da, double db) 
{
    return complex<double>(da, db);
});
    
Complex f[N];                   // The input of FFT 

【问题讨论】:

  • 需要complex&lt;double&gt;[N]的函数原型是什么?
  • void FFT(复数 f[], 复数 ftilde[], int log2N);

标签: c++ vector fft


【解决方案1】:

使用FFT(cvec.data(), ???, log2N)data() 函数将返回一个指向向量(连续)数据开头的指针。请确保log2N &lt;= cvec.size()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-11
    • 2018-12-06
    相关资源
    最近更新 更多