LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to group consecutive equal values from an array X and compute the average of the corresponding values in an array Y?

Solved!
Go to solution

Hello people,

 

I need to process two arrays: one containing voltage values (X) where repeated values appear consecutively, like x5=2.05V=x6=x7=x8,and another with corresponding current measurements (Y), which slightly varies. For each group of repeated X values, I want to calculate the average of the associated Y values and generate two new arrays—one with the unique X values and another with the averaged Y values.

 

So for example for x=5.05V, I have 5 consecutive values in the X array and then I need to know the especific position of those 5 values in the array so I can allocate the values of the Y array and then calculate the average of those 5 values in Y and then save the average in a new array, lets say Y_average and also save the X value in another array X_new.

How can this type of search and save arrays be done in Labview? 

 

Wen

0 Kudos
Message 1 of 14
(394 Views)

The word "equal" for floating point numbers is tricky.

 

If the x values are quantized to a limited number of possibilities, this is quite a simple problem, especially since equal x values are adjacent.

What have you tried?.

 

Why not attach a simple VI containing some typical data?

0 Kudos
Message 2 of 14
(357 Views)

I'm trying to do a curve tracer with Labview, so after measuring the I/V curve I get a curve with a lot of points around a specific curve like the following one.

Whens_Wens_Day_0-1747135253139.png

So I'm trying to do an average of those points and represent the curve like they normally do in some professional curve tracers.

My professor recomends me doing an average point for intervals of for example 5mV, which I don't quite know how to that in LabView.

Another aproximation I can see is that, if I zoom a specific interval of the curve, there is multiple points which share the same X coordinate although not the same Y coordinate. Like the following figure:

Whens_Wens_Day_1-1747135495719.png

So Im thinking about doing the average of those points with the same X and diferent Y because i guess its easier?

Whens_Wens_Day_3-1747135752665.png

Some examples of the Voltaje_Example

Then I checked the typical data of the measurements, attached as txt, and I found that first, they are not ordered consecutively, and that makes the problem even harder to solve.

 

So any suggestions to solve this? 

 

Ps: I tried switching different values of resistors, and with a higher value of resistor the variation of current(Well, I'm measuring voltaje in reality) varies a lot less.

 

Wen

 

 

Download All
0 Kudos
Message 3 of 14
(316 Views)

Hi Whens,

 


@Whens_Wens_Day wrote:

I'm trying to do a curve tracer with Labview, so after measuring the I/V curve I get a curve with a lot of points around a specific curve like the following one.

 

So any suggestions to solve this? 


Why do you have ALL points in just one plot?

Why don't you create 10 (or 11) plots for the different traces in your image?

Separating those traces would make it a lot easier to filter the data…

 

What should we do with your measurement data?

How is the data organized/formatted (in your files)? Is there a meaning in the number of rows and columns?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 14
(306 Views)

Your data looks like one line from the voltage file corresponds to one line of the current file. So read both files with Read Delimited Spreadsheet and loop over both arrays. In the loop, build an array of clusters to sort the data.

cordm_0-1747145034359.png

 

 

For averaging and in your special case of multiple exact x-values, you can group by x-value and do an average.

If you have LV2019, you can use Maps with the x-value as key and a {sum, counter} cluster as value.

 

cordm_1-1747145053529.png

 

In earlier versions, or if you want a different grid, you could define an array of x-values and find for each input x the closest grid point. This is an example with a custom grid, you can swap it out against the sorted and deduplicated input x-values.

 

cordm_2-1747145110746.png

 

 

You should probably also filter out NaN values and ensure that every line has the same number of measurements.

0 Kudos
Message 5 of 14
(276 Views)

These curves seem to follow some simple mathematical model. If you have a formula, I would just do a nonlinear fit. This way you can reduce each curve to a handful of parameters.

 

Else, you could just some some filtering followed by decimation.

0 Kudos
Message 6 of 14
(275 Views)

Here's using a dumb polynomial, but I am sure you can find a reasonable model equation. Depending on what each trace means, you could even do a 2D fit to all data!

(Note that the data files need to be located next to the VI, but you can of course modify that)

 

altenbach_0-1747149933635.png

 

 

 

0 Kudos
Message 7 of 14
(261 Views)

Hi 


I think the easiest way would be to average the original signal both x and y and plot them after the average, this would eliminate the noise you read when acquiring the data. 

 

0 Kudos
Message 8 of 14
(223 Views)

Hi,

 

Cordm's solution looks amazing but I don't really understand your data flow.

Whens_Wens_Day_0-1747240728509.png

What are the inputs for the sum_grid_values? And the cluster of arrays you introduce in Inicialize array is the sorted and deduplicated X values? And the other 2 inputs? Can I have a look of the vi?

 

Wen

0 Kudos
Message 9 of 14
(173 Views)

Hi Gerdw,

 

Actually, I generate each especific trace of my image in a single loop and then I plot them consecutively in the same XY Graph.

They need to be plotted in the same graph to compare the behavior of the transistor across different regions of operation and to ultimately determine the operating point(Q-point).

 

I would want to do an average of the values for a certain grid, lets say 5mV, for each curve IV in which each value X is asociated with a Y value forming a pair. Lastly the data are just a array of lines separated with spaces. 

0 Kudos
Message 10 of 14
(163 Views)