11-10-2014 11:12 AM
Hello everyone,
I have created a VI which converts PSD value to SPL. Formula used to convert PSD to SPL is
SPL=10log(PSD/P^2) where P=2*10^-5
Problems facing:
1. Outer while loop is not terminating even if the condition is true? please refer the attachment( it has comments in block diagram to understand my VI, probe window)
2. Is my VI correct?
Please share your thoughts. Let me know if you need anymore explaination
Thanks in advance
Solved! Go to Solution.
11-10-2014 01:29 PM - edited 11-10-2014 01:31 PM
Unfortunately you (very large) screen shot doesn't actually show the logic for stopping the outside loop.
Unless the problem is caused by the decrement of the array size. If the array size is 0, it will decrement to -1 which might cause the comparison (that you don't show) to fail and keep the loop running.
Mike...
11-10-2014 01:45 PM
Its my bad, sorry for that.
My array size is not zero. I am away will attach it on wednesday
Thanks
11-12-2014 09:16 AM
I attached 'vi' and screenshot of problem.
1. Outer While loop is not terminating even though condition is true
2. Is there any direct conversion from PSD to SPL in Labview
Outer while loop keep tracks of number of channels selected. Here I am displaying mutliple signals in real time.
Inner while loop runs for (Sampling Rate * Block Length/2) times
Thanks
11-12-2014 02:00 PM
Are you sure the inner loop is stopping? The outer loop cannot stop until the inner llop has completed. The fact that the termination condition is true may simply mean that the condition was evaluated before the inner loop completed.
Since you did not save the input arrays with typical default data, we cannot run your VI. When using comparisons in while loops for stopping the loops, using Greater Than or Equal? or Less Than or Equal, depending on the logic, is much safer than just Equal? For example running the VI you posted (with empty input arrays) results in -1 at the array size -1 input to the Equal? comparisons in both loops. So neither loop will ever stop. Since you are only comparing to the size of the arrays, use a for loop with autoindexing.
Using Insert Into Array is almost always not the best way to do whatever you are trying to do and using Build Array in a loop results in multiple memory re-allocations as the array grows. Initialize the array to the final size (or something larger than the largest expected size if the exact size is not known) and use Replace Array Subset inside the loop.
(10^(-5)*2)^2 = 4E-10. Rather than recalulate this velu on every iteration of the inner loop, place a constant on the blockd diagram. Use a descriptive label or free label to describe how it is derived if that is significant. If it is necessary to calculate something which will never change while the program is running, move the calculation outside all loops.
I suspect that the code in the image below does everything you attempt to do in your VI.
Lynn
11-13-2014 10:26 AM
Thank you for elaborate explaination. It is perfectly working.
I am new to labview and I am implementing as I do in programming language (PL). Labview is different from what I do in PL. I will improve on memory efficiency areas.
11-13-2014 01:16 PM
NI has on-line tutorials available to help people get started with LabVIEW. I recommend that you work through some of them. They may help you understand the differences between LV and text-based programming languages.
Lynn