LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Re-index an array

Hi all,

Please, Here I try to change the width of the signal by re-indexing the array . I can do that up to 130. For larger width the array should be flexible. So please some hints to do that will be appreciated.

Thanks,,

0 Kudos
Message 1 of 10
(4,594 Views)

Hello,

 

Could you please be more specific, what exactly you are trying to do. According to the code you are extracting non-zero elements, and then trying to index initial array, and then build it again.

 

What is required to do with the initial array?

 

Thanks,

Arev

 

CTO | RAFA Solutions

 

Certified-LabVIEW-Embedded-Systems-Developer_rgb.jpgCertified-LabVIEW-Architect_rgb.jpg

0 Kudos
Message 2 of 10
(4,563 Views)

@M.A.A.M wrote:

Hi all,

Please, Here I try to change the width of the signal by re-indexing the array . I can do that up to 130. For larger width the array should be flexible. So please some hints to do that will be appreciated.


Do you just want to resample the array (e.g. fewer or more points covering a sub-range of the original data)?

What is magical about 130? What is your definition of "flexible"? I don't understand the meaning of that term.

0 Kudos
Message 3 of 10
(4,536 Views)

Easiest would be to just create a ramp and interpolate according to the new x-values. You can calculate the boundaries according to your desired scale and shift factors.  You could even change the number of points.

 

The attached draft should get you started. All you need to add is the scaling math.

 

 

Download All
Message 4 of 10
(4,524 Views)

Hello, Boss,

Yes exactly I need to resample the orignal array using scaling factor.

There is no magic for 130, just it's an example for what is going when the scalng factor is small, in which the desired pattern will be out of he range of the array size.

I mean by flexible that the array size can programatically increase to show all elements after resampling.

Thanks you.

0 Kudos
Message 5 of 10
(4,477 Views)

@M.A.A.M wrote:

Yes exactly I need to resample the orignal array using scaling factor.

There is no magic for 130, just it's an example for what is going when the scalng factor is small, in which the desired pattern will be out of he range of the array size.

I mean by flexible that the array size can programatically increase to show all elements after resampling.


So? Does my example fit your bill?

 

There are several parameters that determine the outcome of the resampling:

 

  1. number of points in the input
  2. desired number of points in the output
  3. scaling parameter that determines the final peak width (in possibly fractional array index units) compared to the original
  4. etc.

Very few selected combinations will ensure that only existing array values are touched. In all other cases, an interpolation (e.g. linear as in my example)  needs to be performed because the new "index-positions" are not mapped into integer positions of the old array. that's what my code does.

 

If this is not what you want, you need to explain exactly how "your" resampling is supposed to work.

 

0 Kudos
Message 6 of 10
(4,432 Views)

Hello Boss,

Thanks for the time you pay to guide me, appreciate that.

The story like that: the input data represents the pattern generated by a single wire when passing in front of an LED assuming that there is no diffraction. Then if I consider the diffraction, the width of this pattern should be affected. We can easily calculate the width of the diffraction pattern for a known wire size [d], light wavelength [λ] and the distance between the wire and the screen [D] (in our case LED).

Then I want to normalize the original Pattern using the results obtained from the diffraction pattern. The normalization scaling factor in my opinion will be equal to the original width divided by the summation of original width and diffraction pattern width, this factor has a reverse proportionality with [D]. If this factor equals or greater than unity, there will be no problem because the pattern will be smaller and it will shift to the left. But if the factor is less than unity the pattern will shift to the right side of the graph. So, the graph will display just 1250 points, if the pattern within this 1250 points it will be fully displayed. Otherwise it will be partially displayed, even sometimes it's not displayed.

So that, I have no problem to do mathematical calculations, but my problem how to display the normalized graph.

To solve that I have to initialize an array of a size at least to be equal to original size divided by the scale factor.

I hope that my idea was explained well.

Thanks again.

0 Kudos
Message 7 of 10
(4,405 Views)

From the shape of the curve in previous post, which is like gaussian curve to give an idea of the shape, how to rebuild Y array from equally spaced index X , to a new Y array defined by non linear index X ? 

For instance, this question is an extension of linear-log axis representation. But here, it intends to adapt to the shape of the initial curve to have more points in the peak area, and less at the beginning and end (I mean away from the peak = less point)

 

I though like that : 

1- create the function using code formula : OK

2- calculate the derivative : OK

3- find index Z of derivative dY/dX > Th : I can see on graph top right

4- between those index Z, create more points. 

 

Step 3-4 : I don't clearly see how to do it. 

 

The example program works quite well when using : 

non linear factor = 2.5

N point = 200

The formula is X1/(1+X1*pi*(X2-X3)**2)+X4

 

Is there any way to simplify it, or to make this idea more universal ? 

 

0 Kudos
Message 8 of 10
(3,149 Views)

Here's some unasked advice. It won't solve the problem, but it might help you find it faster as you save some time next time...

Spoiler
Simpler.png
Message 9 of 10
(3,135 Views)

Thank you ! simplifications like this is really appreciated.

0 Kudos
Message 10 of 10
(3,111 Views)