LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to speed up Labview code

Solved!
Go to solution

In addition to the things altenbach pointed out several others should be considered.

 

- You appear to have at least two different typedefs for the state enum.  This could cause problems if one gets changed and the other does not.

- All the indexes should be I32. For loops and arrays cannot be larger than the maximum value of an I32. The extra coercions take a small amount of time.

- Local variables are much slower than wires.

- Move any calculations which do not change to the outside of the loops.  For example #of Steps - 1 is calculated inside the while loop in the "first step" case but it cannot change after the program starts running. 

- Use only one Threshold constant. If you ever need to change the value, it will be very tedious to find all the places it is used. If you miss one, the program could do some very strange things. If you have just one and wire everything to that, then making a change becomes simple.

- Move all indicators outside the loops. If the loop iterates faster than about 5 times per second, a user cannot keep track.  More importantly, the time it takes to update indicators can significantly slow the code. (Note that if this is a subVI which runs with the front panel closed, LabVIEW is smart enough to not update those indicators).

- Indicators should never be used just to create local variables.

- The code in the for loops with Index Array, >=?, conditional terminals, followed by array size can be simplified. The code on the right can be ~5 times faster depending on the values.

 

 

Hard way to count.png       Easier way to count.png

- Code like the loops shown above which is duplicated several times should be made into a subVI. One subVI can be used to handle several variations in that code. Some places the start index is always zero. In those places that input to the subVI can be left at the default. Some place only the length output is used. Some use only the boolean. Others use both. One subVI can handle all those situations.

- The "state" = comparisons in several places can be simplified by wiring the state output to the case selector of another case structure. Set one case to select the "=" state and use Default for all the others.

 

And probably other things as well.

 

Lynn

Message 11 of 19
(2,801 Views)

It also seems that you only do simple threasholding on the complex magnitude squared. You could probably eliminate all subVIs to the left of the main case structure by simply taking the absolute value of the complex array and adjust the threshold value accordingly.

 

Yes, as Lynn said, all your integers should be I32. Make the terminals the correct representation, and you would not even need to convert later.

Message 12 of 19
(2,782 Views)

Dear altenbach,

Thanks for your feedback, I will try to exlain to you the exact idea of using this Vi,

 

I am generating power and frequency sweep (-30 dbm t0 -20dbm) in 8 steps. then I added 2 step further at -150 dbm at the first and final step. So the total is let's say 10 steps. SO the result as can be shown in figure 1 (f1).

 

the problem is that there is no synchronization between these two chassis which makes RFSA start at different time from RFSG which casues as attached in figure 2(f2). Thus, this menioned vi is being used to auto correct the widow.

 

this vi uses as long as change the control.  

                                                    -------------------------------------------------

You still have not told us your definition of "so slow". How slow is that? Do you have some numbers? Are you graphing 1M data in the calling VI? What else does the calling VI do? How long does it take for the subVI to complete?

                                                    -------------------------------------------------

The defintion of slow when you want to change the value of the control. it too slow to change the value in front panal. in contrast when the program implement the auto correct window it take second to correct it. 

 

 

Download All
0 Kudos
Message 13 of 19
(2,734 Views)

Dear Lynn,

 

I am really so grateful to your valuable feedback, I've followed exactly your advices but it stills some notes which I hope you could explain to me ass follow

 

johnsold wrote:

 

- You appear to have at least two different typedefs for the state enum.  This could cause problems if one gets changed and the other does not.

                                                                                                             -------------------------------------

sorry, i didn't recognize that till this moment, I checked them and it seems to be the same type definition. can you please tell me which one do you mean?

 

                                                                                                             -------------------------------------

 johnsold wrote:

Move all indicators outside the loops. If the loop iterates faster than about 5 times per second, a user cannot keep track.  More importantly, the time it takes to update indicators can significantly slow the code. (Note that if this is a subVI which runs with the front panel closed, LabVIEW is smart enough to not update those indicators).

- Indicators should never be used just to create local variables.

                                                                                                             -------------------------------------

 the main perpuse of this Vi is to find the index of specific element  in order to re arrange them in the right way. So I tried to use other ways without local variables but it seems to be difficult to implement.

 

                                                                                                             -------------------------------------

By the way I attached the vi after followed your advice. kindly have a look if that's posssible 

 

 

 

0 Kudos
Message 14 of 19
(2,730 Views)

@Al-rawachy wrote:

the problem is that there is no synchronization between these two chassis which makes RFSA start at different time from RFSG which casues as attached in figure 2(f2). Thus, this menioned vi is being used to auto correct the widow.


You should supply your code.  This is a simple thing to synchronize at least close enough, especiallyl since it looks like you are just dealing with CW signals.  I just finished up a power sweep for a customer doing something similar.  I went through some 35 RF levels over 20 frequencies with NI-RFG and an NI Power Meter.  The entire sweep took 46 seconds.  I would expect similar results with NI-RFSA.


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
0 Kudos
Message 15 of 19
(2,708 Views)

I only have a few minutes before I need to leave for the day so I will only comment on two simple items.

 

1. The typedefs. Open the Context Help window.  I always keep it open while I am programming. Move the cursor over the enum constants on the block diagram. The constant which  initiailizes the shift register is unnamed (label is empty). In the True case of "first step" one of the constants is unnamed while the other has label 'f'. I discovered this because the typedef file (the .ctl) was not included which creates errors. The error list showed two different errors, depending on the label of the enum constants.  If the only difference is the label, I think it will not be a problem, but it indicates that the constants were probably created two different ways.

 

2. The synchronization. Search for the >20 dB step between the noise floor and the power level. That is a clear indication of where the second step started. Back up by the number of samples in the baseline step and start the analysis from there.  This will require keeping more than one acquisition in a buffer so that it does not matter where the data set starts on the receiver side. 

 

Lynn

Message 16 of 19
(2,697 Views)

`Some of your manipulations could be greatly improved.  As an example lets look at this section with buffer allocations shown:

Capture1.PNG

Those black squares show where LabVIEW needs to allocate blocks of memory.  Tools>>Profile>>Show Buffer allocations is very handy.

 

Here we see that the array subset allocates a largish array that isn't used except to create a large arry of bool- cast to a large array of U8 Cast to a large array of I32 just to get a count of elements above threshold

Capture.PNG

This is equvalent and a lot less memory is used


"Should be" isn't "Is" -Jay
Message 17 of 19
(2,664 Views)
Solution
Accepted by topic author Al-rawachy

Jeff,

 

Thanks for the improvements.  I was not thinking about memory when I put that together - only that it was about 5 times faster than the original.

 

Note that the Array Size output will be equal to the value in Numeirc Control unless that runs past the end of the array. So the Array Size may not be needed. The OP will need to decide how to handle that case if it can ever occur.

 

Al-rawachy,

 

The attached VI shows how I eliminated all the local variables by  using wires and shift registers. This does not include the changes Jeff suggested. That code is inside the Count.vi. To try Jeff's code make a subVI from his snippet. The Replace Count.vi with that VI. I do not have the IQ subVI so I substituted other code to provide some data for testing purposes. I also disabled Request Deallocation becaues it is almost always not needed.

 

Lynn

Download All
0 Kudos
Message 18 of 19
(2,642 Views)

Hi All,

 

Thank you so much for oyur comments, I really get so much information from your comments, I am really so grateful for you.

 

Also Special thanks to Lynn, i don't know how to express my thanks to you.

 

Regards

Al-rawachy

0 Kudos
Message 19 of 19
(2,592 Views)