openmovementproject / openmovement

Open Movement devices are miniature, embeddable, open source sensors developed at Newcastle University, UK. The source code for the firmware and software is available under a BSD 2-clause license, and the hardware (PCB designs, layouts and schematics), enclosure designs and documentation are available under a Creative Commons 3.0 BY Attribution License.
https://openmovement.dev
146 stars 76 forks source link

AX3_readFile with unpacked data #30

Closed TheTS closed 3 years ago

TheTS commented 5 years ago

Hi Daniel

Is it possible to edit AX3_readFile so it is compatible with unpacked data?

I see some code already to check for samples per packet. Probably just need some edits to parseValueBlockML to handle cases where samplesPerPacket = 80?

Cheers

Tom

EDIT: I think this should be an easy solution:

Instead of storing the acc data in a temp file prior to unpacking, you could just save it into the data struct directly:

if samplesPerPacket == 120,
    ACC_tmp((i-1)*samplesPerPacket+1:i*samplesPerPacket) = fread(fid, samplesPerPacket, 'uint32',0,'ieee-le');
else
    data.ACC((i-1)*samplesPerPacket+1:i*samplesPerPacket,2:4) = reshape(fread(fid, samplesPerPacket*3, 'int16').', [3, samplesPerPacket]).' / 256;
end

Need to skip the next block too, where the unpacking happens:

if samplesPerPacket == 120,
    if options.modality(1),
        % decode values for accelerometer

        if options.verbose > 0,
            fprintf('parsing samples\n');
        end

        % calls external c-code to unpack values (for speed pass on full
        % block instead of loop)

        if options.useC
            data.ACC(:,2:4) = parseValueBlock(ACC_tmp)' / 256;
        else
            data.ACC(:,2:4) = double(parseValueBlockML(ACC_tmp)) / 256;
        end

        clear ACC_tmp; % clear some memory
    end
end

And probably avoid ACC_tmp being initialized:

if samplesPerPacket == 120,
    ACC_tmp = zeros(size(validIds,1)*samplesPerPacket,1,'uint32');
end
danielgjackson commented 3 years ago

[Apologies for the very delayed resolution of this issue.]

There is (now) an alternative reader which works with unpacked data (and also AX6 data, including gyroscope axes): CWA_readFile.m