LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

switch for evaluation of splined function on Dynamic Data Type signal from acquisition card

Hej!

We tried this in my Lab for several hours, and trying out searching several things, but it wouldn't work.

 

Basically we want to implement this code in LabView:

switch(x){
 case x>= 2.00 && x< 2.05: 10^(390.757561*x^3 -154.200482*x^2 +25.072731*x  -5.000000); break;
 case x>= 2.05 && x< 2.10: 10^(390.757561*x^3  -95.586847*x^2 +12.583365*x  -4.083020); break;
 case x>= 2.10 && x< 2.20: 10^(117.140116*x^3  -36.973213*x^2  +5.955362*x  -3.643974); break;
 case x>= 2.20 && x< 2.40: 10^( -0.910451*x^3   -1.831178*x^2  +2.074922*x  -3.301030); break;
 case x>= 2.40 && x< 2.60: 10^(  5.043010*x^3   -2.377449*x^2  +1.233197*x  -2.966576); break;
 case x>= 2.60 && x< 2.80: 10^( -1.718243*x^3   +0.648357*x^2  +0.887379*x  -2.774691); break;
 case x>= 2.80 && x< 3.00: 10^( -0.430628*x^3   -0.382589*x^2  +0.940532*x  -2.585027); break;
 case x>= 3.00 && x< 3.20: 10^(  0.743793*x^3   -0.640965*x^2  +0.735821*x  -2.415669); break;
 case x>= 3.20 && x< 3.40: 10^(  2.399876*x^3   -0.194689*x^2  +0.568690*x  -2.288193); break;
 case x>= 3.40 && x< 3.60: 10^( -2.667102*x^3   +1.245236*x^2  +0.778800*x  -2.163043); break;
 case x>= 3.60 && x< 3.80: 10^( -0.654008*x^3   -0.355025*x^2  +0.956842*x  -1.978811); break;
 case x>= 3.80 && x< 4.00: 10^(  1.465216*x^3   -0.747430*x^2  +0.736351*x  -1.806875); break;
 case x>= 4.00 && x< 4.20: 10^( -0.956057*x^3   +0.131700*x^2  +0.613205*x  -1.677781); break;
 case x>= 4.20 && x< 4.40: 10^(  0.348149*x^3   -0.441935*x^2  +0.551158*x  -1.557520); break;
 case x>= 4.40 && x< 4.60: 10^(  0.920470*x^3   -0.233046*x^2  +0.416162*x  -1.462181); break;
 case x>= 4.60 && x< 4.80: 10^( -2.014023*x^3   +0.319236*x^2  +0.433400*x  -1.380907); break;
 case x>= 4.80 && x< 5.00: 10^(  5.196996*x^3   -0.889177*x^2  +0.319411*x  -1.297569); break;
 case x>= 5.00 && x< 5.20: 10^( -4.680888*x^3   +2.229020*x^2  +0.587380*x  -1.227678); break;
 case x>= 5.20 && x< 5.40: 10^(  0.252058*x^3   -0.579513*x^2  +0.917282*x  -1.058489); break;
 case x>= 5.40 && x< 5.60: 10^(  0.397350*x^3   -0.428278*x^2  +0.715724*x  -0.896196); break;
 case x>= 5.60 && x< 5.80: 10^(  0.560574*x^3   -0.189868*x^2  +0.592094*x  -0.767004); break;
 case x>= 5.80 && x< 6.00: 10^( -1.056144*x^3   +0.146477*x^2  +0.583416*x  -0.651695); break;
 case x>= 6.00 && x< 6.20: 10^(  0.838089*x^3   -0.487210*x^2  +0.515269*x  -0.537602); break;
 case x>= 6.20 && x< 6.40: 10^(  0.125506*x^3   +0.015644*x^2  +0.420956*x  -0.447332); break;
 case x>= 6.40 && x< 6.60: 10^( -0.481852*x^3   +0.090947*x^2  +0.442274*x  -0.361511); break;
 case x>= 6.60 && x< 6.80: 10^(  0.401641*x^3   -0.198164*x^2  +0.420831*x  -0.273273); break;
 case x>= 6.80 && x< 7.00: 10^( -0.131235*x^3   +0.042820*x^2  +0.389762*x  -0.193820); break;
 case x>= 7.00 && x< 7.20: 10^(  0.451841*x^3   -0.035921*x^2  +0.391142*x  -0.115205); break;
 case x>= 7.20 && x< 7.40: 10^( -0.487895*x^3   +0.235184*x^2  +0.430995*x  -0.034798); break;
 case x>= 7.40 && x< 7.60: 10^( -0.222357*x^3   -0.057553*x^2  +0.466521*x  +0.056905); break;
 case x>= 7.60 && x< 7.80: 10^( -0.218073*x^3   -0.190968*x^2  +0.416817*x  +0.146128); break;
 case x>= 7.80 && x< 8.00: 10^(  1.651675*x^3   -0.321811*x^2  +0.314261*x  +0.220108); break;
 case x>= 8.00 && x< 8.20: 10^( -1.279940*x^3   +0.669194*x^2  +0.383737*x  +0.283301); break;
 case x>= 8.20 && x< 8.40: 10^( -0.296071*x^3   -0.098770*x^2  +0.497822*x  +0.376577); break;
 case x>= 8.40 && x< 8.60: 10^(  0.248063*x^3   -0.276413*x^2  +0.422786*x  +0.469822); break;
 case x>= 8.60 && x< 8.80: 10^(  1.441795*x^3   -0.127575*x^2  +0.341988*x  +0.545307); break;
 case x>= 8.80 && x< 9.00: 10^( -1.254627*x^3   +0.737502*x^2  +0.463973*x  +0.620136); break;
 case x>= 9.00 && x< 9.20: 10^( -0.582728*x^3   -0.015274*x^2  +0.608419*x  +0.732394); break;
 case x>= 9.20 && x< 9.40: 10^(  5.704902*x^3   -0.364911*x^2  +0.532382*x  +0.848805); break;
 case x>= 9.40 && x< 9.50: 10^(-13.414892*x^3   +3.058030*x^2  +1.071005*x  +0.986324); break;
 case x>= 9.50 && x< 9.60: 10^( -8.833690*x^3   -0.966438*x^2  +1.280164*x  +1.110590); break;
 case x>= 9.60 && x< 9.70: 10^( 49.841085*x^3   -3.616545*x^2  +0.821866*x  +1.220108); break;
 case x>= 9.70 && x< 9.80: 10^(-58.507434*x^3  +11.335781*x^2  +1.593790*x  +1.315970); break;
 case x>= 9.80 && x< 9.90: 10^(122.109580*x^3   -6.216449*x^2  +2.105723*x  +1.530200); break;
 case x>= 9.90 && x< 9.95: 10^(442.546627*x^3  +30.416425*x^2  +4.525720*x  +1.800717); break;
 case x>= 9.95 && x<10.00: 10^(442.546627*x^3  +96.798419*x^2 +10.886463*x  +2.158362); break;
}

We tried a Function Node, but it would return that we need to give an array index at the # position in

switch(x)#{

We figured, that it would probably be necessary to replace ^ by ** and : by a linebreak, maybe the ; break; are also useless ... How is the correct syntax in a Function Node? Maybe a MathNode would be better?

 

The signal comes from the acquisition card, and is available as a Dynamic Data Type. This is then converted into an array. (We can't help, a converter is drawn automatically). Is this because the script doesn't like to work with DDT?


For other, more straight forward, formulae, we can use a simple "Formula" [like this] and this does the job. However, "Formula" only allows for single line formula, no switches.

 

Is there a way to do this with the script? Or even with drawing 47 boxes containing some comparison elements and maybe a case structure or so?
 

Any help will be warmly appreciated!

 

Best regards, Jonas

0 Kudos
Message 1 of 11
(2,912 Views)

This is easy...

 

One solution would be to convert x to an integer (if it's not already) and multiply by 100.  Wire the value to the conditional node on a case structure and set up the ranges in your text code. For example, the first three ranges would be.

 

200..204

205..209

210..219

 

If you need more resolution that 2 decimal paces, change the multiplier and scale the ranges appropriately.

 

OR (personally I like this one)...

 

You could create an array of your ranges (2.00. 2.05, 2.10, etc) and use the threshold function to determine which bin the input value falls into. With that bin number in hand you could do away with the case structure altogether and create a 1D array of clusters holding your 4 output values and simply index out the element you want and unbundle the values. The bin number would index into the array.

 

That's just a couple ideas that came to mind.

 

Mike...

 


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
Message 2 of 11
(2,902 Views)

Wow, many thanks mikeporter!

Your first idea is reallly smart!

We had a similar idea to your second one, but we couldn't figure out how to do it. And we still cannot.

Would you mind, sending us a small .vi file with the implementation?

 

The arrays are those here:

  390.7576 -154.2005   25.0727   -5.0000
  390.7576  -95.5868   12.5834   -4.0830
  117.1401  -36.9732    5.9554   -3.6440
   -0.9105   -1.8312    2.0749   -3.3010
    5.0430   -2.3774    1.2332   -2.9666
   -1.7182    0.6484    0.8874   -2.7747
   -0.4306   -0.3826    0.9405   -2.5850
    0.7438   -0.6410    0.7358   -2.4157
    2.3999   -0.1947    0.5687   -2.2882
   -2.6671    1.2452    0.7788   -2.1630
   -0.6540   -0.3550    0.9568   -1.9788
    1.4652   -0.7474    0.7364   -1.8069
   -0.9561    0.1317    0.6132   -1.6778
    0.3481   -0.4419    0.5512   -1.5575
    0.9205   -0.2330    0.4162   -1.4622
   -2.0140    0.3192    0.4334   -1.3809
    5.1970   -0.8892    0.3194   -1.2976
   -4.6809    2.2290    0.5874   -1.2277
    0.2521   -0.5795    0.9173   -1.0585
    0.3974   -0.4283    0.7157   -0.8962
    0.5606   -0.1899    0.5921   -0.7670
   -1.0561    0.1465    0.5834   -0.6517
    0.8381   -0.4872    0.5153   -0.5376
    0.1255    0.0156    0.4210   -0.4473
   -0.4819    0.0909    0.4423   -0.3615
    0.4016   -0.1982    0.4208   -0.2733
   -0.1312    0.0428    0.3898   -0.1938
    0.4518   -0.0359    0.3911   -0.1152
   -0.4879    0.2352    0.4310   -0.0348
   -0.2224   -0.0576    0.4665    0.0569
   -0.2181   -0.1910    0.4168    0.1461
    1.6517   -0.3218    0.3143    0.2201
   -1.2799    0.6692    0.3837    0.2833
   -0.2961   -0.0988    0.4978    0.3766
    0.2481   -0.2764    0.4228    0.4698
    1.4418   -0.1276    0.3420    0.5453
   -1.2546    0.7375    0.4640    0.6201
   -0.5827   -0.0153    0.6084    0.7324
    5.7049   -0.3649    0.5324    0.8488
  -13.4149    3.0580    1.0710    0.9863
   -8.8337   -0.9664    1.2802    1.1106
   49.8411   -3.6165    0.8219    1.2201
  -58.5074   11.3358    1.5938    1.3160
  122.1096   -6.2164    2.1057    1.5302
  442.5466   30.4164    4.5257    1.8007
  442.5466   96.7984   10.8865    2.1584

 

I wonder, if it is really not possible to just use the code and paste it somehow?

 

Many thanks,

Jonas

 

0 Kudos
Message 3 of 11
(2,888 Views)

Look at the attached VI, it demonstrates the threshold functionality.

 

You can use the "read from spreadsheet" function, to bring your arrays in to LabVIEW.

Message 4 of 11
(2,884 Views)

Many thanks reshri!

This sounds amazing.
 I am looking forwartd to looking at your file! However, I cannot open your file with LabView9. And I cannot updatye to 2012, since I need to transfer files to our Labcomputer, which runs with LabView9.
 -> Can you send me a Labview9 file?

Sorry for that and many thanks!

Greetings from Copenhagen,

Jonas

0 Kudos
Message 5 of 11
(2,879 Views)

This should work,

 

Regards

Message 6 of 11
(2,869 Views)

Thanks a lot, this is awesome. We would never have figured that out.

I have tried to put in the data, but couldn't do it. - Is there a way to enter the values into the array? Lookslike the "read from spreadsheet" would be a dynamic thing. I have the values as tab separated values, we can copy them to csv, semicolon separated, ... whatever.However, our data will not change, it's just for setting the 200 values once.

 

Cheers,

Jonas

0 Kudos
Message 7 of 11
(2,866 Views)

A handy trick is to have the "read from spreadsheet" get the data from the file and write it to an indicator on the front panel. After running the VI one time, go to the block diagram of the VI, right click on the indicator's terminal and select Change to Constant from the shortcut menu. Now you have a constant containing all your data and you can delete the read from spreadsheet VI.

 

Mike...


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
Message 8 of 11
(2,864 Views)

Oh yes, one more tweak that you might want to add to the code Jonas posted: What happens if X is less than 2? If you want to flag that input as an error condition, increment the index by one just before it goe into the array indexer and add a new Row 0 to your data array containing the values that you want the logic to output in that case.

 

A similar situation exists with values greater than 10. Adding a row to the end of the data will allow you to identify that condition as well.

 

Mike...

PS: when you like something, a good way to show it is to click the "Kudos" button...


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
Message 9 of 11
(2,861 Views)

We are working on this now, ...

However, we were wondering, if it were possible to use the Function Node or even the MathMode, to carry out such tasks, that or really only about applying a formula to a signal.

 

Best, Jonas

0 Kudos
Message 10 of 11
(2,856 Views)