09-09-2009 10:00 AM - edited 09-09-2009 10:03 AM
A fun one for 9/9/9. Re/Im to Complex. I am using this particular function as an excuse to point out the power of LV's complex arithmetic (and to create some cool pictures). Even if you live and work in the "real" world, there are plenty of uses for imaginary numbers. For instance, you recall that a phasor, given by e^(i w t) = cos(wt) + i sin(wt) = Cis(wt) is a compact and effective tool for many trigonometric calculations. Converting cartesian coordinates to polar is also a snap with complex number functions.
This is also a good time to repeat altenbach's tip from the XY graph VIOTD, the XY graph will accept complex numbers directly and plot the imaginary component versus the real component. Great for polar plots. I will also make a shameless plea for my imaginary friend whom I am currently missing. And for the experts among us, am I missing something, or is there no good reason for the inputs to this function (and those similar) to be required. I am tired of wiring zeros to the Re terminal when I want a pure imaginary number.
Now to the fun part. Many of LV built-in math functions accept complex numbers. A phasor can be generated by wiring a complex number to the exponential function. This is easy to visualize, and even easy to achieve with simple trig functions. Now let's see what would happen when the phase of a phasor is given by a second phasor. You could either work through all of the sines of cosines, or just plug it in and see what happens. The following example lets you choose the number of points and two angular frequencies. What is shown is the result of taking the complex exponential of a complex exponential. A lot of complexity from some simple (to code) math. Enjoy.
Groundrules for VIOTD here.
09-09-2009 01:06 PM
Hi Darin,
attached is a version that has a default value set to 0. Maybe you want to copy the help file of the original one for your own usage and place it on your palette....
Felix
09-09-2009 01:27 PM
09-09-2009 05:18 PM - edited 09-09-2009 05:19 PM
Darin.K wrote:e^(i w t)
You can even make your own FFT as follows. 😄 Pretty simple code!
(of course it's slow, so it's just for educational use ;)).
09-09-2009 05:29 PM
altenbach wrote:
Darin.K wrote:e^(i w t)
You can even make your own FFT as follows. 😄 Pretty simple code!
(of course it's slow, so it's just for educational use ;)).
Message Edited by altenbach on 09-09-2009 03:19 PM
That is pretty cool! In this case, we'll say the first 'F' is for Finite.
09-09-2009 05:55 PM
Darin.K wrote: That is pretty cool! In this case, we'll say the first 'F' is for Finite.
I retained the name FFT to show which of the vi.lib VI it mimics. Of course it's only fast compared to paper and pencil. 😄
(To be fair, the code is not really my own, but slightly modified version of the baseline code for the fft challenge from back in 2003.)