write fixed point data via fwrite to tcp

2 ビュー (過去 30 日間)
Tom DeLonge
Tom DeLonge 2019 年 3 月 14 日
回答済み: Tom DeLonge 2019 年 3 月 26 日
I have a mx7 array of doubles which I would like to transmit via tcpip using fwrite. However, I would like to transmit each column in it's own format, e.g.
int16 - fixed point - fixed point - double - int16 - fixed point - fixed point
The fixed points are 64bit long (16 + 48).
Now, how can I do this using fwrite? I would like to send the whole array at once and not each row/value on it's own.
Also, I should note that m can be rather large (on the order of 50k)... Can anyone suggest a solution?
  1 件のコメント
Tom DeLonge
Tom DeLonge 2019 年 3 月 14 日
編集済み: Tom DeLonge 2019 年 3 月 14 日
my idea so far was to
  1. rearrange the columns a bit,
  2. typecast the whole thing down to a mx11 single array,
  3. transmit via fwrite as 'single'
the only problem with this approach is that I cannot use typecast on fixed point objects in matlab. I would have to write my own conversion routine for that I guess?

サインインしてコメントする。

採用された回答

Tom DeLonge
Tom DeLonge 2019 年 3 月 26 日
Just wanted to answer my own question. I used my own routine to convert a double number to a fixed point, which is then being sent in disguise as a uint64. For a big endian receiver and a 64 bit fixed-point number with a word length of 16 bits, the code is simply
fxpInt64 = swapbytes(int64(dblIn*2^48));
fxpInt64 = swapbytes(typecast(fxpInt64(:),'uint16'));
Then, as can be seen, I in turn typecasted everything to uint16, which was sort of the largest common denominator for my classes.This is then being sent using fwrite and uint16 in it's class argument.

その他の回答 (0 件)

製品


リリース

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by