LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using linear interpolation for to find a certain X from data in a 1D array

Solved!
Go to solution

Hello community this is my first post! Have been reading the forums for some time now trying to figure out my way around the software. Have learned a lot over the last few months but i still have a lot more i want to learn.

I'm creating an application in Labview 2013 that can detect the cutoff frequency of a Low or High Pass Filter. I have two data points that are being indexed onto the frame of a for-loop over a user chosen number of iterations. These data points describe the dB gain vs frequency as an AC sweep is performed through either a Low or High Pass Filter. I'm trying to use linear interpolation to determine what the cutoff frequency is (assuming it will be at about -3dB no matter what range i sweep), but am having no luck. I've tried bundling creating arrays. indexing the individual streams with no luck. I find that my skills with arrays and clusters are sub-par and i feel that is the source of my struggles.Here is a screen shot of the back end of my application. Any information would be much appreciated.

0 Kudos
Message 1 of 12
(6,895 Views)
Solution
Accepted by RJMason

Hi RJ,

 

when you are looking for a certain X value corresponding to a known Y value you should use the function Threshold1DArray.

Interpolate1DArray gives an Y value for a known X value…

 

Btw. most of the time it's much better to provide a real VI with some embedded default data then just to present an image!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 12
(6,842 Views)

@GerdW wrote:

when you are looking for a certain X value corresponding to a known Y value you should use the function Threshold1DArray.


But do note that the Threshold 1D Array is expecting a constantly rising waveform.  So you may need to reverse the array to get the value you want.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 3 of 12
(6,838 Views)

Thank you, I will test out your solution. I just want to be clear that since the user is choosing the number of points to plot (iterations) there is little chance that -3dB and the associated frequency will be in the data set. That i why i was looking to linear interpolation to find the solution. I assume it will take the two points and frequencies directly adjacent to the dB value i am looking for and estimate what that frequency valued might be.

0 Kudos
Message 4 of 12
(6,811 Views)

@crossrulz wrote:

Threshold 1D Array is expecting a constantly rising waveform.

The right term is "non-descending" which is slightly different. 😄 But yes, that function will work fine once you negate the array and threshold. You should form your upper input into an array of points so you get the x in the right magnitude.

Also note that your x-axis is logarithmic, so your might need to tweak depending if you want a linear interpolation on a linear or logarithmic scale. You can easily account for that if needed.

Message 5 of 12
(6,791 Views)

GerdW after reading your comment again i understand what you meant by suggesting the Threshold 1D Array. It works very well for the High Pass Filter, right within my 5% error margin (likely do to  round off error in formula node).


Crossrulz you are correct in it not working for descending plots, like a Low Pass filter. I have found the function reverse array that may get me where i need to be.

It will have to work with either circuit so i must come up with a way for it to determine that. I'm thinking of using a case structure with the conditions of first Y < Second Y. That should let me know what circuit i am dealing with and i can execute depending on that situation.

Do you know of a functions that will allow me to compare the first and second elements of a 1D array?

0 Kudos
Message 6 of 12
(6,787 Views)

@RJMason wrote:


Do you know of a functions that will allow me to compare the first and second elements of a 1D array?


"Index array" resized to two outputs will get you the first two elements. Have you found the comparison palette?

Message 7 of 12
(6,771 Views)

Yes i have. I realized what i had was a 1D array of 2 cluster elements. I played around with combinations of Split 1D array, Index Array and UnBundle by Name and found that if i just index the dB gain into the edge of the For Loop and bypass the 1D array cluster all together i can just index elements one and two and compare them pretty easy. I'll test a few more configurations to make sure all is well.

0 Kudos
Message 8 of 12
(6,766 Views)

I was unclear what you meant at first with "negate the array". I see now that its throws the the Min Max off, swapping them basically. I fixed this by just swapping the indicators as i was not sure how to negate the entire array. All seems to be working fine now. Thanks!

0 Kudos
Message 9 of 12
(6,730 Views)

@RJMason wrote:

I was unclear what you meant at first with "negate the array". I see now that its throws the the Min Max off, swapping them basically. I fixed this by just swapping the indicators as i was not sure how to negate the entire array. All seems to be working fine now. Thanks!



A simple array can be negated at once and if you have an array of clusters, you can just multiply with a suitable scalar element.

 

 

 

I have no idea why you are bringing "indicators" into the discussion. These operations are just for the interpolation math, don't need to be displayed, and thus don't involve indicators.

 

Can you show us your final code?

0 Kudos
Message 10 of 12
(6,724 Views)