LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to search array with margins?

Solved!
Go to solution

Hi!

 

I have a signal that i take in from a PXI 5600 and store it in an array. What i want to do is to find the peak of the signal (this i have done succesfully) and then calculate the bandwidth.

 

 

What i do now is to take the peak value and calculate 20dB, then i use the "1 D Array search" but i get the index -1. My guess is that this is happening because of that the array doesnät contain EXACTLY the calculated value.

 

Can i somehow search the array for the values around the calculated one?  For example; if i calculated the value 10.08 i want to search for everything between 9.9 - 10.1.

 

 

then i wonder how i can plot these points whith a line between them in my already power spectrum

0 Kudos
Message 1 of 14
(3,671 Views)

Hi Firas,

 

ever looked at the comparison palette and wondered about that "InRangeAndCoerce" function?

check.png

You can also apply your own math as shown above...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 14
(3,664 Views)

Use Threshold 1D Array rather than Search.  You are correct that Search looks for exact values and that you will almost never find then with floating point data. The Threshold function returns a fractional index that represents the interpolation of the data bewteen indexes when the data is not an exact match.

 

The detailed help explains the -1 index value returned.  If you are not in the habit of keeping context help on while porgramming and looking at details when you do not understand how something works, try it. The detailed help for the Search function includes a link to the Threshold function and a brief explanation of when it might be the better choice.

 

Lynn

0 Kudos
Message 3 of 14
(3,660 Views)

Hi Lynn,

 

ThresholdArray has one shortcoming as the help says "Use this function only with arrays sorted in non-descending order."!

Best regards,
GerdW


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

Make a subVI that contains a for loop.  Have the loop exit when the value is within your range.


GCentral
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 5 of 14
(3,647 Views)

GerdW,

 

Right.

 

If the signal is very clean so that noise is not an issue, extracting array subsets before and after the peak and then reversing and possibly inverting the arrays could make the Threshold function work. 

 

Regardless, some programming will need to be done to find the specified points.

 

Lynn

0 Kudos
Message 6 of 14
(3,646 Views)

I like this way a bit better than GerdW just because of the indexing part, i need it to calculate the frequency. But i'm having 2 problems:

 

1 - The loop condition will not connect as you did. It says : "Connecting two terminals of different types . 

The type of the source is 1-D array of
boolean (TRUE or FALSE).
The type of the sink is boolean (TRUE or FALSE).

 

2 - I will get the first value this way. But how can I search the other value (value after the peak). Do i have to create a new array that starts from the index where the peak is?

0 Kudos
Message 7 of 14
(3,616 Views)

Hi Firas,

 

to search errors it is always helpful to attach the VI or at least a snippet/picture of the BD!

Then you should also make clear which example you used...

 

Then:

- When the comparison results in an array you can change the comparison mode, index the arrays before the comparison or after. It depends on what you have programmed - and you didn't show that...

- When you do it my way you get a boolean array. You can search that array for your interesting points using "Search 1D Array"...

Best regards,
GerdW


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

Sorry, thought i quoted the solution i used.

 

I think i get your solution now and i've attached a print of what im doing. As i said before i have a peakvalue and want to calculate the bandwith, that means one point at -20dB to the left of the peak and one point to the right.

 

Im still getting -1 from the array searchs. I dont get whats wrong:S

 

 

 

 

 

Link to the pic: http://img221.imageshack.us/img221/5857/95828741.jpg

 

0 Kudos
Message 9 of 14
(3,611 Views)

Hi Firas,

 

always upload picture here in this forum! Your imageshack-file is resized - and it's link is malformed...

So you got that on your own... No, you don't got that...

 

- You don't need a sequence structure for that calculation...

- Attach a VI with some example data: make an indicator showing your waveform. Create a constant from that indicator and save the vI. Attach it...

Best regards,
GerdW


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