Processing an exponential function into AFG - Page 1
Forum section: electronics / beginners

author: LoveLaika
author_rank: Frequent Contributor
timestamp: January 31, 2025, 08:11:47 pm
content: I'm trying to write out a simple exponential function (y=e-t) from LabVIEW into my arbitrary function generator (Gwinstek AFG-2112). To an extent, I'm able to send it out, but it looks more like a square wave or a series of step functions rather than an analog signal, and I was wondering if I could get some help with it? I have a feeling that this is due to trying to write out an analog signal into a digital representation, but I'm at a loss on how to proceed.So, in LabVIEW, you can write out a waveform function, and it is sampled based on the number of samples you want in the waveform (#s) and the sampling rate in samples per second (Fs). The combination of those two gives you the waveform you want to send out. According to the function generator user manual linked above, for arbitrary waveforms, you are limited in the number of points and sample rate, shown below. Now, when it's transmitted to the generator, the LabVIEW functions for the device scales the data into integer values to represent the waveform within a range of [511,-511] to represent the max and min of the waveform.Given all this, how would you select appropriate values that would best showcase the exponential function that I'm trying to output? The sampling rate has to be high in order to showcase the minute changes in voltage, but being limited to 4k points, you can only sample so fast. Plus, you can't set the rate of the AWG, only the frequency (and the # of points in the waveform). How do you pick values such that it looks more like a continuous function rather than discrete values?Quote

author: inse
author_rank: Super Contributor
timestamp: January 31, 2025, 09:00:53 pm
content: Is this linked to the “delay“ thread, why have you stopped responding there?The arbitrary waveform will always look like discrete values, because it is, depends on how close you look.Stretch your function to the max samples (4k) and upload the values. The timing will then be defined by the frequency you enter and limited by the max sample rate (20MS/s) as you stated already.If you want to go faster, you will have to sacrifice resolution.Maybe reconsider the advice to get a more capable instrument (says me, owning a Agilent 33250a 😁)

author: rstofer
author_rank: Super Contributor
timestamp: January 31, 2025, 09:44:09 pm
content: Plot the function y=e^-x at Desos.com. The '^' raises the cursor so you can insert the exponent:https://www.desmos.com/calculatorThe function is probably no longer interesting beyond x=6 (y=0.002) and probably not even beyond x=4 (y = 0.018) so make a complete cycle equal to the range 0 .. 4 or 0 .. 6. Put as many data points in that range as can. Actually, one less so the function ends one cycle before it starts the next.Personally, I would try to figure what text the AWG wants to see and write a Fortran program to generate the sequence. I suppose I could use C in a pinch... I'm not sure what LabView brings to the dance. Maybe this idea isn't realizable, I don't have the AWG or LabView.ADD:And yes, the output will look like rectangles at some scale. All you can expect is to minimize the effect by using as many samples as possible.

author: LoveLaika
author_rank: Frequent Contributor
timestamp: January 31, 2025, 10:50:43 pm
content: I thought the matter from that time was settled, so it felt unnecessary to continue it. This topic was for a whole different issue. Turns out that after reading the instruction manual, I can set up a trigger to do a frequency sweep, but I can't use the trigger to enable or disable the output. I just kind of gave up on that option.Ironically, if you were to use Gwinstek's Arbitrary Waveform software, it managed to do it rather well. It's just complicated to replicate the same results in LabVIEW.I'm looking into a way by writing out their software results to a CSV file, read it with labview, and then write it out, but the results are very inconsistent in that it doesn't even match up at all. Waveform looks like it just repeats itself every millisecond. There's always something up with this software; really wish the manufacturers gave some good examples for this kind of thing.

author: Nominal Animal
author_rank: Super Contributor
timestamp: February 01, 2025, 08:36:50 am
content: The function you want to generate is actually$$y = A_\max \, e^{-t/T}$$where \$A_\max\$ is the maximum amplitude, and the value of \$y\$ at time \$t = 0\$, and \$T\$ is the time when the amplitude has fallen to \$A_\max \, e^{-1} \approx 0.367879 \, A_\max\$.In practice, you decide \$A_\max\$ (maximum amplitude), and maximum time \$t_\max\$ first. Then, assuming integer output, you choose \$T\$ such that \$y(t_\max) = 0.5\$, i.e. it has decayed to half an unit, which means all consecutive values would round to zero. Since \$0.5 = \frac{1}{2} = A_\max \, e^{-t_\max/T}\$, the solution for \$T\$ is$$T = \frac{t_\max}{\log\left(2 A_\max\right)}$$In this case, if you want \$t_\max = 4095\$ (samples) and \$A_\max = 511\$, then \$T \approx 591\$.Here is the \$y = 511 e^{-t/591}\$ for \$0 \le t \le 4095\$:(Click to embiggen)

author: LoveLaika
author_rank: Frequent Contributor
timestamp: February 04, 2025, 10:41:02 pm
content: Thanks for the reply. This was helpful. I must admit though, after digging around, I found the root of the problems was in the associated VIs provided by the manufacturer.It turns out that their VIs were totally sending the data in such a different way than expected. So, after looking at their source code and tweaking how they send out data, I got it to work. I'm now able to finally send out data just like with their waveform creation software.