Filter löschen
Filter löschen

write fixed point data via fwrite to tcp

2 Ansichten (letzte 30 Tage)
Tom DeLonge
Tom DeLonge am 14 Mär. 2019
Beantwortet: Tom DeLonge am 26 Mär. 2019
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 Kommentar
Tom DeLonge
Tom DeLonge am 14 Mär. 2019
Bearbeitet: Tom DeLonge am 14 Mär. 2019
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?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Tom DeLonge
Tom DeLonge am 26 Mär. 2019
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.

Weitere Antworten (0)

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by