# How to implement the imaginary part of FFT equation applied to a signal in computer/C++?

I am trying to apply FFT on a time domain signal in C++, however I am having trouble with the imaginary part i.e square root of -1. In the FFT equation we have,

$$X =\frac{1}{2\pi}\int_a^b x(t) \ e^{-j\omega t} \ dt$$

we know that: $$e^{-j\omega t} = \cos(\omega t) - j\sin(\omega t) \tag{2}$$

we also know that:

$$\ j = \sqrt{-1}\$$

Problem : I am trying to apply the fft equation on a signal and the problem of implementation arises when coding the equation(2) in C++. As, we know the value of $\ j = \sqrt{-1}\$ is infinite or if tried to solve using a calculator, we get a Math Error*. And so is my program giving an error and I'd like to get suggestions and advises on how to solve this issue and apply the FFT equation in C++.

• Use a 2 element vector for complex numbers, store the imaginary component as a real number in the 2nd element (without any sqrt(-1)), and read up on complex arithmetic, as you can't use C scaler arithmetic operations on complex numbers (2 element vectors) and get the correct results. – hotpaw2 Mar 18 '15 at 18:50

Specifically in C++, there is the class complex<T> from the STL library that takes care of storing two values of type T for every complex value. You should use that, it's part of the standard libraries.