Generating specific byte sequence in Simulink - matlab

I am trying to communicate with a camera in Simulink via the two blocks tcp/ip and receive/send.
Therefore I need to send the following specific 12 byte sequence (displayed in hex):
07:00:00:00:00:00:00:00:00:8c:01:00
I was trying to solve it with the simulink block "byte pack". I connected 12 constant-blocks with it and chose the decimal for each constant-block, that is corresponding to a byte of the 12 bytes, and changed the input data type to double. But it didnt work and I dont know what I've made wrong.
Any suggestions or other solutions to my problem?

Related

Audioworklets and pitch

I've recently started working with audioworklets and am trying to figure out how to determine the pitch(s) from the input. I found a simple algorithm to use for a script processor, but the input values are different than a script processor and doesn't work. Plus each input array is only 128 units. So, how can I determine pitch using an audioworklet? As a bonus question, how do the values relate to the actual audio going in?
If it worked with a ScriptProcessorNode, it will work in an AudioWorklet, but you'll have to buffer the data in the worklet because, as you noted, you only get 128 frames per call. The ScriptProcessor gets anywhere from 256 to 16384.
The values going to the worklet are the actual values that are produced from the graph connected to the input. These are exactly the same values that would go to the script processor, except you get them in chunks of 128.

Size of binary file after base64 encoding? Need explanation on the solution

So I'm studying for the upcoming exam, and there's this question: given a binary file with the size of 31 bytes what will its size be, after encoding it to base64?
The solution teacher gave us was (40 + 4) bytes as it needs to be a multiple of 4.
I'm not being able to come across this solution, and I have no idea how to solve this, so I was hoping somebody could help me figure this out.
Because base 64 encoding divide the input data in six bit block and one block use an ascii code.
If you have 31 byte in input you have 31*8/6 bit block to encode. As a rule of thumb every three byte in input you have 4 byte in output
If input data is not a multiple of six bit the base64 encoding fills the last block with 0 bit
In your example you have 42 block of six bit, with last filled with missing 0 bit.
Base 64 algorithm implementation filled the encoded data with '=' symbol in order to have of multiple of 4 as final result.

Transfer Value via UDP between Simulink/Labview

I'm working on a project that requires a value be passed in real-time between Matlab's Simulink and Labview on networked systems (currently running Matlab 2010b and Labview 7.0). I've been trying to do this with UDP Send/Receive functions in either program, however Labview only seems to deal in Strings with UDP/TCP-IP. Simulink only reads int/double values from UDP ports.
Is there a way for me to convert these values AFTER the read-in operation, or otherwise get around the type restriction? Any advice (or alternative ways to pass a value between the two programs) would really be appreciated. Unfortunate, due to hardware restrictions, I'm stuck with these program versions.
Thanks!
The TCP/UDP functions in LV use strings because it's a convenient way to represent an array of bytes, which is what a TCP stream basically is. You can take the data and convert it so that it's usable. Assuming Simulink encodes values the same way (simple binary for ints, IEEE754 representation for floats), then you can simply use the type cast or flatten to/unflatten from string functions to convert the data. You might need to change the order of the bytes to account for endianess.
You can look at the TCP examples in LV and the documentation on flattened data to understand more on how this works.
As a side point, UDP is lossy and is mainly suitable if you need to broadcast or get data quickly, like when streaming video. If the data is important, you should use TCP.

Simulink Convert Single to 4 Bytes

I want to convert a single to 4 bytes in order to send them by serial port.
for example 30:0x41 0xF0 0x00 0x00
I don't know if a Simulink block already exists or if I should create a matlab function for this aim.
There is a simulink block called "Extract Bits". This can extract any set of bits from the input. Your input need to be of integer type. You would need to use 4 such blocks to get the 4 bytes.
See documentation for the block at http://www.mathworks.com/help/simulink/slref/extractbits.html
For unpacking double or single data types you need "Byte Pack" block from Embedded Coder product. You can find documentation at http://www.mathworks.com/help/ecoder/ref/bytepack.html.

Serial communication with simulink

I'm trying to send and receive data through a serial port using simulink (matlab 7.1) and d-space. The values I want to send and receive are doubles. Unfortunately for me the send and receive blocks use uint8 values. My question is how can I convert doubles into an array of uint8 values and vice versa? Are there simulink blocks for this or should I use embedded matlab functions?
Use the aptly named Data Type Conversion block, which does just that.
EDIT following discussion in the comments
Regarding scaling, here's a snapshot of something I did a long time ago. It's using CAN rather than serial, but the principle is the same. Here, it's slightly easier in that the signals are always positive, so I don't have to worry about scaling a negative number. 65535 is the max value for a uint16, and I would do the reverse scaling on the receiving end. When converting to uint16 (or uint8 as in your case, it automatically rounds the value, and you can specify that behaviour in the block mask).
There are pack and unpack blocks in simulink, search for them in simulink library browser. You could need som additional product, not sure which.