我正在编码一种快速傅立叶变换算法,该算法使用复数向量递归地执行Cooley Tukey方法。头文件和.cpp文件的参数名称和语法匹配,但是仍然出现“未定义引用”错误。由于错误中提到了“额外”分配器参数。我认为这可能与为我们的抽象基类和派生的Cooley-tukey类使用模板有关。所有问题都来自FFF_REC函数,该函数递归划分输入。
Github:https://github.com/ProgrammerB/Fourier-Transform-Terminal-/blob/master/classes/cooley-tukey.h
我已经尝试将参数更改为引用,并将私有成员添加到cooley-tukey类中,但是却遇到相同的错误。
Cooley-Tukey班:
template<typename T>
class Cooley_tukey: protected Fourier<T>{
public:
Cooley_tukey();
Cooley_tukey(std::string file_name, double frequency, double,
frequency_step, std::string output_name);
//~Cooley_tukey();
void FFT(const std::vector<T> &index, const std::vector<T> &value);
std::vector<complex<T>> FFT_REC(std::vector<complex<T>> &temp, int
total_time); //recursion function for FFT
private:
int total_time;
};
部分错误:
classes\cooley-tukey.cpp:91:10: error: no matching function for call to
'Cooley_tukey<double>::FFT_REC(std::vector<std::complex<double>,
std::allocator<std::complex<double> > > [(total_time / 2)], int,
std::vector<std::complex<double>, std::allocator<std::complex<double> >
>&)'FFT_REC(odd, total_time/2, result);
FFT递归函数(错误源):
template<typename T>
std::vector<complex<T>> Cooley_tukey<T>::FFT_REC(std::vector<complex<T>>& temp, int total_time)
{
// Check if it is split up enough
if (total_time >= 2)
{
// Split even and odds up
std::vector<complex<T>> odd[total_time/2];
std::vector<complex<T>> even[total_time/2];
for (int i = 0; i < total_time / 2; i++)
{
even->at(i) = temp.at(i*2);
odd->at(i) = temp.at(i*2+1);
}
// Split up tasks through FFT recursion method
FFT_REC(even, total_time/2);
FFT_REC(odd, total_time/2);
// DFT portion of FFT - calculates after everything has been split up through FFT_REC
for (int frequency = 0; frequency < total_time / 2; frequency += this->frequency_step)
{
std::complex<T> t = exp(std::complex<T>(0, -2 * M_PI * frequency / total_time)) * odd->at(frequency);
//Result of Cooley-Tukey algorithm:
//*This gives us the frequency values at certain times
temp.at(frequency) = even->at(frequency) + t;
temp.at(total_time / 2 + frequency) = even->at(frequency) - t;
}
}
return temp;
}
template class Cooley_tukey<double>;
答案 0 :(得分:0)
您要创建一个向量数组,形式为even
/ odd
,而您应该只有一个向量。该错误表明没有一种方法可以采用向量数组。
我想你是说:
// Split even and odds up
std::vector<complex<T>> odd;
std::vector<complex<T>> even;
odd.reserve(total_time/2);
even.reserve(total_time/2);
for (int i = 0; i < total_time / 2; i++)
{
even.push_back(temp.at(i*2));
odd.push_back(temp.at(i*2+1));
}
您还试图使用at()
将值设置为空向量,这会导致错误。向量可能没有分配任何存储空间,如果您尝试使用at()
对其进行索引,则在超出范围时会出现异常。