What does IIR and FIR filter are used for in embedded

I have actually made a code for it. but I am not tested it right now. I like to show it to you guys, if u can figure out will it work or not. what it does it takes 2 averages one move faster and other move slower. and for output on buzzer if fast average is greater than slower the target is detected, but that I will figure out when I test it in field.

This code I made from by reading from different detector related projects

and if u all are wondering what controller I am using. I am working with attiny1617.

#define sampleAveShift 5
#define sampleArraySize 32
#define trackAveShift 6
#define trackArraySize 64

const byte adc = A0;



unsigned int CurrentSample;    //holds value from adc
unsigned int SampleAve = 0; // this is fast average 4*32 =128 samples
unsigned int TrackAve = 0; //this is slower average 4*32*64 samples


void setup()
{
  Serial.begin(115200);

}
void loop()
{
  CurrentSample = analogRead(adc);
  ProcessSample();
}


void ProcessSample(void)
{
  static unsigned int sampleArray[sampleArraySize];
  static unsigned int trackArray[trackArraySize];
  static char sampleIndex = 0, trackIndex = 0;
  static unsigned int tmp = 0;
  static char i, sampleCount;
  tmp += CurrentSample; // tmp is effectively a 12-bit value
  sampleCount++;
  if (sampleCount == 4) // If we've accumulated 4 samples, store
  {
    sampleArray[sampleIndex] = tmp >> 2; // Store the current sample - 10 bits
    sampleCount = 0;
    tmp = 0;
    sampleIndex++; // Increment the array pointer
    if (sampleIndex == sampleArraySize) // If we're wrapping around...
      sampleIndex = 0; // Set the pointer back to the beginning
    SampleAve = 0;
    for (i = 0; i < sampleArraySize; i++) // Average all the samples
      SampleAve += sampleArray[i]; // This is effectively a 15-bit value
    SampleAve >>= sampleAveShift; // Divide back down to a 10-bit value
    Serial.println(SampleAve);
    trackArray[trackIndex] = SampleAve; // Store the average
    trackIndex++; // Increment the array pointer
    if (trackIndex == trackArraySize) // If we're wrapping around...
      trackIndex = 0; // Set pointer back to the beginning
    TrackAve = 0;
    for (i = 0; i < trackArraySize; i++) // Average all the averages
      TrackAve += trackArray[i]; // This is effectively a 16-bit value
    TrackAve >>= trackAveShift; // Divide back down to a 10-bit value
    Serial.print("TrackAve");
    Serial.println(TrackAve);
  }
}