LPF in mikroC pic 32

Thread Starter

idobh

Joined Jul 14, 2024
11
how can i do LPF in mikroc pic32?
what code do I need to implement to apply the LPF?

thank youd
 

Ian0

Joined Aug 7, 2020
13,097
What frequency sine-wave? What is the sampling rate? What does the noise consist of? and what frequency is it?
 

Thread Starter

idobh

Joined Jul 14, 2024
11
As you have added broadband noise, there will always be noise on the filtered signal, because the noise appears at every frequency.
in matlab I got this:
1720986649560.png


so i think that i some pic32 code of low pass filter i can do something like that
 

Ian0

Joined Aug 7, 2020
13,097
are you sure just this line will be enough for that?>
Yes - that's a single pole IIR filter. I use it all the time to remove noise from ADC inputs.
It can be implemented in three instructions in ARM code, so it executes in 62ns on a 48MHz clock.
 

Thread Starter

idobh

Joined Jul 14, 2024
11
Yes - that's a single pole IIR filter. I use it all the time to remove noise from ADC inputs.
It can be implemented in three instructions in ARM code, so it executes in 62ns on a 48MHz clock.
I have clock of 50 MHZ
are you can show me how to implement this filter to my code? how to do it?
 

Thread Starter

idobh

Joined Jul 14, 2024
11
Yes - that's a single pole IIR filter. I use it all the time to remove noise from ADC inputs.
It can be implemented in three instructions in ARM code, so it executes in 62ns on a 48MHz clock.
I see this fir code but its not working for me:

Code:
void CalculateFloatFilterCoefficients()
  {
   for (k = 0; k< (FILTER_ORDER +1); k++)
   {
    floatFilterCoefficient[k] = 1.0/(FILTER_ORDER+1);
   }
  }
 
  void ConvertCoefficients()
  {
   for (k = 0; k< (FILTER_ORDER +1); k++)
   {
    Q15_Ftoi( floatFilterCoefficient[k], &Q15_FilterCoefficient[k]);
   }
  }
 

void DoFIRfiltration()
  {
   for (k=0; k< (SIGNAL_LENGTH) ; k++)
   {
    outputData[k] = FIR_Radix(Q15_FilterCoefficient, FILTER_ORDER+1,signal, SIGNAL_LENGTH,k);
   }
  }
moderators note: added code tags
 
Last edited by a moderator:

Ian0

Joined Aug 7, 2020
13,097
I have clock of 50 MHZ
are you can show me how to implement this filter to my code? how to do it?
Your input signal is noisy_sine_wave.
so
filtered_sine_wave += (noisy_sine_wave-filtered_sine_wave)/factor

factor sets the frequency response

By the way, FIR filtering takes an awful lot of computation - for whatever number of coefficients you have you have to do that many MAC instructions every cycle.
 
Top