sampling rate Metabase Motion R not consistent.

Hi

I have tried to run the accelerometer sensor data acquisition with +-4 , 400 HZ its not consist sample rate between two records
Time x y z. delta (Time difference )
1.60553E+12 -0.18859863 0.16674805 -0.954834 1
1.60553E+12 -0.19165039 0.1685791 -0.96203613 3
1.60553E+12 -0.19091797 0.16564941 -0.9625244 3
1.60553E+12 -0.1928711 0.16369629 -0.9609375 3
1.60553E+12 -0.1940918 0.16687012 -0.9592285 1
1.60553E+12 -0.19335938 0.16442871 -0.9605713 3
1.60553E+12 -0.19616699 0.16760254 -0.9593506 3
1.60553E+12 -0.19128418 0.16699219 -0.95996094 2
1.60553E+12 -0.19165039 0.16320801 -0.9602051 3
1.60553E+12 -0.19274902 0.16540527 -0.96313477 3
1.60553E+12 -0.18981934 0.16052246 -0.9604492 2
1.60553E+12 -0.19189453 0.16687012 -0.96118164 2
1.60553E+12 -0.18798828 0.16967773 -0.9595947 3
1.60553E+12 -0.19348145 0.17004395 -0.9602051 3
1.60553E+12 -0.1920166 0.16955566 -0.9559326 1
1.60553E+12 -0.18859863 0.16467285 -0.9625244 3
1.60553E+12 -0.18823242 0.16882324 -0.96435547 3
1.60553E+12 -0.19274902 0.16809082 -0.95996094 2
1.60553E+12 -0.19299316 0.16125488 -0.9626465 3
1.60553E+12 -0.19494629 0.1665039 -0.9622803 2
1.60553E+12 -0.19140625 0.16967773 -0.954834 3
1.60553E+12 -0.19372559 0.1685791 -0.9604492 2
1.60553E+12 -0.19641113 0.16638184 -0.96325684 3
1.60553E+12 -0.19299316 0.16601562 -0.9572754 3

How can achieve the consistent accelerometer sensor data acquisition I have tested with Metabase IOS app / Test app same results observed .

Can you please let me know what is best configuration to achieve best sampling rate

Appreciated your response Thanks

Comments

  •  auto signal = dynamic_cast<MblMwDataSignal*>(it->second);
        bool handled= false;
        int64_t epoch = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
    
        MblMwDataProcessor* processor = dynamic_cast<MblMwDataProcessor*>(signal);
    
    
    
    int64_t now = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
        for(uint8_t i= 2; i < len; i+= CARTESIAN_FLOAT_SIZE) {
            MblMwData* data = data_response_converters.at(signal->interpreter)(false, signal, response + i, len - i);
            data->epoch= now;
    

    As I learned from metawearboard.cpp it seems epoch is based on system_clock and time_since_epoch() count.
    how to get this value consistent between the two samples. below is current settings kept on the mobile app side

            mbl_mw_acc_bosch_set_range(device.board, MBL_MW_ACC_BOSCH_RANGE_4G)
                mbl_mw_acc_set_odr(device.board, Float(400))
                mbl_mw_acc_bosch_write_acceleration_config(device.board)
    

    Please let me know what are excepted configurations to get the epoch time.

    Is the epoch is original time of the sensor collected the accelerometer data?

  • edited December 2020

    Epoch time is the time at which the computer gets the sensor data. So that's why you see some minor changes.

    The sensor is sampling correctly so the deltas are correct but the epochs granularity won't be because there are minor delays from the BLE and side processing by the time the "computer" gets the data.

    This is just real life...real data is not perfect. That's why we invented post processing.

  • Hi Laura

            mbl_mw_acc_bosch_set_range(device.board, MBL_MW_ACC_BOSCH_RANGE_16G)
            mbl_mw_acc_set_odr(device.board, Float(800))
            mbl_mw_acc_bosch_write_acceleration_config(device.board)
    

    What is the sampling frequency? I understand that each “delta t” is not consistent (0, 1, 2, 3) but the overall frequency seems to be around 1250Hz (second sensor 1239Hz). Didn’t we set 800Hz (or 1600Hz). See the first screenshot below.

    please suggest how to achieve desired frequency

  • First, you are not setting the ODR correctly; you need to use hard coded params: MBL_MW_ACC_BOSCH_RANGE_4G
    Second, you need to make sure that if you set it at 800z, that you are logging and not streaming.

  • HI Laura

    I have used the example MetaWearApiTest and tested with various combination none of those are producing the desired frequency which we set

    is the frequency which we set considered in firmware though mbl_mw_acc_set_odr or any other method available ?

  • Furthermore, I am using a logging mechanism not steaming below is code which used

    func startLogging(selectedFrequencyValue:Float, SelectedScale:Int) {
    guard let device = device else {
    return
    }
    device.connectAndSetup().continueWith(.mainThread) { t in

                switch SelectedScale {
                case 0:
                    mbl_mw_acc_bosch_set_range(device.board, MBL_MW_ACC_BOSCH_RANGE_2G)
                case 1:
                    mbl_mw_acc_bosch_set_range(device.board, MBL_MW_ACC_BOSCH_RANGE_4G)
                case 2:
                    mbl_mw_acc_bosch_set_range(device.board, MBL_MW_ACC_BOSCH_RANGE_8G)
                case 3:
                    mbl_mw_acc_bosch_set_range(device.board, MBL_MW_ACC_BOSCH_RANGE_16G)
                default:
                    fatalError("Unexpected accelerometerBMI160Scale value")
                }
                mbl_mw_acc_set_odr(device.board, selectedFrequencyValue)
                mbl_mw_acc_bosch_write_acceleration_config(device.board)
    
            print("selectedFrequencyValue",selectedFrequencyValue)
            print("selectedFrequencyValue",SelectedScale)
            //start device
            let signal = mbl_mw_acc_bosch_get_acceleration_data_signal(device.board)!
                        mbl_mw_datasignal_log(signal, bridge(obj: self)) { (context, logger) in
                            let _self: DeviceObject = bridge(ptr: context!)
                            let cString = mbl_mw_logger_generate_identifier(logger)!
                            let identifier = String(cString: cString)
                            _self.loggers[identifier] = logger!
                        }
            mbl_mw_logging_start(device.board, 0)
            mbl_mw_acc_enable_acceleration_sampling(device.board)
            mbl_mw_acc_start(device.board)
            self.isCollectingStarted = true
            self.delegate?.startLoggingCaled()
    
        }
    }
    
    func stopLogging() {
        guard let device = device else {
            return
        }
        device.connectAndSetup().continueWith(.mainThread) { t in
            mbl_mw_acc_stop(device.board)
            mbl_mw_acc_disable_acceleration_sampling(device.board)
            guard let logger = self.loggers.removeValue(forKey: "acceleration") else {
               print("acceleration logger not found")
                self.delegate?.hideHUD(device: device)
                self.logCleanup { error in
    
                    }
    
                return
            }
            //self.accelerometerBMI160Data.removeAll()
            mbl_mw_logger_subscribe(logger, bridge(obj: self)) { (context, obj) in
                let acceleration: MblMwCartesianFloat = obj!.pointee.valueAs()
                let _self: DeviceObject = bridge(ptr: context!)
                //here need to check if device. mac has some data will append but currently facing an error
                _self.accelerometerBMI160Data.append((obj!.pointee.epoch, acceleration))
    
            }
    
            var handlers = MblMwLogDownloadHandler()
            handlers.context = bridgeRetained(obj: self)
            handlers.received_progress_update = { (context, remainingEntries, totalEntries) in
                let _self: DeviceObject = bridge(ptr: context!)
                let progress = Double(totalEntries - remainingEntries) / Double(totalEntries)
                DispatchQueue.main.async {
                    print(progress)
                    if progress == 1.0 {
                        _self.isDownloaded = true
    
                        var accelerometerData = Data()
                        for dataElement in _self.accelerometerBMI160Data {
                            accelerometerData.append("\(dataElement.0),\(dataElement.1.x),\(dataElement.1.y),\(dataElement.1.z)\n".data(using: String.Encoding.utf8)!)
                        }
                        _self.save(accelerometerData)
    
                    }
    
                    if remainingEntries == 0 {
                        _self.logCleanup { error in
    
                            }
                        }
                    }
    
            }
    
            mbl_mw_logging_download(device.board, 100, &handlers)
        }
    }
    
Sign In or Register to comment.