help proggraming a sensor to count RPM

hi all in the forum here is what im trying to program. i have an optical sensor which its inside a black case outside the case im shooting a potholed pointer(those you use in presentations) so when a the flying wheel pass, more specifically one tooth pass through the middle and block the light of the led the arduino reads it and start a count of the RPM..... for example if i use a teeth wheel(not sure yet about how many teeth id be using) for every 40 times the sensor goes low will be a spin in..........

im not good at programming so im almost an ignorant in this......

this is a code so very basic i wrote when using other examples.... but if you help me adding stuff for faster counts and filters would be good.... but im not sure if this code works i havent tested it i just wrote it, using all knowledge i have but this its my limits jejejee

volatile unsigned int rpmcount;
 unsigned int rpm;
 unsigned long timeold;
 void setup()
 
 {
   Serial.begin(115200);
   attachInterrupt(0, rpmfun, RISING);
   rpmcount = 0;
   rpm = 0;
   timeold = 0;
   }
 void loop()
 {
   if (rpmcount >= 100) { 
     
    rpm = (millis() - timeold) / rpmcount;
     const float freqHz = ((float) rpmcount / (float) (micros() - timeold)) * 1000000.0;
     const float RPM = freqHz * 60.0;
     timeold = micros();
     rpmcount = 0;
     Serial.println(rpm,DEC);
 
    }
 }
 void rpmfun()
 {
   rpmcount++;
 
 }

for reference the sensor its like a optical barrier, if its not very well explained...

one of the thing id like to implement its a low-pass filter, cos there are many facts to make irregular readings like electrical noises, vibration and many more so i would like to filter the sign using a low-pass filter....

im not really sure if this is right but it must be something like this:

double filtropasobajo (double *x, double *y, 
               int M, double xm1)
{
  int n;
  y[0] = x[0] + xm1;
  for (n=1; n < M ; n++) {
    y[n] =  x[n]  + x[n-1];
  }
  return x[M-1];
}

this would be in c..... but how to add it in the scketch for filter the sign???