I have made a test program in python "test upsample downsample wav.py" to understand how the re-sampling process works.
The program uses a FIR filter with the coefficients calculated with the online tool Tfilter: http://t-filter.engineerjs.com/
The program takes as an input a wave 16 bit mono file and outputs 6 wave files :
8X upsample
4X upsample
2X upsample
1/2X Downsample
1/4X Downsample
1/8X Downsample
Then I tried to port the same program on the PIC.
Probably i have exaggerated with the number of taps of the filter as i have 117 - 233 and 465 taps for my three filters. Ah, I have used the same filter for 2X upsample and 1/2 downsample, 4X and 1/4X, 8X and 1/8X.
I found out that to convert a sample of about 2 seconds it takes 15 minutes to the PIC with my NOT optimized program!
As the PIC has to read and write the values from the external flash memory a small part of this time is used for this but most of the time (about 90%) is used by this loop:
for (i=0;i<nTaps;i++){
out+=(int32_t)inbuffer[i]*FilterTaps[i+FilterOffset[Ratio]];
}
that is the convolution of the filter with the signal.
The PIC24 i am using does not have multiply and accumulate instructions for signal processing. I am now trying to optimize the code writing it in assembler. This part does not need to be in real time but 15 minutes is too long. I am also considering the option to switch to a dsPIC33 that has the MAC instructions.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.