-
-
Save asheeshr/bc87f8c6486f649ef029 to your computer and use it in GitHub Desktop.
#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); | |
} |
Sadly, I can't get this code to work at all. The above test file will not compile and run. :-(
i tried to run this code unfortunatly not working :( any alternatives??
Should work now.
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.
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
Looks good. What is the best way to experiment with applying multiple filters at the same time?
Same problem of jamiej1989. I'm trying to use SGA filter, but it gives me always 0. I'm using int variables.
Any idea?
@juliusbangert
how can i process multiple signals?
@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];
}
:)
@asheeshr great, code work for me.
Yo dude, (sga_filter( -> (ema_filter(
Very nice btw