1

I'm coding a Fast Fourier Transform algorithm that does the Cooley Tukey method recursively using complex vectors. The header file and the .cpp file match in parameter name and syntax, but I get the 'undefined reference' error still. Due to the "extra" allocator parameter being mentioned in the error. I think this might have something to do with using a template for our abstract base class and derived Cooley-tukey class. All of the problems have come from the FFF_REC function that recursively divides up the input.

Github: https://github.com/ProgrammerB/Fourier-Transform-Terminal-/blob/master/classes/cooley-tukey.h

I've already tried to change my parameters to references and add a private member into the cooley-tukey class, but I get the same error.

Cooley-Tukey Class:

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;

};

Part of the error:

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-Recursion function(source of errors):

    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>;
  • 1
    Possible duplicate of [Why can templates only be implemented in the header file?](https://stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header-file) – Some programmer dude Apr 28 '19 at 04:37
  • Possible duplicate of [Why can templates only be implemented in the header file?](https://stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header-file) – recnac Apr 29 '19 at 02:07

1 Answers1

0

You’re creating an array of vectors as even/odd whereas you should just have a vector. The error says there isn’t a method that takes an array of vectors.

I assume you mean:

// 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));
}

You were also trying to use the at() to set values into empty vectors which would’ve caused errors. Vectors may not have any storage allocated and if you try to index them with at() you’ll get an exception when it goes out of bounds.

Sami Kuhmonen
  • 30,146
  • 9
  • 61
  • 74