MATLAB: Same-length, same-type vectors take up different amounts of space as .mat files

31 views Asked by At

I have neural recordings of two resolutions, one sampled at 2048Hz and the other at 32768Hz. I implemented an analysis pipeline for the 2048Hz recording that I want to apply to the other, higher-resolution recording.

The recordings were done in parallel in the same system, so everything about the data and their circumstances is qualitatively the same, except for the sampling rate. This is why I resample the 32768Hz recording down to 2048Hz before applying my pipeline, expecting it to work just the same. However, the resulting vector, while the same length as the original 2048Hz recording, ends up being saved as a much larger .mat file.

I resample the data using the resample function in MATLAB 2018a:

>> which resample.m
/usr/local/MATLAB/R2018a/toolbox/signal/signal/resample.m

I enter my 32768Hz signal with p, q = 1, 16.

There is no big issue with my pipeline yet, only this: The resampled signal has the expected number of samples, which is the same as that in the corresponding signal originally recorded at 2048Hz. All vectors are doubles. However, when I go to save it, it takes up much more space as a .mat file than the original 2048Hz recording:

save('original_32768Hz.mat', 'original_highSF', "-v7")
save('original_2048Hz.mat', 'original_lowSF', "-v7")
save('resampled_to_2048Hz.mat', 'resampled_lowSF', "-v7")

Results: Original 32768Hz recording re-saved as is: 385 MB

Original 2048Hz recording re-saved as is: 22.1 MB

Original 32768Hz recording resampled to 2048Hz and saved: 38.7 MB

This ~50% increase in size relative to the expected size is not replicated when I just straight-up trancate the original 32768Hz vector to the size of the 2048Hz vector and save that. In that case, it is the same size as the originally 2048Hz recording, as expected.

The issue also does not replicate if I simulate the recordings with similar lengths and "sampling rates" directly in MATLAB instead of loading the recordings from the file type used in the lab. I realize that this might make answering the question a lot harder, but maybe someone has a guess as to what might happen to the vectors in the course of resampling that makes a file containing a resampled vector much larger than a file containing a non-resampled vector of the exact same length.

0

There are 0 answers