# Wanted fast atan2() code implementation for a dsPIC33FJ128GP802 based guitar phaser effect

Hi, I'm new here and this is my first post :D

I'm trying to make a phaser guitar pedal using a dsPIC33FJ128GP802 and the Microchip's FFT/iFFT library functions.

I did all the hard calculations and finally get the board working in playback mode. It does what follows in realtime:

sample 128 samples from the ADC -> do the FFT to 128 samples -> do the iFFT to the 128 samples -> output through the DAC 128 samples

open image file onlineMy problem at this point is that I can't find around the web a fast enough fixed point Q1.15 format atan2() cos() and sin() function implementation that can allow me to do all the needed computations for a phaser effect for 128 samples in a time approximately of (1/(36.423529KHz))*128 seconds without counting the time to do FFT and iFFT. Yes, the sampling frequency of this device is set to 36.423529KHz.

Can you help me somehow finding a faster atan2() implementation? I was thinking of lookuptables but I have not so much memory on the dsPIC...

Furthermore is this the way a phaser should be implemented? I want to implement it necessarely using the FFT/iFFT library functions...

The code below is taken from my repo:

Github profile: DanCasterIt

Name of the repo: dspic-phaser-effect

I don't put the link otherwise the forum do not allow me to do this post. There you can find the entire MPLABX project ready to be cloned and compiled.

if I enable the atan2() in the loop after "//PHASER CODE" I can hear pure noise from the output of the DAC because the function takes more time than the sampling period. If I delete the loop and its content everything works perfectly in playback mode.

/* Perform FFT operation */

#if FFTTWIDCOEFFS_IN_PROGMEM

FFTComplexIP(DMA_BUFFER_LENGHT_LOG, &sigCmpx[0], &twiddleFactors_FFT[0], COEFFS_IN_DATA);

#else

FFTComplexIP(DMA_BUFFER_LENGHT_LOG, &sigCmpx[0], (fractcomplex *) __builtin_psvoffset(&twiddleFactors_FFT[0]), (int) __builtin_psvpage(&twiddleFactors_FFT[0]));

#endif

/* Store output samples in bit-reversed order of their addresses */

BitReverseComplex(DMA_BUFFER_LENGHT_LOG, &sigCmpx[0]);

//PHASER CODE

SquareMagnitudeCplx(DMA_BUFFER_LENGHT, &sigCmpx[0], &module[0].real);

for(i = 0; i < DMA_BUFFER_LENGHT; i++) {

phase[i] = (fractional) atan2((float) sigCmpx[i].imag, (float) sigCmpx[i].real);

//LFO TO PHASE

sigCmpx[i].real = (fractional) ((float) module[i].real * cosf((float) phase[i]));

sigCmpx[i].imag = (fractional) ((float) module[i].real * sinf((float) phase[i]));

}

/* Perform IFFT operation */

#if FFTTWIDCOEFFS_IN_PROGMEM

IFFTComplexIP(DMA_BUFFER_LENGHT_LOG, &sigCmpx[0], &twiddleFactors_IFFT[0], COEFFS_IN_DATA);

#else

IFFTComplexIP(DMA_BUFFER_LENGHT_LOG, &sigCmpx[0], (fractcomplex *) __builtin_psvoffset(&twiddleFactors_IFFT[0]), (int) __builtin_psvpage(&twiddleFactors_IFFT[0]));

#endif