• AVR Freaks

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

New Member
  • Total Posts : 4
  • Reward points : 0
  • Joined: 2020/05/03 13:08:07
  • Location: 0
  • Status: offline
2020/07/23 18:11:43 (permalink)
4 (1)

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 online

My 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 */
    FFTComplexIP(DMA_BUFFER_LENGHT_LOG, &sigCmpx[0], &twiddleFactors_FFT[0], COEFFS_IN_DATA);
    FFTComplexIP(DMA_BUFFER_LENGHT_LOG, &sigCmpx[0], (fractcomplex *) __builtin_psvoffset(&twiddleFactors_FFT[0]), (int) __builtin_psvpage(&twiddleFactors_FFT[0]));
    /* Store output samples in bit-reversed order of their addresses */
    BitReverseComplex(DMA_BUFFER_LENGHT_LOG, &sigCmpx[0]);
 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 */
    IFFTComplexIP(DMA_BUFFER_LENGHT_LOG, &sigCmpx[0], &twiddleFactors_IFFT[0], COEFFS_IN_DATA);
    IFFTComplexIP(DMA_BUFFER_LENGHT_LOG, &sigCmpx[0], (fractcomplex *) __builtin_psvoffset(&twiddleFactors_IFFT[0]), (int) __builtin_psvpage(&twiddleFactors_IFFT[0]));


1 Reply Related Threads

    Starting Member
    • Total Posts : 36
    • Reward points : 0
    • Joined: 2008/04/16 12:09:44
    • Location: 0
    • Status: offline
    Re: Wanted fast atan2() code implementation for a dsPIC33FJ128GP802 based guitar phaser ef 2020/09/17 04:33:16 (permalink)
    I'm working on FOC motor control and the example code in AN1078 uses a CORDIC method to do essentially atan2(). There is also a sin/cos derivation from an angle since the calculations in FOC are rotational transforms etc...
    I wonder if the libq.h might also have anything useful for you? (https://www.microchip.com/forums/m790718.aspx)
    Jump to:
    © 2020 APG vNext Commercial Version 4.5