Code Optimize

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Code Optimize

1,862 Views
VincentLau
Contributor I
Hi,
  I am using MC13213 which is a hcs08 core to do FIR filiter calculation. However there are too many 16bit multiply 16bit data in this algorithm, so the time is too long. Is there anyone can give me some good ideas on how to simply this work or a better skill on multiplication? Thank you!
 
Sincerely
 
Vincent
 
Labels (1)
0 Kudos
Reply
4 Replies

683 Views
VincentLau
Contributor I
Ok. I paste my code here. Maybe it is  a liitle "puerile" code. :smileywink:
 
const float H[25]={ 0,0,0, 0.0012,0.0035,0.0024,-0.0088,-0.0269,-0.0272,0.0243,   0.1326,   0.249,
     0.3,0.2492,0.1326,0.0243,-0.0272,-0.0269,-0.0088,0.0024,0.0035, 0.0012,0,0,0};
unsigned int Original_Data[512];
 
void FIR_Filter(void){
      unsigned int i,j;
      float temp=0.0;
      
      for(i=24;i<512;i++){
      
        for(j=0;j<25;j++){
       
             temp+=( H[j] * Original_Data[i-j] );                      
                       
         }
         Original_Data[(i-24)]=(unsigned int) temp;
          temp=0.0;
      }
}
 
Thanks a lot to anyone who gives me ideas!
0 Kudos
Reply

683 Views
Morph19
Contributor I
Hello, a couple of months ago i did a FIR and a IIR filter in the AW60, they were like 11 order or so, and the sampling frecuency was 5 KHz for one of them and 4 KHz for the other. I use the 10 bits ADC  from the AW60  for the input and a serial 10 bits DAC for the output. I used the math subroutines from the "AN1219-M68HC08 Integer Math Routines" and 20MHz bus frecuency. They are very slow filters if you take a look at the 20Mhz bus, but i never try to optimize the algoritms. Why do you say that you algorithm is slow, what sampling frecuency are you getting. The first thing to optimize my filter would be a parallel very fast DAC.
0 Kudos
Reply

683 Views
VincentLau
Contributor I
Thank you again for your reply, Morph19. I am using a Kaiser window FIR filter to smooth noise that is great than 5 Hz when the sample frequence is 100 Hz and order is 25! I test it on MC13213 which bus frequence is 8 MHz. However, what a pity is that it almost spends 12 seconds on processing 512 sampling data.I think that too many const float data multiplication from Kaiser window may be an hard work for an 8-bit MCU. How can I fix it by a skill way? 
 
0 Kudos
Reply

683 Views
kef
Specialist I
Morph19 suggested you using integer only routines. That would be way faster.
 
Is your 512 samples buffer integer or float? Conversion from float to int and back can take a lot of time. And FIR code, I guess, iterates more than once through this buffer. Making buffer float could improve the speed.
Could you show your filter code? Someone could give you more ideas.
 
BTW for some weird reasons, maybe optimization for size, HC(S)08 Codewarrior floating point multiply routines aren't using hardware multiplier (8x8->16bit MUL instruction). Of course that's slow. Multiply routine takes almost 4000 bus cycles on non zero and finite arguments. Using MUL it could take less than 700 cycles.
 
0 Kudos
Reply