Gaussian smoothing of time series
Afficher commentaires plus anciens
I have a time series with measurements taken at time t along with measurement uncertainties. I would like to smooth this data with a Gaussian function using for example, 10 day smoothing time.
How could this be done?
Thank you
Réponse acceptée
Plus de réponses (2)
Image Analyst
le 16 Mai 2013
If you don't have the Signal Processing Toolbox, make up your weighted window, then use conv():
filteredSignal = conv(originalSignal, gaussianWindow);
1 commentaire
Ashraful Haque
le 18 Mai 2020
Hey I know this comment is from a long time ago. But Hopefully you see my reply. My question was how do I create a gaussian window function without the signal processing toolbox? What are the input(s) and output(s)?
Andreas Pagel
le 5 Août 2021
I had a similar issue with some 'random' noise spikes on the signal which I wanted to eliminate. The usual smoothing and moving avg approaches I found when searching for solutions did not match my expectations as the noise would still distord the results.
So, I created some kind of of a gauss filter, using a scatter recording approach.:
the code is still a bit rough but does it's job.
I get 10 readings, record them in an array thay counts how ofter a given value is found and pull then the value that got most hits;
#define sampleSize 10
int sampleArray[sampleSize + 1][2] = {{0}}; // initialise array
Sorry for being lazy...
I know it's not optimal but I like the easy way of using real references for adressing the array, ie 1st record sits in array[1]
push () records the values and increments the counter for a given value:
void push (int val) {
short i = 0;
for (i = 1; i <= sampleSize; i++) {
if (debug) Serial.printf("%i-%i: %i #%i\n", i, val, sampleArray[i][0], sampleArray[i][1]);
if (sampleArray[i][0] == val) {
++sampleArray[i][1];
return;
}
else if (sampleArray[i][0] == 0) {
sampleArray[i][0] = val;
++sampleArray[i][1];
return;
}
else if (i == sampleSize) Serial.printf("ERROR - too many values: %i\n", i);
}
}
and pull() returns the value with most hits:
int pull() {
int maxCnt = 0;
int maxVal = 0;
short i = 0;
for (i = 1; i <= sampleSize; i++) {
if (sampleArray[i][1] > maxCnt) {
maxCnt = sampleArray[i][1];
maxVal = sampleArray[i][0];
}
}
return maxVal;
}
since I wanted to simplify the tests, I did not even use a data source but simply used random numbers.
int readValue() {
short i = 0;
// reinit array
for (i = 1; i <= sampleSize; i++) {
sampleArray[i][0] = 0;
sampleArray[i][1] = 0;
}
for (i = 1; i <= sampleSize; i++) {
//push(AnalogRead(ADC));
push(random(20, 35));
}
return pull();
}
my main loop calls the readValue() and sends it to an IoT cloud - now lukily with out anymore with the spikes I ahd before.
I use the code now in different sketches for data capturing and it works perfectly fine :-)
Catégories
En savoir plus sur Images dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!