LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Waveform Generation - what would you do?

Solved!
Go to solution

Heyy all,

 

Case 1 - Function Node subVI

Ram8_0-1758016509816.png

Everything is straightforward, you just need to call this subvi in the main loop

 

Case 2 - Select subVI

Ram8_1-1758017374338.png

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!

0 Kudos
Message 1 of 10
(283 Views)
Solution
Accepted by Ram8

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"!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 10
(270 Views)

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.

0 Kudos
Message 3 of 10
(261 Views)

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?)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 4 of 10
(245 Views)

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;
}

 

Ram8_0-1758028896634.png

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)

Ram8_4-1758025432353.png

 

But what I get now is:

Ram8_1-1758028913674.png

 

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)

0 Kudos
Message 5 of 10
(164 Views)

Sorry,

 

My max and min was intertwined.

 

But still the limits are as high as 160 and low as -80

Ram8_0-1758029580088.png

But waveform is starting to look like what is needed.

0 Kudos
Message 6 of 10
(150 Views)

@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;
}

 

Ram8_0-1758028896634.png

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)

Ram8_4-1758025432353.png

 

But what I get now is:

Ram8_1-1758028913674.png

 

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?

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
0 Kudos
Message 7 of 10
(139 Views)

Hi Ram,

 


@Ram8 wrote:

But still the limits are as high as 160 and low as -80

Ram8_0-1758029580088.png


So it boils down to (adjust numbers as needed):

  1. ramp 0 to 160 in 256 samples
  2. ramp 160 to 0 (?) in 1792 samples
  3. ramp 0 to -80 in 256 samples
  4. ramp -80 to 0 in 1792 samples

Possible solution:

  • You need a FOR loop with the Ramp function inside.
  • Provide an input as array, with start, end and NumOfSamples for each row.
  • Use a concatenating output tunnel to create your array of samples from each ramp part…
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 8 of 10
(137 Views)

Hi Ram,

 

my suggestion as image:

I used an array of clusters to hold your ramp parameters…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 9 of 10
(102 Views)

@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.)

0 Kudos
Message 10 of 10
(17 Views)