LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Converting a double data type to a signed integer

    The attached VI reads analog data from a spreadsheet.  I would like to use a type cast to convert the double precision data into a signed 16 bit integer.  What constant should be wired to the "type" wire of the type cast for an I16.
0 Kudos
Message 1 of 14
(5,530 Views)
You don't need to use TypeCast in this instance. You can just use the conversion functions (Numeric -> Conversion palette):



To answer the question directly, right-click on the array element and select the Representation menu item. Select the representation you want.


Message Edited by smercurio_fc on 06-25-2008 10:52 AM

Message Edited by smercurio_fc on 06-25-2008 10:53 AM
0 Kudos
Message 2 of 14
(5,524 Views)
    I should have also included that it needs to be binary.
0 Kudos
Message 3 of 14
(5,520 Views)
That doesn't really mean anything. All numbers are stored in binary. Your VI is clearly not finished, but from what I can tell you just need to feed I16 values to the Snd Write Wave File function. Well, that conversion function will do that.

Also:
  • Does your spreadhseet only contain 3 rows? If so, the indexing out of each row and then rebuilding the array is not necessary. Simply wire the 2D array directly to the conversion function.
  • You are already auto-indexing the for-loop so you do not need to wire a 3 to the "N" terminal.
  • You can eliminate the need for the conversion alltogether by simply not using the stock Read From Spreadsheet File. Create a customized one that reads in the values as I16 directly. To do this:
  1. Change the polymorphic version of the Read From Spreadsheet File to "Integer".
  2. Double click the VI to open it.
  3. Save it under a new name. (Select "Save As...", then select "Open additional copy"). Make sure you save it in your own work directory. Do not save it in the LabVIEW directory!
  4. In this new VI switch to the block diagram.
  5. Change the datatype of the "type (empty)" control, the "all rows" indicator, and the "first row" indicator to I16. Save it.
  6. Replace the VI on your block diagram with this new VI. You will then get the data as I16 directly, with no need for conversion functions.
0 Kudos
Message 4 of 14
(5,498 Views)

Sorry, that makes no sense. Do you want to to use binary display format in your graph?

What I suspect is that the data in your spreadsheet file needs to be scaled and not just converted like you are doing. That's only because you have a %.6 format string. If you do have floating point numbers in the file, then what you have will not work at all.

0 Kudos
Message 5 of 14
(5,493 Views)
Good point, Dennis. Didn't think there might be scaling in the file.

To poster: Can you please post a sample of the data file that you're trying to read?
0 Kudos
Message 6 of 14
(5,486 Views)
       Attached is the data file and the vi that has been changed to following the procedure in Reply 4.  It still doesn't work, I suspect because the data file is in scientific notation.  
Download All
0 Kudos
Message 7 of 14
(5,473 Views)
The procedure I had outlined assumed you were dealing with integer values. Besides, you only did half of it. However, that's irrelevant since you don't have integer values. You have floating-point values. The notation doesn't matter as much as the dataype. As Dennis correctly surmised, this is probably scaled data. Does the name of your text file give an indication as to what these values mean? For instance, what does the value of -5.394458E-3 refer to? Where did this data come from?

Also, you are not indexing out the values correctly. Your data is in columns, but you are indexing out rows. You also still insist on using the TypeCast function when you have no need to do so.
0 Kudos
Message 8 of 14
(5,468 Views)
    The input data are time histories of three analog voltages recorded using Signal Express, expressed in scientific notation.  It appears that Signal Express only records scaled values
0 Kudos
Message 9 of 14
(5,447 Views)
Are these voltages the outputs from microphones? I graphed the data, and it looked like this:


Certainly looks like it might be sound. If you're just trying to write out a WAV file then you can try something simpler, like using the Sound File Write function, as shown in the attached example (LabVIEW 8.2). When I played back the WAV file I heard faint clicks. Is that what those are?


Message Edited by smercurio_fc on 06-25-2008 05:30 PM
Download All
0 Kudos
Message 10 of 14
(5,437 Views)