Median or mode filter

Everything about programming the platform and using the Waspmote API
Post Reply
stefan_FVT
Posts: 5
Joined: Mon Sep 25, 2017 1:30 pm
Company: Fiskevårdsteknik

Median or mode filter

Post by stefan_FVT » Tue Sep 26, 2017 2:45 pm

Hi,
I'm sampling the ultrasonic sensor but the values are a bit noisy and I would like to calculate the median or mode value for 10 measurements with each measurement taken with half a second apart.

I couldn't find any function for this in the library and I've tried importing Arduino libraries with errors. If someone have a filter or a code snippet that works I would be thankful!

/Stefan

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: Median or mode filter

Post by libelium-dev » Wed Sep 27, 2017 10:30 am

Hi Stefan,

You can calculate the average for 10 values developing a code like this

Code: Select all

  int sum = 0;
  for ( int i=0; i<10; i++){    
    // get distance     
    dist = Agriculture.getDistance();  // this function will be different depending on your sensor board
  
    sum = sum + dist;
    delay(1000);
  }
  
  // calculate average
  float average = sum/10;
Regards

stefan_FVT
Posts: 5
Joined: Mon Sep 25, 2017 1:30 pm
Company: Fiskevårdsteknik

Re: Median or mode filter

Post by stefan_FVT » Wed Sep 27, 2017 11:41 am

I don't want to use an average value since it will include the noise.

I rather use a median or mode to exclude abnormal readings.

Is there a way of doing this?

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: Median or mode filter

Post by libelium-dev » Thu Sep 28, 2017 8:39 am

Hi,

What formula do you want to implement?

Regards

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest