Fixed Point DSP Rounding Help Topic is solved

Sub forums for various specialist XMOS applications. e.g. USB audio, motor control and robotics.
Post Reply
RitchRock
XCore Addict
Posts: 186
Joined: Tue Jan 17, 2017 9:25 pm

Fixed Point DSP Rounding Help

Post by RitchRock »

Can anyone point me to a good reference or help me understand what I should be doing to get my rounding correct when doing multiplication in the frequency domain w/ fixed point numbers?

NOTE: I'm using dsp_fft_split_spectrum and dsp_fft_merge_spectra so that I can save on operations. That's why I'm just multiplying the "two reals" together instead of complex vector multiplication in the following code. The final output seems to have low SNR and some artifacts, however my filter cutoff frequencies do seem to be as expected. Again, I believe it's a rounding problem. If I comment out the multiplication my output sounds fine...any help is appreciated.

Code: Select all

#define GUARD 2

void mult_two_reals(dsp_complex_t A[NFFT/2][2], dsp_complex_t B[NFFT/2][2]){
    unsigned r_one_lo ,r_two_lo;
    int r_one_hi , r_two_hi;
    
    int round = 0x7FFFFFFF;

#pragma unsafe arrays
    for (int x=0 ; x<2 ; x++){
        for(int y=0 ; y<(NFFT/2) ; y++){
            {r_one_hi , r_one_lo} =  macs(A[y][x].re, B[y][x].re, 0, round);
            {r_two_hi , r_two_lo} =  macs(A[y][x].im, B[y][x].im, 0, round);
            A[y][x].re = r_one_hi<<GUARD | r_one_lo>>(32-GUARD);
            A[y][x].im = r_two_hi<<GUARD | r_two_lo>>(32-GUARD);
        }
    }
}


View Solution
User avatar
andrew
Experienced Member
Posts: 114
Joined: Fri Dec 11, 2009 10:22 am

Post by andrew »

I would use long long multiplication. If you use a long long as the intermediate storage type then left shift to return to int type you will get at most 0.5 bits of error.
for example:(using stdint.h)

Code: Select all

int32_t x, y;
int32_t a = ((int64_t)x * (int64_t)y)>>31;
RitchRock
XCore Addict
Posts: 186
Joined: Tue Jan 17, 2017 9:25 pm

Post by RitchRock »

Makes sense, however I am still getting the same result.

I noticed that within the comments for dsp_fft_split_spectrum() it states that "the DC component of the imaginary output spectrum (index zero) will contain the real component for the Nyquest rate." Should I be doing something special with this?
User avatar
andrew
Experienced Member
Posts: 114
Joined: Fri Dec 11, 2009 10:22 am

Post by andrew »

Yes, you don't treat the DC or NQ as complex numbers like all the rest(i.e. a real multiplication is one multiply and a complex multiply is four real multiplications)
RitchRock
XCore Addict
Posts: 186
Joined: Tue Jan 17, 2017 9:25 pm

Post by RitchRock »

Aha! That helped me realize where I was going wrong. Working now. Thanks!
Post Reply