LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

assign a binary code to a number

Thanks for reading this......This is what  i want to do, let's suppose that i have this number 0.8125 and i want to relate it with a 4 bit-binary code , for example 0001...
any advice!!! thanx in advance!!!
0 Kudos
Message 1 of 12
(4,300 Views)

Riot, are you saying you want to

1) see the string of 0's/1's associated with 0.8125, or

2) make a new reference system where (for example) 0010=

0*.8125^3 + 0*.8125^2 + 1*.8125^1 + 0*.8125^0

David C
Applications Engineering
0 Kudos
Message 2 of 12
(4,282 Views)
before anything else thanx for taking time to read this.
 
ok ,let me explain it better, i just defined 16 quantizing levels, according to pcm technique  i must assign a code for every sample  that lies in the range of  a specific quantized level .
 
Lets supposed one of my samples is within this range of values 0.750-8.75 ;that would  be  level 14in my case , and i must define a code for this level(for example 1110)  in order to associate my sample with this level....
 
i've been studying this carefully and i think  i should represent  this code through a waveform , that is, a square waveform with the respectives high and low levels (representing the 0's and 1's), not sure if i can use an Array for storing this waveform...i should be able to represent 2^4 different combinations of  0's and 1's ..........i wrote this because am gonna have to modulate each of this pulses( the code for each quantized level) using a hihg frequency carrier (  Am modulation technique)....
 
i defined the levels like this
 
L0----------------  0000       
L1----------------  0001
L2....................  0010
.. .
...
L15..................  1111
 
so on....
 
i attached a graph for a better understanding.....
Thanx...
0 Kudos
Message 3 of 12
(4,264 Views)
Riot,
 
I'm afraid I am still not positive I know what you want.  It sounds like you basically want to do analog->digital conversion and store the result in binary form.  I understand your square waveform, with high as 1 and low as 0 or vice versa.  What I don't understand is whether you need to be able to determine which level a certain sample is in or whether you have that figured out and just need to represent the case in 0/1 form.  I also wasn't sure if your original 0.8125 question tied to your .750-8.75 example.
 
For the second case first, the answer is yes, you can make an array of 0/1.  The simplest way would be to make it a Boolean array.  Place an array on the front panel or an array constant on the block diagram and then put something of the data type you want inside -- in this case, put a Boolean inside.  The array will adapt to the data type.  All you need is a 1-D array of 4 elements to represent your case.
 
If you need to figure out what level it is in, I would recommend using a state machine.  Go to File>>New... and use VI>>From Template>>Frameworks>>Design Patterns>>Standard State Machine.  You think of it as an "elseif" test that's compact and easy to use.  Try the In Range and Coerce function (Programming>>Comparison>>In Range and Coerce) for the tests.
 
General comments: in LabVIEW, a waveform is comprised of an array of data points, so manipulating data in array form makes sense.  Also, if you are doing something with an analog signal, you can use the built-in signal generator (Programming>>Waveform>>Analog Waveform>>Waveform Generation).  LabVIEW has pretty extensive built-in help, so remember you can search both Help>>Find Examples and general text help.
 
Hopefully that will get you started.
 
 
David C
Applications Engineering
0 Kudos
Message 4 of 12
(4,254 Views)

Hi,  it’s me again!!!

Ok , i’ve been asked to create a program (using Labview, of course) that tries to simulate a pcm- am modulation. What I have to do is work wih a  .wav file ( I already did this ,and acquired 3 seg) .

 

I defined 16 levels ( my quantizing levels). When I acquired this 3seg ( now in .wav format) I noticed that the upper and lower limits were 1 and -1 ,correspondingly. I read this from the wave form graph.

 

Every level has a width of  0.125( I calculated this  using a formula, since I’ll be using  just four bits for representing each of the quantizing levels. Width=2/(2^4)=0.125   ).

 

Maybe doing this just makes no sense( since Labview already sampled the 3 voice-second and saved it as a wav file) am doing this just for academical purposes, as a final project for  my DPS course  .

 

In this program I tried to implement the ‘In Range and Coerce’ function that you previously recommended me  (great tip!) and i also used a Boolean Array for representing (coding) each of the 16  quantized levels.

 

I decided to use just 4 bits, the idea is that every time that a sample lies within a particular  quantized level this sample will be represented through the code I defined ( sample 0.624 lies in  level 12 and the code for this level is 1100;  I write this just as an example) so from now on the sample of magnitude 0.624 would be represented by 1100

 

 

 

 

Ok this is for the pcm part……For the AM modulation part I need to multiply my coded samples with a sine wave  ,that would  be used as  the Carrier( just for simulating we are  sending the data  to a far place, where the signal will be demodulated  and ,of course, decoded so finally we get the original signal, that would be my 3 voice second).

 

That’s why ,I think, I should convert the Boolean array into a 0’s and 1’s array,  (to an array of numbers) since, I think, you can not multiply an array of booleans  with an array of numbers!!

 

Ok basically, i am using the”Coerce “ function to activate the case structure so the array o Booleans be activated and then be converted into a 4 length array of 4 elements(containing the specific code for the particular quantized level)

 

…..The thing is that I should be able to save all this arrays every time that the coerce function detects that one of my samples lay in one of my quantized levels……..

 

lets say, for example, that 144 of my 96000 samples are between 0.5 and .625 so I should be able to keep record of this 144 samples but not with its magnitude  but represented now through the four digit code …and I just don’t know how to do it,

i need something like “An array of arrays” so I can make difference between the different samples, now represented through the 4 bit code  I defined …any ideas!!!!

 

Download All
0 Kudos
Message 5 of 12
(4,208 Views)
Riot, see attached code.  It's a sample of what you can do in your VI.
 
  1. For every coerce, put a Select after the T/F.  If T (i.e. if the point coming in lies in that range) output the level number.  If F, output 0.
  2. Sum all of these together.  Since only one of your cases should have been true, the summation block should only have one non-zero input (or, if it is level 0, every input will be zero).  It's like a switch, but saves you doing stacked T/F switches.
  3. Send the sum to a case selector that has a case for every level (16 cases).
  4. For each case, have the 0/1 representation you want.  You can make this a constant array of 0/1 or just take the Booleans you already have and translate them like you had already done for the first array.
  5. Output to the index on the For loop.

Another option is manipulate your array index output data into an integer (multiply by 1000, for example) and input into a single case structure.  Case structures can accept ranges, but not decimals.  Then set a range for -875..-749 (instead of your -0.875..-0.75) and have 16 cases, each with your array output linked to the index as described above.  This is also in the attached VI.

Final result should be an array of 4 col. and n rows, where n is the number of samples you took.  The index will be in time order, too.  As long as you multiply your wave by this index at the same rate at which you sampled, you should be fine.

 

David C
Applications Engineering
0 Kudos
Message 6 of 12
(4,178 Views)

Hi Riot,

I made some changes to your program to handle the data as a string converted later to a bipolar pulse train ready to be modulated. This example is simplified to a 2 bit quantization.

I hope it might be useful

0 Kudos
Message 7 of 12
(4,169 Views)

Riot,

I am not sure you need to use the in range and coerce look-up tables at all.  Take a look at the attached VI.  I take a sample waveform find its min and max to compute the quantum.  I then simply use the Quotient & remainder function to get the quotient.  So I have converted the value to a level.  By then converting it to a U8 you basically have your levels in binary.  In this case the lowest level is 0, next is 1 (0001), then 2 (0010) etc.  If you need the lowest level to not =0 then a lookup table or some simple subtraction may fix the levels.

I then multiply it by a sine wave like you had asked and I believe that shows the signal you where hoping for.  Notice I also plotted it on a digital graph so you can look at that as well.

0 Kudos
Message 8 of 12
(4,146 Views)
thanx  fcamacho for reading this , i am interested in your solution too , but i couldn't open the vi ,since i am using LabView 8.Can you sasend it for  for 8 version please...Thanx!!! 
0 Kudos
Message 9 of 12
(4,145 Views)
Hi Evan, can you save it for Labview 8 please...,Thanx!!!
0 Kudos
Message 10 of 12
(4,137 Views)