Changing sample quantity of raw data in XG24 Silabs

How can I increase the number of samples in the raw input inside the variable below?

static const float features[] = { }

I would like to create a kind of “local database”, where my input has 16 values and the microcontroller would test all these features, showing the result generated from “run_classifier( )”. I am not using a sensor, so I would like to emulate a sensor behaviour in this case.
For example, I would like to have this kind of entry:

static const float features[] = {
    // LABEL A
    1383.6400, 1380.6800, 1376.6900, 1375.4900, 1374.0100, 1373.7300, 1372.4500, 1370.8200, 1370.8500, 1370.8400, 1371.6800, 1373.7300, 1374.6255, 1383.6400, 1370.8200, 4.2495,

    // LABEL B
    299.8100, 497.9900, 686.2500, 844.8600, 821.4100, 818.4800, 664.6500, 460.3900, 256.3200, 52.4600, 20.4300, 497.9900, 493.0045, 844.8600, 20.4300, 302.6931,

    // LABEL C
    1467.0900, 1464.7800, 1464.5800, 1378.7000, 1036.0900, 191.5400, 63.6800, 181.5000, 181.5900, 514.5200, 122.8700, 514.5200, 733.3582, 1467.0900, 63.6800, 623.5187,

    //LABEL D
    12.0000, 13.0000, 13.0000, 11.0000, 11.0000, 13.0000, 12.0000, 12.0000, 11.0000, 12.0000, 11.0000, 12.0000, 11.9091, 13.0000, 11.0000, 0.8312
 }

I am using this firmware Edge Impulse Example: standalone inferencing as a base, and this variable is located in the /app.cpp

#include "edge-impulse-sdk/classifier/ei_run_classifier.h"
#include <cstdio>

// Raw features copied from test sample
static const float features[] = {
    // Copy raw features here (e.g. from the 'Model testing' page)
};

I tried to change the define in the metadata of this variable from my model generated in Edge Impulse

EI_CLASSIFIER_RAW_SAMPLE_COUNT

which set the sample count from 1 to 4 (as the example that I would like to try, previously mentioned), but it is not working.

#ifndef _EI_CLASSIFIER_MODEL_METADATA_H_
#define _EI_CLASSIFIER_MODEL_METADATA_H_

#include <stdint.h>
#include <stdbool.h>

#define EI_CLASSIFIER_NN_INPUT_FRAME_SIZE        16
#define EI_CLASSIFIER_RAW_SAMPLE_COUNT           1
#define EI_CLASSIFIER_RAW_SAMPLES_PER_FRAME      16
#define EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE       (EI_CLASSIFIER_RAW_SAMPLE_COUNT * EI_CLASSIFIER_RAW_SAMPLES_PER_FRAME)

For some reason the microcontroller is not reading more than 16 raw values and not moving to the next 16 values continuosly. Can somebody help me with that? :pray:

static const float features[] = { } holds the data for a single inference run by the Edge Impulse Classifier().

You need to have your code loop over features[] that is declared like:

static const float features[4][16] = { }

Hi @MMarcial ,

I changed the declaration of the variable and the loop to get the signal (get_signal_data( ) function). However, I get an error related to the type of my out_ptr variable, as below:

invalid types ‘float[size_t {aka unsigned int}]’ for array subscript

How can I change that? This variable is inside an struct that works as an wrapper for my features and there is not much comment on how this struct works… The functions void app_init(void) and void app_process_action(void) are the same from the template.

This is my code in app.c

#include "edge-impulse-sdk/classifier/ei_run_classifier.h"
#include <cstdio>
#include "sl_sleeptimer.h"


float features[2][16] = {
    // LABEL A
    1247.0000, 1247.0000, 1247.0000, 1236.0000, 1247.0000, 1224.0000, 1236.0000, 1224.0000, 1236.0000, 1224.0000, 1224.0000,1236.0000, 1235.6364, 1247.0000, 1224.0000, 10.2886,

    // LABEL B
    209.0000, 216.0000, 207.0000, 209.0000, 211.0000, 214.0000, 211.0000, 211.0000, 216.0000, 214.0000, 204.0000, 211.0000, 211.0909, 216.0000, 204.0000, 3.7538
};

static signal_t signal; // Wrapper for raw input buffer
static size_t buf_len;

// Callback: fill a section of the out_ptr buffer when requested
float get_signal_data(size_t offset, size_t length, float *out_ptr)
{
// Original part of the code
//    for (size_t i = 0; i < length; i++) {
//        out_ptr[i] = (features+ offset)[i];
//    }

// UPDATED ITERATION
  for (size_t i = 0; i < 2; i++) {
      for (size_t j = 0; j < 16; j++) {
          out_ptr[i][j] = features[i][j];
      }
  }

    return EIDSP_OK;
}


/***************************************************************************//**
 * Initialize application.
 ******************************************************************************/
void app_init(void)
{
    // Calculate the length of the buffer
    buf_len = sizeof(database) / sizeof(database[0]);

    // Assign callback function to fill buffer used for preprocessing/inference
    signal.total_length = buf_len;
    signal.get_data = &get_signal_data;


}

/***************************************************************************//**
 * App ticking function.
 ******************************************************************************/

void app_process_action(void)
{
    EI_IMPULSE_ERROR res;       // Return code from inference
    ei_impulse_result_t result; // Used to store inference output

    // Perform DSP pre-processing and inference
    res = run_classifier(&signal, &result, false);

    printf(" \r\n\r\n============= Classifier ================= \r\n");
    // Print return code and how long it took to perform inference
    printf(" run_classifier returned: %d\r\n", res);
    printf(" Timing: DSP %d ms, inference %d ms\r\n",
            result.timing.dsp, 
            result.timing.classification);

    // Print the prediction results (object detection)
    printf(" Predictions:\r\n");
    for (uint16_t i = 0; i < EI_CLASSIFIER_LABEL_COUNT; i++) {
        printf("   %s: ", ei_classifier_inferencing_categories[i]);
        printf("%.5f\r\n", result.classification[i].value);
    }

    printf(" \r\n\r\n=========================================== \r\n");
    sl_sleeptimer_delay_millisecond(2000);
}


out_ptr doesn’t have a 2nd dimension.

Change line
out_ptr[i][j] = features[i][j]; to
out_ptr[i] = features[i][j];