From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

While loop or buffer while in simulation loop

Solved!
Go to solution

Hello, 

 

I am trying to compute an FFT calculation every 0.1 ms on a incoming signal. This signal is being fed through a design in multisim, and the FFT is being preformed on the voltage and current to calculate a Nyquist.

 

In matlab, storing the values of a signal to pass through the FFT block is done simply with a buffer. In labview it seems near impossible.

 

Any help would be appreciated! 

 

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

Can you give a simple code example VI and use comments perhaps to show what the problem is?

 

Do you have something that works but is too slow?


GCentral
0 Kudos
Message 2 of 14
(3,916 Views)

See the other discussion with the same question.


GCentral
0 Kudos
Message 3 of 14
(3,898 Views)

Here is the VI, I just cannot loop the FFT function to occur ever 0.1 ms 

0 Kudos
Message 4 of 14
(3,886 Views)

If you want the FFT to occur during the simulation, place it inside the simulation loop. If you have a step size smaller than 0.1 ms and you don't want it to occur every case, use a Case Structure.

 

If you need to buffer a bunch of points from subsequent iterations of the Control and Sim loop between iterations where you want to use the FFT, use a Shift Register and Build Array. Reset the array when you take the FFT.


GCentral
0 Kudos
Message 5 of 14
(3,882 Views)

Ok, scratch all of the above. Working on it 😉

 

Replace "Shift Register" with "Memory" and we're pretty much good.

The VI I'm uploading has no logic - you need to implement that, and do something with the FFT. It should otherwise do what you want.


GCentral
0 Kudos
Message 6 of 14
(3,877 Views)

hmm seems like it should work, I've updated the code with the Nyquist plot below, however I'm getting an error saying that case structures are not allowed within the simulation loop..  

 

simulation_loop.png

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

I don't think the problem is the case structure - I think it's that you've put the Nyquist plot inside the case structure.

 

See this article: Block diagram terminals are not allowed inside Case structures on simulation diagrams.

 

You can probably work around it by using another Memory block, and writing the graph every iteration. Move the graph outside of the case structure, and send the plot out of the True case, into the Memory, and then back into the case structure, where you can wire it straight through the False case. Then, it will only change in the True case, when you make a new FFT measurement.


GCentral
0 Kudos
Message 8 of 14
(3,839 Views)

hmm okay I have the real and imaginary parts of the Nyquist plot coming out okay. I use the memory block to output the results every 0.1 seconds discretely. (there should only be 1 real and imaginary component every 0.1 sec)

 

However I still cant seem to get the FFT to perform every 0.1 sec which is making the output Nyquist incorrect. Am I supposed to be switching the case structure on and off every 0.1 seconds in the simulation? I am unclear on how the memory blocks are working with the case structure 

 

simulation_loop.png

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

The Memory blocks act like a Shift Register - they are building an array of Y values which once every so often (so yes, make the boolean true every 0.1ms for example, not with a control) is passed to the FFT function. The rest of the time (for example, when the iteration time is 0.00008, 0.00009) it just adds a new element to the array. When it reaches 0.0001, it should trigger the True case and carry out the FFT.

 

I don't know what the Img functions do and I don't have the Simulation toolkit available right now, but it might be that you can use those. Did my suggestion before involving a 3rd Memory block lead to a broken wire complaining about direct feedback cycles? 


GCentral
0 Kudos
Message 10 of 14
(3,822 Views)