-
Notifications
You must be signed in to change notification settings - Fork 337
Libre value smoothing
Libre values are usually not smooth. Goal is to smoothen the values. xDrip4iOS uses Savitzky Golay algorithm as explained here
Smoothening is done in two steps:
- First the per minute values are smoothed. Libre always sends per minute values for the latest 16 minutes. Previous readings will be stored, up to maximum 64, as a result the 64 latest per minute readings will be smoothed. Here a filterWidth of 5 is used, and applied 2 times.
- As a third step, smooth per 5 minutes : every value in the range of 16 (up to 64) per minute readings, will be smoothed with values from 5, 10, 15 minutes before and 5, 10, 15 minutes after, with a filterWidth of 3, and applied 3 times. The reason to do an additional smoothing per 5 minutes, is because in the end, xDrip4iOS will only show a reading every 5 minutes, and not per minute.
Also the 32 per 15 minutes values will be smoothed but these will only be used if the app did not read values for more than 15 minutes. Here the filterWidth is 4, which is quite agressive. When smoothing the values of 8 hours (maximum amount of readings that Libre can send), high peaks (or dips) may be strongly flattened. This would only be applicable if Libre hasn't been read for longer period. If the Libre is read every 5 minutes, then the smoothing of peaks will be less because it's per minute.
When processing the last reading, then we don't know yet that the reading is a peak (or dip). The algorithm assumes that the readings will continue to go up or down at the same speed as the last 5 minutes. As a result, the last reading may still not be very well smoothed.
The smoothing needs to be enabled in the developer settings.
Before using the resulting values, the existing readings of the last 21 minutes will be deleted, and then recreated using the new smoothed values.
This is an example of smoothing 15 minutes of readings (just as an example to show how it's done)
https://github.com/JohanDegraeve/xdripswift/blob/master/xdrip/Extensions/Array.swift
Smoothing is applied in the function parseLibre1Data in https://github.com/JohanDegraeve/xdripswift/blob/master/xdrip/BluetoothTransmitter/CGM/Libre/Utilities/LibreDataParser.swift
There's additional processing in function processNewGlucoseData in https://github.com/JohanDegraeve/xdripswift/blob/master/xdrip/View%20Controllers/Root%20View%20Controller/RootViewController.swift