# Graphing Data at 10 Hz

**URL:** <https://forum.intervals.icu/t/graphing-data-at-10-hz/95981>\
**Category:** Uncategorized\
**Created:** [29 March 2025 20:03 UTC](https://forum.intervals.icu/t/graphing-data-at-10-hz/95981 "2025-03-29T20:03:08Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roger\_W\_Schmitz](https://forum.intervals.icu/user_avatar/forum.intervals.icu/roger_w_schmitz/32/61961_2.png) [@Roger\_W\_Schmitz](https://forum.intervals.icu/u/Roger_W_Schmitz)\
**Post date:** [29 March 2025 20:03 UTC](https://forum.intervals.icu/t/graphing-data-at-10-hz/95981/1 "2025-03-29T20:03:09Z")

</div>

I have a situation where I’m using a Garmin to collect Moxy data at 10 Hz via a ConnectIQ app. ConnectIQ only allows writing to the .fit file once per second so I set it up to write an array of timestamps, SmO2, and THb data in 3 developer data fields.

Now, I’d like to graph the data in Intervals. I can unpack the data in a custom stream script with the code below

```auto
{
    for (let m of icu.fit.record) {
        let timeArray = m['1st Time Sensor 7769 on Location Not Set']?.value;
        let smo2Array = m['1st SmO2 Sensor 7769 on Location Not Set']?.value;
        for (let i = 0; i < timeArray.length; i++) {
            if (timeArray[i] > 0) {
                console.log(timeArray[i]/1000 + "," + smo2Array[i])
            } 
        }
    }
}

```

I’d like to make a Custom Activity Chart to plot the data, but I’m not sure how to proceed. I’m not able to create an Activity Stream of the arrays of data. I’m not able to access the .fit data directly in the Custom Activity Chart.

Does anyone know of an approach for plotting this data?

[Here’s a link](https://1drv.ms/u/s!AhylFc6Kb-WOlPdG8aW-ij32IGQLgA?e=ILmJT8) to the .fit file with the arrayed data in it.

[Here’s a link](https://1drv.ms/u/s!AhylFc6Kb-WOlPdHHRZ9jU004pXTxQ?e=UPqph8) to the .csv file made from the .fit file.

---

<div class="post-metadata">

**Author:** ![david](https://forum.intervals.icu/user_avatar/forum.intervals.icu/david/32/30189_2.png) [@david](https://forum.intervals.icu/u/david)\
**Post date:** [2 April 2025 04:19 UTC](https://forum.intervals.icu/t/graphing-data-at-10-hz/95981/2 "2025-04-02T04:19:37Z")

</div>

I need to figure out how best to support high resolution data in activity streams. Right now everything except HRV is 1 Hz and there is special hackery for HRV. The easiest is to keep 1 Hz but have an array of values like what you have done. However I am worried that there will be some application needing ms precision on the timestamp for each value.

---

<div class="post-metadata">

**Author:** ![david](https://forum.intervals.icu/user_avatar/forum.intervals.icu/david/32/30189_2.png) [@david](https://forum.intervals.icu/u/david)\
**Post date:** [11 April 2025 10:10 UTC](https://forum.intervals.icu/t/graphing-data-at-10-hz/95981/3 "2025-04-11T10:10:15Z")

</div>

Custom activity streams can now store an array of numbers (32 bit floats) per second. You have to create the stream using Javascript, you can’t just select a record field.

```auto
{
  for (let m of icu.fit.record) {
    let v = m['1st SmO2 Sensor 7769 on Location Not Set']?.value
    if (v) data.setAt(m.timestamp.value, v)
  }
}

```

This is what ends up in the stream:

 ![Screenshot 2025-04-10 at 16.11.11](https://forum.intervals.icu/uploads/default/original/3X/1/4/141739dd69a3d6044a2d95757df3de4fb6f97439.png)

The Intervals.icu activity trace charts will display the first value from each array. You can [build your own charts in JavaScript](https://forum.intervals.icu/t/custom-activity-charts/28627) to get at the high resolution data.

The CSV download uses a single column with colons to separate the values (like HRV):

 ![Screenshot 2025-04-10 at 16.27.07](https://forum.intervals.icu/uploads/default/original/3X/1/3/13d9ae5613e48d5ef9abc456d77b0b4b123c6808.png)

I could make this work for the simple record field version but that would change existing behaviour. At the moment if you use that on an array field the first value from the array is used. Maybe I should just go ahead and make the change?

---

<div class="post-metadata">

**Author:** ![AlexxIT](https://forum.intervals.icu/letter_avatar_proxy/v4/letter/a/e9bcb4/32.png) [@AlexxIT](https://forum.intervals.icu/u/AlexxIT)\
**Post date:** [22 May 2026 08:22 UTC](https://forum.intervals.icu/t/graphing-data-at-10-hz/95981/4 "2026-05-22T08:22:41Z")

</div>

@Roger_W_Schmitz Can I ask you how you managed to record your data exactly once per second in the ConnectIQ app?

According to the SDK, we can call `field.setData`, but we don’t know exactly when the recording will occur. Therefore, we don’t know whether we need to add a new value to the current second’s array or whether it’s time to start the next one.

---

<div class="post-metadata">

**Author:** ![Roger\_W\_Schmitz](https://forum.intervals.icu/user_avatar/forum.intervals.icu/roger_w_schmitz/32/61961_2.png) [@Roger\_W\_Schmitz](https://forum.intervals.icu/u/Roger_W_Schmitz)\
**Post date:** [22 May 2026 13:11 UTC](https://forum.intervals.icu/t/graphing-data-at-10-hz/95981/5 "2026-05-22T13:11:09Z")

</div>

Hi AlexxIT,

In ConnectIQ, we can call field.setData whenever we want. We could call it at 1 Hz or call it faster or slower. The Garmin device is going to write to the .fit file once per second and it will write whatever data is set at that moment.

So if we were calling field.setData twice per second, half of the data we set would just get skipped. If we call field.setData once every two seconds, then every data point we set would get written to the .fit file twice.

One bummer is that we don’t know if the last data we set has been written to the .fit file yet. If we happen to be calling field.setData very close to in phase with when the Garmin writes to the .fit file, then it’s possible that some data points are written twice and some are skipped. I don’t know how tight the timing is on this so this might not be a common problem.

Best regards,

Roger

---

<div class="post-metadata">

**Author:** ![AlexxIT](https://forum.intervals.icu/letter_avatar_proxy/v4/letter/a/e9bcb4/32.png) [@AlexxIT](https://forum.intervals.icu/u/AlexxIT)\
**Post date:** [22 May 2026 13:18 UTC](https://forum.intervals.icu/t/graphing-data-at-10-hz/95981/6 "2026-05-22T13:18:09Z")

</div>

Thanks! If I understand you correctly, you have not solved the problem of reliably writing an array of data to a FIT file. This means that some data may be lost due to different timings of calling setData and the actual recording of data into the FIT file by the Garmin OS. Your demo file looks good. I thought you knew some secret.

---

<div class="post-metadata">

**Author:** ![pepe](https://forum.intervals.icu/user_avatar/forum.intervals.icu/pepe/32/36539_2.png) [@pepe](https://forum.intervals.icu/u/pepe)\
**Post date:** [22 May 2026 13:53 UTC](https://forum.intervals.icu/t/graphing-data-at-10-hz/95981/7 "2026-05-22T13:53:56Z")

</div>

Curiously, Garmin in its Heart Rate monitors with internal memory writes HRV using 12 timestamps in a go:

```auto
= TYPE=12 NAME=hr NUMBER=132
--- timestamp=1126167485=2025-09-07T08:18:05Z
--- event_timestamp=1778373632=1736693.000 s
--- fractional_timestamp=0=0.0000 s
--- filtered_bpm=71=71 bpm
--- xxx251=0=0
==
= TYPE=11 NAME=hr NUMBER=132
--- filtered_bpm=71=71 bpm,71 bpm,71 bpm,71 bpm,71 bpm,71 bpm,71 bpm,71 bpm
--- event_timestamp_12=0=0.000 s,0.031 s,0.068 s,0.214 s,0.117 s,0.206 s,0.075 s,0.108 s,0.021 s,0.022 s,0.083 s,0.135 s
==
= TYPE=11 NAME=hr NUMBER=132
--- filtered_bpm=71=71 bpm,71 bpm,71 bpm,75 bpm,77 bpm,78 bpm,79 bpm,79 bpm
--- event_timestamp_12=11=0.011 s,0.152 s,0.238 s,0.103 s,0.205 s,0.084 s,0.099 s,0.133 s,0.178 s,0.110 s,0.045 s,0.024 s
==

```

---

<div class="post-metadata">

**Author:** ![AlexxIT](https://forum.intervals.icu/letter_avatar_proxy/v4/letter/a/e9bcb4/32.png) [@AlexxIT](https://forum.intervals.icu/u/AlexxIT)\
**Post date:** [22 May 2026 14:31 UTC](https://forum.intervals.icu/t/graphing-data-at-10-hz/95981/8 "2026-05-22T14:31:02Z")

</div>

I’ve never studied FIT files from HRM. But I have studied FIT files from Garmin watches that contain HRV. A separate record type called `hrv` is used there. It is different from what is available to developers.

In general, I have a working method for saving data more often than once per second without loss. It is suitable for HRV. I just thought @Roger_W_Schmitz knew an easier way.

---

<div class="post-metadata">

**Author:** ![Roger\_W\_Schmitz](https://forum.intervals.icu/user_avatar/forum.intervals.icu/roger_w_schmitz/32/61961_2.png) [@Roger\_W\_Schmitz](https://forum.intervals.icu/u/Roger_W_Schmitz)\
**Post date:** [22 May 2026 14:59 UTC](https://forum.intervals.icu/t/graphing-data-at-10-hz/95981/9 "2026-05-22T14:59:20Z")

</div>

Oh I misunderstood the question. We do have a way of stuffing higher frequency data into the .fit file from Connect IQ. We put the timestamp and the sensor data into an array. See the Fit Contributor code below.

Then we have a script in an Activity Chart in Intervals.icu that upacks the arrays. That script is pasted below the Fit Contributor code.

```auto
using Toybox.Application as App;
using Toybox.WatchUi as Ui;
using Toybox.System as Sys;
using Toybox.FitContributor as Fit;
import Toybox.Application.Storage;

const TIME_FIELD_ID = 0;
const SMO2_FIELD_ID = 1;
const THB_FIELD_ID = 2;
const DEVICE_INFO_ID = 3;
const TAGS_FIELD_ID = 4;

// format and units for displaying SmO2 data
const G_currentHemoPercentUnits = Ui.loadResource(Rez.Strings.smo2_units);
const G_currentHemoPercentLabel = Ui.loadResource(Rez.Strings.smo2_label);

// format and units for displaying THb data
const G_totalHemoConcentrationUnits = Ui.loadResource(Rez.Strings.thb_units);
const G_totalHemoConcentrationLabel = Ui.loadResource(Rez.Strings.thb_label);
const G_AppSensor = Ui.loadResource(Rez.Strings.AppSensor);

class MO2FitContributor {

    // FIT Contributions variables
    hidden var mTime = null;
    hidden var mSmO2 = null;
    hidden var mThb = null;
    hidden var mDeviceInfo = null;
    hidden var mTags = null;
    hidden var mArraySize = 21;
    hidden var tagFieldName = "MoxyTags"; // Field name recognized by Intervals.icu
    hidden var tags = "MoxyTenHz"; // Multiple tags are space delimited
    hidden var tagLength = tags.length() + 1;

    // Constructor
    function initialize(activity) {
		var location = Storage.getValue("SensorLx").toNumber();
		if (location > Glocations.size()-1 or location < 0 or location == null) {
			location = Glocations.size()-1;
		}
        var label = " Sensor " + Storage.getValue("SensorId").toString() + " on " + Ui.loadResource(Glocations[location]);
        mTime = activity.createField(G_AppSensor + " " + "Time" + label, TIME_FIELD_ID, Fit.DATA_TYPE_UINT32, { :count=>mArraySize, :mesgType=>Fit.MESG_TYPE_RECORD, :units=>"msec" });
        mSmO2 = activity.createField(G_AppSensor + " " + G_currentHemoPercentLabel + label, SMO2_FIELD_ID, Fit.DATA_TYPE_FLOAT, { :count=>mArraySize, :mesgType=>Fit.MESG_TYPE_RECORD, :units=>G_currentHemoPercentUnits });
        mThb = activity.createField(G_AppSensor + " " + G_totalHemoConcentrationLabel + label, THB_FIELD_ID, Fit.DATA_TYPE_FLOAT, { :count=>mArraySize, :mesgType=>Fit.MESG_TYPE_RECORD, :units=>G_totalHemoConcentrationUnits });
		mDeviceInfo = activity.createField("CIQ_device_info", DEVICE_INFO_ID, Fit.DATA_TYPE_UINT8, { :count=>8, :mesgType=>Fit.MESG_TYPE_SESSION });
        mTags = activity.createField(tagFieldName, TAGS_FIELD_ID, FitContributor.DATA_TYPE_STRING, { :count=>tagLength, :mesgType=>FitContributor.MESG_TYPE_SESSION });
        mSmO2.setData(0);
        mThb.setData(0);
        mTags.setData(tags);
    }

    function compute(sensor) {
        if( sensor != null ) {
            var time = new[sensor.data.iSize];
            var smo2 = new[sensor.data.iSize];
            var thb = new[sensor.data.iSize];
            var j;
            var buffer_end = false;
            for (var i = 0; i < sensor.data.iSize; i++){
                j = (i + sensor.data.iTail) % (sensor.data.iSize + 1);
                if (j == sensor.data.iHead ) {
                    buffer_end = true;
                }
                if (!buffer_end) {
                    time[i] = sensor.data.timeBuffer[j];
                    smo2[i] = sensor.data.smo2Buffer[j];
                    thb[i] = sensor.data.thbBuffer[j];

                }
                else {
                    time[i] = 0;
                    smo2[i] = 0;
                    thb[i] = 0;
                }
            }
			mTime.setData(time);
            mSmO2.setData(smo2);
            mThb.setData(thb);
        }
    }
    
    function setDeviceInfo(sensor_position, serial_number, manufacturer) {
        mDeviceInfo.setData([31,sensor_position,(serial_number),(serial_number >> 8),(serial_number >> 16),(serial_number >> 24),(manufacturer),(manufacturer >> 8)]);
    }

}

```

{

```
// version 0.1.0 April 29, 2025

const activity = icu.activity

const itags = activity.tags || \[\];

if (itags.includes('MoxyTenHz')) {

  let Time_array = icu.streams.TenHzTime;

  let SmO2_array = icu.streams.TenHzSmO2;

  let THb_array = icu.streams.TenHzTHb;

  let time = \[\];

  let smo2 = \[\];

  let maxtime = 0;

  for (let i = 0; i < Time_array.length; i++) {

    const timerow = Time_array\[i\];

    if (timerow != null) {

        const smo2row = SmO2_array\[i\];

        for (let j = 0; j < timerow.length; j++) {

            if (timerow\[j\] / 1000 > maxtime) {

                maxtime = timerow\[j\] / 1000;

                time.push(timerow\[j\] / 1000);

                smo2.push(smo2row\[j\]);

                console.log(timerow\[j\] + "," + smo2row\[j\].toFixed(1));

            }

        }

    }

  }

  let data = \[

  { // Plot the segmented fit as lines

      x: time,

      y: smo2,

      mode: 'lines',

      type: 'scatter',

      name: 'Fitted Lines',

      marker: {

        color: '#202020',

        opacity: 1

      }

  },

  \]

  

      let layout = {

      title: {

          text: "SmO2 Graph",

          font: {

          size: 36,

          color: '#000000'

          }

      },

      xaxis: {

          title: 'Time (Seconds)',

          font: {

          size: 24,

          color: '#828282'

          }

      },

      yaxis: {

          title: 'SmO2 (%)',

          font: {

          size: 24,

          color: '#828282'

          }

      },

      images: \[

      {

          x: 0.9,

          y: 1.05,

          sizex: 0.15,

          sizey: 0.15,

          source: "https://www.moxymonitor.com/wp-content/uploads/Moxy-tagline-logo.png",

          xanchor: "right",

          xref: "paper",

          yanchor: "bottom",

          yref: "paper"

      }

      \],

      margin: {

          l: 40,

          r: 20,

          t: 75,

          b: 40

      },

      }

  

      chart = { data, layout }

  }

}

```

---

<div class="post-metadata">

**Author:** ![AlexxIT](https://forum.intervals.icu/letter_avatar_proxy/v4/letter/a/e9bcb4/32.png) [@AlexxIT](https://forum.intervals.icu/u/AlexxIT)\
**Post date:** [24 May 2026 18:43 UTC](https://forum.intervals.icu/t/graphing-data-at-10-hz/95981/10 "2026-05-24T18:43:10Z")

</div>

> [@Roger\_W\_Schmitz](#):
>
> We put the timestamp and the sensor data into an array. See the Fit Contributor code below.

Thanks! How often do you call the `compute` function? You are probably calling it from the DataField `compute` function. After calling, you probably clear the array. During my tests, there was a problem with the race condition. Clearing the array and receiving data from the sensor could occur simultaneously. And the program was losing data. Garmin does not have locks like other languages. Perhaps in the case of SmO2, this was unnoticeable. But in the case of HRV, it’s very critical.

---

<div class="post-metadata">

**Author:** ![Roger\_W\_Schmitz](https://forum.intervals.icu/user_avatar/forum.intervals.icu/roger_w_schmitz/32/61961_2.png) [@Roger\_W\_Schmitz](https://forum.intervals.icu/u/Roger_W_Schmitz)\
**Post date:** [24 May 2026 19:04 UTC](https://forum.intervals.icu/t/graphing-data-at-10-hz/95981/11 "2026-05-24T19:04:20Z")

</div>

> [@AlexxIT](#):
>
> often

It looks like I’m calling compute once per second. It’s been a while since I worked on this, but I recall that I had to do something like writing 2 seconds worth of data during every write to overcome the race condition. The data is collected at 10.24 Hz and iSize is set to 21. It’s horribly inefficient, but I couldn’t come up with another way to deal with it.

The intervals script de-duplicates the data when it unpacks it.

Roger

---

<div class="post-metadata">

**Author:** ![AlexxIT](https://forum.intervals.icu/letter_avatar_proxy/v4/letter/a/e9bcb4/32.png) [@AlexxIT](https://forum.intervals.icu/u/AlexxIT)\
**Post date:** [25 May 2026 07:14 UTC](https://forum.intervals.icu/t/graphing-data-at-10-hz/95981/12 "2026-05-25T07:14:09Z")

</div>

> [@Roger\_W\_Schmitz](#):
>
> but I recall that I had to do something like writing 2 seconds worth of data during every write to overcome the race condition

Yes, this should really work.

In my case, I did it differently. I see that you used a circular buffer in the DataField and parsed it when writing to the FIT file. I wrote the circular buffer into a FIT file and parsed it when reading from it. This way we will definitely not get to the race. You just need to additionally record, along with the buffer, where its tail is pointing.
