Conversion of float to int16
35 次查看(过去 30 天)
显示 更早的评论
Hi everyone
I have ECG data in float, and I would like to convert it into int16 to be used by the manually created toolbox. To convert float into int16, I multiplied data with 2^15 and cast it. However, the output of the toolbox is not the desired output. So I tried to analyze the previous ECG data and how it was converted to int16 format(2 bytes), yet I did not understand how data_float is converted into data_int16(both mat files are attached). Any suggestions would be highly appreciated.
Thank you.
2 个评论
Jan
2023-3-12
What is the corresponding code in "the manually created toolbox"? Profer to post the code instead of paraphrasing its intention.
回答(2 个)
Walter Roberson
2023-3-12
s1 = load('data_float.mat');
data_float = s1.data_float;
s2 = load('data_int16.mat');
data_int16 = s2.data_int16;
A = [data_float(:), ones(numel(data_float),1)];
b = double(data_int16(:));
coeffs = A\b
projected = coeffs(1) .* data_float(:) + coeffs(2);
difference = projected - b;
subplot(4,1,1); plot(data_float); title('data\_float');
subplot(4,1,2); plot(data_int16); title('data\_int16');
subplot(4,1,3); plot(data_int16); hold on; plot(projected); hold off; legend({'int16', 'projected'});
subplot(4,1,4); plot(difference); title('difference projected minus actual')
If there were a linear relationship between the float and int16 then it would be captured perfectly (to within round-off) by the projected data. But you can see that the difference between projected and actual starts low and ends high. This tells us that some kind of trend was removed.
Jan
2023-3-12
The signals are not related by a linear transformation:
The signals look similar, but the int16 version has a downwards trend at the end and the peak heights are not equivalent. Maybe a filter was applies also?
Instead of guessing the applied transformation, it would be reliable to look in the original code or to ask the author.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Single-Rate Filters 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!