I'm trying to implement an inverse discrete Fourier transform function.
The input x
is a vector of floats, but I need to perform complex math on it in the for loops.
I created a placeholder for x
, which is called vector_x
. vector_x
is a vector of complex 0s. When I ran the code below, I got an an error of:
no matching function for call to βstd::vector<float>::vector(std::vector<std::complex<float> >::size_type, std::complex<float>)β
std::vector<float> vect_x(Xf.size(),static_cast<std::complex<float>>(0, 0));"
void IDFT(std::vector<float> &x, const std::vector<std::complex<float>> &Xf)
{
// allocate space for the vector holding the frequency bins
// initialize all the values in the frequency vector to complex 0
// x.resize(Xf.size(), static_cast<float>(0.0));
std::vector<float> vect_x(Xf.size(),static_cast<std::complex<float>>(0, 0));
// x_in.resize(Xf.size(), static_cast<float>(0.0));
// "auto" keyword is used for type deduction (or inference) in C++
for (auto k = 0; k < Xf.size(); k++)
{
for (auto m = 0; m < vect_x.size(); m++)
{
std::complex<float> expval(0, 2 * PI * (k * m) / vect_x.size());
vect_x[k] += vect_x[k] * std::exp(expval);
}
}
}