Last active
July 10, 2020 20:24
-
-
Save asheeshr/bc87f8c6486f649ef029 to your computer and use it in GitHub Desktop.
Simple Test File for Microsmooth Library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); | |
} |
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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks good. What is the best way to experiment with applying multiple filters at the same time?