Fast Fourier Transform (FFT) (Part 4)

Part 1234567891011

Once the FFT algorithm is executed, we get complex values, made of imaginary values and real values. We need to apply some maths in order to convert them in magnitude values. This is quite simply done thanks to the following routine which converts the complex (so as to say rectangular) values into a polar value:

void PlainFFT::complexToMagnitude(double *vR, double *vI, uint8_t samples) {
// vM is half the size of vR and vI
	for (uint8_t i = 0; i < samples; i++) {
		vR[i] = sqrt(sq(vR[i]) + sq(vI[i]));

Read this document about conversion (p 6)

Computing the phase information is quite easy, but I do not really care about it and it requires the arctangent() trigonometric which does not come standard in Arduino language. However if you need it, you will have to use the math library) and compute the pahse values using the following formula: phase[FFT(A)]=arctangent(|Imag[FFT(A)]| / |Real[FFT(A)]|).

Next post on same subject

Leave a Reply

You must be logged in to post a comment.