Skip to content

Instantly share code, notes, and snippets.

@asheeshr
Last active July 10, 2020 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asheeshr/bc87f8c6486f649ef029 to your computer and use it in GitHub Desktop.
Save asheeshr/bc87f8c6486f649ef029 to your computer and use it in GitHub Desktop.
Simple Test File for Microsmooth Library
#include <microsmooth.h>
uint16_t *ptr;
void setup()
{
Serial.begin(9600);
pinMode(3, INPUT);
ptr = ms_init(EMA);
if(ptr == NULL) Serial.println("No memory");
}
void loop()
{
int i = pulseIn(3, HIGH, 25000);
Serial.print("Input: "); Serial.println(i);
Serial.println(ema_filter(i, ptr));
Serial.println("Back");
delay(100);
}
@mavincent
Copy link

Yo dude, (sga_filter( -> (ema_filter(

Very nice btw

@PogCarr
Copy link

PogCarr commented Oct 6, 2015

Sadly, I can't get this code to work at all. The above test file will not compile and run. :-(

@sijojohnkv
Copy link

i tried to run this code unfortunatly not working :( any alternatives??

@asheeshr
Copy link
Author

Should work now.

@jamiej1989
Copy link

Does the sga filter work? It's just giving me a value of 0. I'm trying to filter a spectroscopy signal, considering sga was invented for this it would be great to get it working.

@FlyF1D
Copy link

FlyF1D commented Aug 2, 2017

It should be noted that this library does not accept float inputs. The author has stated elsewhere that this is the case:
http://code-run-debug-repeat.blogspot.com/2014/03/microsmooth-signal-smoothing-library.html

@juliusbangert
Copy link

Looks good. What is the best way to experiment with applying multiple filters at the same time?

@TeoLucco
Copy link

TeoLucco commented Oct 5, 2017

Same problem of jamiej1989. I'm trying to use SGA filter, but it gives me always 0. I'm using int variables.
Any idea?

@moebiussurfing
Copy link

@juliusbangert
how can i process multiple signals?

@maxpfeif
Copy link

maxpfeif commented Mar 13, 2018

@asheeshr In your sga_filter you have defined i as an uint8_t, but later assign it to be a negative number in a for-loop. This can be problematic...

See i=-SGA_MID.

uint64_t sum=0;
uint8_t SGA_MID = SGA_LENGTH/2;
uint8_t i;

for(i=1;i<SGA_LENGTH;i++)
{
history_SGA[i-1]=history_SGA[i];
}
history_SGA[SGA_LENGTH-1]=current_value;

for(i=-SGA_MID;i<=(SGA_MID);i++)
{  
sum+=history_SGA[i+SGA_MID]*sga_coefficients[SGA_INDEX][i+SGA_MID];
}
history_SGA[SGA_MID]=sum/normalization_value;
return history_SGA[SGA_MID];

}

:)

@irwanayeah
Copy link

irwanayeah commented Jul 10, 2020

@asheeshr great, code work for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment