I am trying to convert an analog value to a digital value (8 bit A/D converter, input range 0-5V ).
I have used the formula (input*255/5) to convert to digital, then i have used digital to binary vi to convert this digital value to 8 bits.
The problem here is the data type mismatch between my output from the formula, which is a double data type and the input of the vi which is a digital data type, so how to solve this problem ? Thank you in advance
The digital data you mention is On/OFF. The example below illustrates the type of data that is entered and output from digital to binary.vi
On the left hand side is three samples of digital data in continuous signal format from three separate sources, (signal 0, signal 1, signal 2).
The first sample gives binary 2 (010). As you can see this would be not be of any use for a single signal.
If you still want to do the above, you could use DWDT Boolean Array to Digital as illustrated below:
Related
I have a file format called .ogpr (openGPR, a dead format used for Ground Radar data), I'm trying to read this file and convert it into a matrix using Matlab(R).
In the first part of file there is a JSON Header where are explained the characteristics of data acquisition (number of traces, position etc), and on the second part there are two different data blocks.
First block contains the 'real' GPR data and I know that they are formatted as:
Multibyte binary data are little-endian
Floating point binary data follow the IEEE 754 standard
Integer data follow the two’s complement encoding
I know also the total number of bytes and also the relative number of bytes for each single 'slice' (we have 512 samples * 10 channel * 3971 slices [x2 byte per sample]).
Furthermore: 'A Data Block of type Radar Volume stores a 3D array of radar Samples At the moment, each sample value is stored in a 16-bit signed integer. Each Sample value is in volts in the range [-20, 20].'
Second block contains geolocation infos.
I'd like to read and convert the Data Block from that codification but it ain't clear especially how many bytes break the data and how to convert them from that codification to number.
I tried to use this part of code:
bin_data = ogpr_data(48:(length(ogpr_data)-1),1);
writematrix(bin_data, 'bin_data.txt');
fileID = fopen('bin_data.txt', 'r', 'ieee-le');
format = 'uint16';
Data = fread(fileID, Inf, format);fclose(fileID)
Looks like your posted code is mixing text files and binary files. The writematrix( ) routine writes values as comma delimited text. Then you turn around and try to use fopen( ) and fread( ) to read this as a binary file in IEEE Little Endian format. These are two totally different things. You need to pick one format and use it consistently, either human readable comma delimited text files, or machine readable binary IEEE format files.
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?
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.
I am trying to build a DSP process in Matlab.
The ADC delivers uint16 data. This data should be filtered and processed. The filter works in the DSP with fixed point (fract16).
Should a transformation take place if I want to do work with the data Matlab? How to do it?
You can just treat the 16 bit unsigned fractional data as integers and then scale the data to floating point in the range 0.0..+1.0 prior to any processing. E.g.
data = data / 65535.0;
If the data is actually signed fractional (int16) then you would convert it to the range -1.0..+1.0 like this:
data = data / 32768.0;
I'm relatively new to Simulink and I am looking for a possibility to extract 1-3 specific bits from one byte.
As far as I know the input format (bin, dec, hex) of the constant is irrelevant for the following!? But how can I say that the constant "1234" is hex and not dec?
In my model I use the "Constant Block" as my source (will be parametrised by a MATLAB variable which comes from a m-file).
A further processing with the "Extract Bits Block" causes an error on incompatible data types.
Can someone help me to deal with this issue?
Greets, poeschlorn
You should probably do the conversion hex->dec in your .m initialization file and use this value in Simulink.
Maybe this is not the most elegant solution, but I converted my input to decimal and then created a BCD representation of it via OR and AND logic blocks for further use.
If you have the Communications Toolbox/Blockset then you can use the Integer to Bit Converter block to do a conversion to a vector of binary digits then just extract the "bits" that you want. The Bit to Integer Converter block will do the reverse transformation.
If you don't have the Communicatins Blockset then it wouldn't be hard to do a similar thing to this using a plain MATLAB Function block.