0

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);
        }
    }
}
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
  • 1
    Almost the same code as in [this question](https://stackoverflow.com/questions/65968989/no-instance-of-overloaded-function-when-resizing?noredirect=1#comment116637545_65968989). And the answer is relevant too. – Lukas-T Jan 30 '21 at 15:39
  • 1
    @churill Either all the students are entering the same question - or we have a case of violating `StackoverflowMember(const StackoverflowMember&) = delete;` – Ted Lyngmo Jan 30 '21 at 15:41

0 Answers0