09-16-2025 05:32 AM
Heyy all,
Case 1 - Function Node subVI
Everything is straightforward, you just need to call this subvi in the main loop
Case 2 - Select subVI
The same thing but with Select. The 'i' will be passed from a 'for' loop in the main vi where this subvi is called.
So my question is which case would you use? I feel like case A is concise and easier for error checks.
Also, is there another efficient way to do this? Advice appreciated! Cheers and hope you have/had a great day!
Solved! Go to Solution.
09-16-2025 05:44 AM
Hi Ram,
@Ram8 wrote:
So my question is which case would you use? I feel like case A is concise and easier for error checks.
None of them…
It seems you create a "waveform" (better: an array of samples) by appending 4 ramps.
Why not use the ramp function (4 times) and a simple BuildArray node?
@Ram8 wrote:
Also, is there another efficient way to do this?
As said before: LabVIEW comes with several basic waveform generation functions: use them!
LabVIEW also knows about a waveform datatype, that consists of more than just an array of samples. Use the correct wording for your questions!
Also generic advice: ask for WHAT you want to achieve, don't ask HOW you intend to achieve your goal!
You will get much better help when you describe your requirements (like "I need a waveform of ramp up, hold, ramp down, hold") instead of "should I use a formula node or some select nodes"!
09-16-2025 05:54 AM
Hi GerdW,
Thanks! Still new to this world, I will look into the waveform functions.
If it was a random case of if else statements, which approach would you suggest?
Regards,
Ram.
09-16-2025 06:12 AM
Hi Ram,
@Ram8 wrote:
a random case of if else statements
"if then else" is never random, you have to apply known limits…
Please provide better descriptions of your requirements!
Again: explain the WHAT, but not the HOW!
(What about a simple statemachine, that can append "waveform" parts (like ramp and sine), based on a list of parameters?)
09-16-2025 07:26 AM - edited 09-16-2025 08:22 AM
Hi,
I would like to build an asymmetrical triangular waveform.
Since the size of the samples is a variable, I am unsure on the use a case structure.
There are min and max limits to the waveform as well.
The following C code was used to:
double asym_tri(int i, int size, double lo, double hi)
{
double value;
if (i < size / 16) {
value = 16.0 * i / size;
} else if (i < size / 2) {
value = (8.0 / 7.0) - (16.0 / 7.0 * i / size);
} else if (i < size * 9.0 / 16) {
value = -16.0 * (i - (size / 2)) / size;
} else {
value = -(8.0 / 7.0) + (16.0 / 7.0 * (i - (size / 2)) / size);
}
return value * (hi - lo) / 2 + (hi + lo) / 2;
}
This is a snippet of me using Ramp Pattern.vi. Could you help me achieve the C code?
The subvi is basically: value * (hi - lo) / 2 + (hi + lo) / 2;
What I wanna achieve is: (I have taken 4096 as sample size here, this can change)
But what I get now is:
I want the waveform as an array, because this value will populate another 3rd party function call.
Lemme know if you need more info.
Regards,
Ram.
(Extra info: I am able to achieve the waveform using Select and Function Node, but want to optimize to LabVIEW's potential)
09-16-2025 08:33 AM
Sorry,
My max and min was intertwined.
But still the limits are as high as 160 and low as -80
But waveform is starting to look like what is needed.
09-16-2025 08:55 AM
@Ram8 wrote:
Hi,
I would like to build an asymmetrical triangular waveform.
Since the size of the samples is a variable, I am unsure on the use a case structure.
There are min and max limits to the waveform as well.
The following C code was used to:
double asym_tri(int i, int size, double lo, double hi) { double value; if (i < size / 16) { value = 16.0 * i / size; } else if (i < size / 2) { value = (8.0 / 7.0) - (16.0 / 7.0 * i / size); } else if (i < size * 9.0 / 16) { value = -16.0 * (i - (size / 2)) / size; } else { value = -(8.0 / 7.0) + (16.0 / 7.0 * (i - (size / 2)) / size); } return value * (hi - lo) / 2 + (hi + lo) / 2; }
![]()
This is a snippet of me using Ramp Pattern.vi. Could you help me achieve the C code?
The subvi is basically: value * (hi - lo) / 2 + (hi + lo) / 2;
What I wanna achieve is: (I have taken 4096 as sample size here, this can change)
![]()
But what I get now is:
![]()
I want the waveform as an array, because this value will populate another 3rd party function call.
Lemme know if you need more info.
Regards,
Ram.
(Extra info: I am able to achieve the waveform using Select and Function Node, but want to optimize to LabVIEW's potential)
What is the source of this C implementation? is this based on any other formula? what is the significance of those constants in the implementation?
09-16-2025 08:56 AM
Hi Ram,
@Ram8 wrote:
But still the limits are as high as 160 and low as -80
So it boils down to (adjust numbers as needed):
Possible solution:
09-16-2025 02:14 PM - edited 09-16-2025 02:15 PM
09-17-2025 01:28 PM
@GerdW wrote:
Hi Ram,
my suggestion as image:
I used an array of clusters to hold your ramp parameters…
If the ramps are guaranteed to be contiguous then you can skip the "start/end" and just have "target" and "samples". (You'd need to provide a starting point though.)