LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to split an array into two arrays with alternating elements

Solved!
Go to solution

Hello, 

 

I am measuring real and imaginary part of scattering parameters in Vector network analyzer. The analyzer is giving two data points (real and imaginary) at each sweep point (frequency) in a form of 1D array. The real and imaginary part are intermixed in the array- the first element is real and the second one is imaginary and so on .. I want to split this array into two arrays with alternating elements. Can anyone help me how to do it?   

 

Thanks in advance!

0 Kudos
Message 1 of 15
(1,755 Views)
Solution
Accepted by topic author LabSky

Decimate 1D array is exactly what you need, feed in the 1D array, resize the function to output two 1D arrays

santo_13_0-1637166345779.png

 

santo_13_1-1637166370300.png

 

 

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 2 of 15
(1,752 Views)

Simply use the "Decimate 1D Array" function.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 3 of 15
(1,751 Views)

Did you know that "decimate" originally meant to kill one out of every ten in a group as a group punishment?

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 4 of 15
(1,746 Views)

I would typecast it to a complex array instead. Now you only have one array. 😄

 

 

altenbach_0-1637166968025.png

 

I assume that most further processing will operate on complex datatypes anyway. 😄

 

(Of course you need to adjust the array constant according to the input, for example if the input is SGL, it would need to be CSG, etc. If the input array is integer, you should probably convert it to floating point first.)

 

My gut feeling is that the typecast solution will be more efficient, because there is no change in memory order of the elements. If you decimate, you create two separate 1D arrays of half size, just to interlace them again into the complex array. Array data is always contiguous in memory, so unless the compiler can see through all that, more allocations are needed for this route.

 

altenbach_0-1637168209719.png

 

 

 

 

Message 5 of 15
(1,744 Views)

@Bill - could you please elaborate on your observation of decimate 1D?

 

@Altenbach - that is an excellent way, new learning about TypeCast and complex numbers.

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 6 of 15
(1,717 Views)

It's in the etymology of the word.  Thankfully, the decimate array doesn't kill people (not directly, anyway); it just sorts elements in an array like a card dealer deals a poker hand and you end up with an "array" of cards.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 7 of 15
(1,712 Views)

Hello guys, 

 

Thank you very much for your help. I truly appreciate your prompt replies. 

 

Both solutions work well. I need  both the real and imaginary parts but separately for further analysis. 

 

Thanks!

0 Kudos
Message 8 of 15
(1,709 Views)
Solution
Accepted by topic author LabSky

@LabSky wrote:

Both solutions work well. I need  both the real and imaginary parts but separately for further analysis. 

 


Can you tell us a bit more about that "further analysis".

 

It is likely that everything can be done much more efficiently directly with complex data, for example most transforms (e.g. FFT) understand complex inputs. Even simpler things such as magnitude and phase are easy to obtain without need of any trigonometry functions. 😄

Scaling and rotation in the complex plane (e.g. for phase correction) is just a multiplication with a complex scalar of given R and theta and if r=1, it's just a rotation (example).

 

Even xy graphs understand complex arrays directly and will graph IM vs RE!

 

(this is only the tip of the iceberg!)

 

altenbach_1-1637172264983.png

 

 

 

 

0 Kudos
Message 9 of 15
(1,696 Views)

@altenbach I am measuring an absorption curve which is proportional to the imaginary part of  susceptibility tensor. To be honest we only care about imaginary part. But for the completeness we do also measure the real part. 

The vector network analyzer is very sophisticated instruments although. It allows to measure the magnitude, phase, and delay  separately. 

 

Your suggestion is indeed the best for the handling and post processing of complex data sets.    

 

 

 

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