# LabVIEW

cancel
Showing results for
Did you mean:

Solved!
Go to solution

## Resample/ interpolate/ decimate array

Hi, I am confused about the function that I should use for my program (VI attached below). So here it is - I am using two incremental encoders to calculate semi period and from this the RPM of two gearbox shafts. The gearbox is run from the differential side with a dyno. To calculate the difference in the RPM of a shaft from the theoretical speed calculated from the motor rpm, a third encoder is used to determine the rpm of the motor. But the problem is that the shaft IRC gives 720 pulses as Semi periods but the motor IRC gives only 120 pulses. So I would like to convert this 120 to 720, i.e., get four readings between each pulse to get the equivalent. 1 to 2 of motor readings is equivalent to 1 to 6 readings of shaft IRC. I need to get the motor rpm re-sampled continuously in order to use that data to calculate the other stuff in other loops. I am not sure how to do this, so any suggestion of help would be really appreciated! 🙂 Thank you in advance!

P.S - The method that I have used in the VI to align and resample is the wrong one which needs modification.

Message 1 of 7
(2,096 Views)

## Re: Resample/ interpolate/ decimate array

First you need to fix your VI, it is full of deadlocks and race conditions.

• Your three loops cannot run in parallel, the upper two can only start when the lowest has stopped. You'll never get more than one iteration out of the upper two loops.
• Pressing "save 2" (save? OK) during a run would lock up your VI forever, because the event structure cannot be reached.
• You are resetting the various stop booleans via locals in parallel to running the loops. No telling what happens first.
• It is confusing to have several objects name  "stop", just with different letter case.
• Why is "gear" a floating point value? Ever tries to switch to gear 2.3? Gear should probably be an enum.

Resampling a signal is trivial but I wouldn't even try to implement it in your VI because of all the other issues. Can you create a small VI with only the two signals you need to align?

Message 2 of 7
(2,072 Views)

## Re: Resample/ interpolate/ decimate array

@altenbach wrote:

First you need to fix your VI, it is full of deadlocks and race conditions.

• Your three loops cannot run in parallel, the upper two can only start when the lowest has stopped. You'll never get more than one iteration out of the upper two loops.
• Pressing "save 2" (save? OK) during a run would lock up your VI forever, because the event structure cannot be reached.
• You are resetting the various stop booleans via locals in parallel to running the loops. No telling what happens first.
• It is confusing to have several objects name  "stop", just with different letter case.
• Why is "gear" a floating point value? Ever tries to switch to gear 2.3? Gear should probably be an enum.

Resampling a signal is trivial but I wouldn't even try to implement it in your VI because of all the other issues. Can you create a small VI with only the two signals you need to align?

I changed the gear value to enum and re-did the stop also, but I could not remove one of them because I need both the loops to stop at the same time. I can directly wire it but in case my number of loops increase, local variable would be simpler. Please let me know if you have any alternative to this. For the save, I will try to modify it somehow. Also, if I have to run the three loops in parallel, how do I do it? I figured out that my upper loop is wrong but as mentioned above, I need instantaneous values of resampling data. 😞 I could not figure it out at all and that's the main issue I am facing now.

I'll get 6 readings in the lower loop within the time span of 1 reading in the upper most loop. But I need the resampled reading of the upper loop at the same time I get readings in the lower loops because only then other simultaneous calculations can be done. Can you suggest me what can be done, please?

Message 3 of 7
(2,038 Views)

## Re: Resample/ interpolate/ decimate array

As I said, you need to remove the wired data dependency between the loops so they can run in parallel. Once you fixed all that, we can talk about the alignment.

Message 4 of 7
(2,036 Views)
Solution
Accepted by topic author raghav06

## Re: Resample/ interpolate/ decimate array

@raghav06

I changed the gear value to enum and re-did the stop also, but I could not remove one of them because I need both the loops to stop at the same time. I can directly wire it but in case my number of loops increase, local variable would be simpler. Please let me know if you have any alternative to this.

Use one control bool element inside Loop 1, use a read local variable of that bool element in loop 2 and loop 3

@raghav06Also, if I have to run the three loops in parallel, how do I do it? I figured out that my upper loop is wrong but as mentioned above, I need instantaneous values of resampling data. 😞 I could not figure it out at all and that's the main issue I am facing now.

I'll get 6 readings in the lower loop within the time span of 1 reading in the upper most loop. But I need the resampled reading of the upper loop at the same time I get readings in the lower loops because only then other simultaneous calculations can be done. Can you suggest me what can be done, please?

Don't do that:

You may want to read this NI article about Queues and the Producer Consumer Pattern:

http://www.ni.com/white-paper/3023/en/

Message 5 of 7
(2,019 Views)

## Re: Resample/ interpolate/ decimate array

@alexderjuengere wrote:

@raghav06

I changed the gear value to enum and re-did the stop also, but I could not remove one of them because I need both the loops to stop at the same time. I can directly wire it but in case my number of loops increase, local variable would be simpler. Please let me know if you have any alternative to this.

Use one control bool element inside Loop 1, use a read local variable of that bool element in loop 2 and loop 3

@raghav06Also, if I have to run the three loops in parallel, how do I do it? I figured out that my upper loop is wrong but as mentioned above, I need instantaneous values of resampling data. 😞 I could not figure it out at all and that's the main issue I am facing now.

I'll get 6 readings in the lower loop within the time span of 1 reading in the upper most loop. But I need the resampled reading of the upper loop at the same time I get readings in the lower loops because only then other simultaneous calculations can be done. Can you suggest me what can be done, please?

Don't do that:

You may want to read this NI article about Queues and the Producer Consumer Pattern:

http://www.ni.com/white-paper/3023/en/

Thank you! I got the idea behind it 🙂

Message 6 of 7
(2,002 Views)

## Re: Resample/ interpolate/ decimate array

@altenbach wrote:

As I said, you need to remove the wired data dependency between the loops so they can run in parallel. Once you fixed all that, we can talk about the alignment.

Thank you for the suggestion! 😄 I removed the interconnecting wires now. Do you have any other method for the resampling?

Message 7 of 7
(2,000 Views)