how arbitray waveforms are generated - Page 1
Forum section: electronics / beginners

author: ant17
author_rank: Regular Contributor
timestamp: November 22, 2019, 11:14:46 pm
content: Hi guys i have a question thats been bugging me. I want to build a arbitrary waveform generator and have been looking at some proffesional ones. like the ones from keysight and others most of them load their arbitrary waveforms from what they call waveform memory Then to some sort dac but .My question is how are the values calculated for a given waveform for the represented digital values in memory and even in dds how the values calculated can anyone help.

author: MarkF
author_rank: Super Contributor
timestamp: November 23, 2019, 01:56:44 am
content: I'll give you a rough idea how to do it.But, the real problem comes into being able to send out the samples fast enough.- To start, you generate a table of samples that represents one period of the waveform.- Then, you will write each sample to a DAC at a fixed rate between each write.Repeating the table when you reach the end.- The rate you write the samples will determine the frequency of the waveform.- Then, the DAC output would go to an op-amp for scaling and DC offset.As an example:Consider a single cycle of a sine wave which you would write to a 8-bit DAC.Assuming a DAC like an MCP4802 which outputs a 0 to 4 volt signal.As you sequence through the table, the DAC will generate the sine wave one cycle at a time.Where writing a 0 to the DAC outputs 0 volts and writing a 255 to the DAC outputs 4 volts.The table represents one cycle of the waveform which will be repeated.You can put any waveform shape you wish to generate into the table (hence "arbitrary" waveform).Like I said, the frequency is a function of the rate you sequence through the table.There are two ways to change the frequency.- One is the rate you write each sample to the DAC.- The second, is by using a constant sample rate but skipping samples (i.e. every other sample or every third sample).- Or a combination of both depending on how fine the samples are.This works fairly well for a micro-controller to clock the samples to a DAC to generate audio frequencies. For higher frequencies, the process really needs to be done in hardware (like a AD9834 DDS chip for instance). In order to generate a frequency, you would want to have at least 10 samples per cycle. Therefore, the rate you write samples would be at least 10 times faster than the frequency you want to generate.In my opinion, arbitrary waveforms are over rated. In the majority of cases, a sine, triangle or square wave will satisfy test conditions.

author: rs20
author_rank: Super Contributor
timestamp: November 23, 2019, 01:58:41 am
content: Or use this, which has built-in memory:https://www.analog.com/en/products/ad9102.html#product-overview

author: joeqsmith
author_rank: Super Contributor
timestamp: November 23, 2019, 02:06:16 am
content: Quote from: ant17 on November 22, 2019, 11:14:46 pmLooking at your question form a completely different angle, I don't always calculate the values. Sometimes I will capture live signals with a DSO (or other means) and use that to drive the Arb. I designed my first Arb and would draw the waveforms on paper and scan them in. Nowdays, I use Labview to create the waveforms.

author: rstofer
author_rank: Super Contributor
timestamp: November 23, 2019, 02:09:54 am
content: The values are given in a waveform file. The real question is 'how is the file created?'. First, the format needs to match the file requirements but let's assume that's no big deal.As to the values: Compute them with Fortran, C or <whatever>.

author: ant17
author_rank: Regular Contributor
timestamp: November 23, 2019, 02:17:27 am
content: hi guys thanks for your reply i planned on using an fpga. With a external dac at 2Gs/s for an analog bandwidth of 400Mhz. I have seen that matlab has a function where you can make your own waveforms but something like a sawtooth. I don't understand how you know where each part of the waveform is suposed to go. Is there a formula or is it trigonometery can someone please explain

author: james_s
author_rank: Super Contributor
timestamp: November 23, 2019, 02:49:36 am
content: What do you mean where each part of the waveform is supposed to go? The samples are just stored in sequence, each is a binary number representing a voltage, you send them in sequence to the DAC and out comes your waveform. Fundamentally it's no different than playing raw uncompressed digital audio.

author: MarkF
author_rank: Super Contributor
timestamp: November 23, 2019, 02:57:42 am
content: It doesn't matter.You sample memory (table) is acircularbuffer. The last sample wraps around to the first sample.In order to avoid a discontinuity, you do not want a big amplitude difference between the last and first sample.Imagine three cycles of a repeating waveform.Then, lay a selection window of one complete cycle over the three.You can slide your window ANY where over the three cycles for your pick of one complete cycle.(You will repeat the samples when writing to the DAC. Hence, it does not matter where in the cycle your first sample starts.)

author: MarkF
author_rank: Super Contributor
timestamp: November 23, 2019, 03:03:48 am
content: If you want to be able to synchronize your output, you could output a trigger pulse on another pin when you wrap around the end of the sample memory.

author: ant17
author_rank: Regular Contributor
timestamp: November 23, 2019, 05:22:39 am
content: sorry i mean i don't understand what actually generates the point or samples in the memory for given waveform. i don't understand sorry like do you generate the waveform in somthing like matlab and then load it into memory does it happen like that

author: AG6QR
author_rank: Frequent Contributor
timestamp: November 23, 2019, 05:29:43 am
content: Quote from: ant17 on November 23, 2019, 02:17:27 amYou generate the table of values however you want and put the parts wherever you want. That's why they call it an arbitrary waveform generator.If you have a particular purpose or set of requirements that you want the waveform to meet, of course you generate the table of values to meet those requirements.

author: ant17
author_rank: Regular Contributor
timestamp: November 23, 2019, 07:10:52 am
content: so if i want to generate a sawtooth of say 400Mhz with certain period how would that be generated thanks

author: james_s
author_rank: Super Contributor
timestamp: November 23, 2019, 07:22:10 am
content: This is one of those things where if you have to ask, you're a long way from getting something workable. You generate a sawtooth like you generate any other waveform. You draw one cycle as a series of dots, the vertical position of each dot represents the value of that sample. If you want 400 MHz you have to clock the samples into the DAC at 400MHz times the number of samples, which is probably going to be 20-30 minimum. If you do the math you'll quickly see why AWGs are typically not anywhere near 400MHz.Also frequency and period are inextricably linked, it makes no sense to specify both the frequency and the period, you can't change one without changing the other.

author: ant17
author_rank: Regular Contributor
timestamp: November 23, 2019, 08:35:03 am
content: ok thanks

author: oPossum
author_rank: Super Contributor
timestamp: November 23, 2019, 08:45:19 am
content: Any periodic waveform can be created from a sum of sines. (Fourier synthesis).Sawtooth for example...https://web.njit.edu/~matveev/Courses/M331_F17/html/FourierSawToothSine.html

author: rstofer
author_rank: Super Contributor
timestamp: November 23, 2019, 05:46:24 pm
content: Attached is a plot of cos(x) in with 10 steps per waveform (blue with circles) and 100 steps per waveform (orange with dots). The difference is pretty noticeable.So, if you want a 1 MHz clean looking sine wave, you might want to sample at 100 MHz. You only need 100 values in the file but you have to clock pretty fast. If you are going to implement phase shifting, you simply start reading the file from some point other than t=0 and wrapping around.The MATLAB code looks like:Code:x=0:2*pi/10:2*pi;y=cos(x);plot(x,y,'-o')hold onx=0:2*pi/100:2*pi;y=cos(x);plot (x,y,'-.')ylabel('Cosine Function')legend('10 samples','100 samples')title('COS(x)')axis([0 2*pi -1.5 1.5])shgThe sample spacing is done here:x=0:2*pi/10:2*pi;At line 1, x is a vector starting at 0 and extending to 2*pi with intervals of 2*pi/10 or 11 samples (fence post problem). The first and last should be the same.At line 2, y is also a vector containing the cos(x) and it too has 11 values. You can see that with the blue circle at the far right end of the plot.Lines 5 & 6 do the same thing but they produce 101 samples for the orange plot.Don't have MATLAB? No problem, the code works perfectly on Octave and Octave is free. It's a very good clone of MATLAB.If you want to see the x and y values, numerically, just remove the semicolon from the end of the appropriate line (1,2,5 or 6).

author: rstofer
author_rank: Super Contributor
timestamp: November 23, 2019, 06:07:12 pm
content: Quote from: james_s on November 23, 2019, 07:22:10 amEven an 80 MHz Siglent (the maximum range my budget would allow) won't produce an 80 MHz square wave, 25 MHz is as far as it goes. I guess they don't implement it as a simple step function in the middle of the period. That SDG2082X is $619 plus shipping so AWGs get pretty expensive even for low frequencies. It samples at 1.2GSa/sThere is a lot of educational material re: the Analog Discovery 2 over at Digilent. They talk about the AWG and how it is implemented. It is only 12 MHz bandwidth with 100 MSa/s sampling:See Section 3 here:https://reference.digilentinc.com/reference/instrumentation/analog-discovery-2/reference-manualI'm pretty sure 400 MHz sounds neat when you write it down but I'm not sure it is realizable by mere mortals. With a 1 GSa/s rate, there would only be 2.5 samples per waveform. I didn't produce a plot like that but it would be pretty hideous.

author: rstofer
author_rank: Super Contributor
timestamp: November 23, 2019, 06:18:02 pm
content: Quote from: joeqsmith on November 23, 2019, 05:58:22 pmI like analog computing and simulating the suspension of a vehicle (at least one front tire) is a classic problem since it is essentially a mass-spring-damper problem and those are well understood. But what if the ground under the tire contains a chuck-hole? I have toyed with the idea of using an AWG to generate the surface. I could do this quite easily with the Analog Discovery 2. I could even model those nefarious speed bumps!Other than sheer laziness, I don't know why I haven't done it yet.AWGs could be a lot of fun to play with but I'm just guessing that the frequency is going to be a whole lot less than 400 MHz. For my suspension project, even the 12 MHz bandwidth of the Analog Discover 2 is FAR more than required. Nothing on the chassis is working in microsecond time scales. If it does, I guess we move to Euler's Method.

author: rstofer
author_rank: Super Contributor
timestamp: November 23, 2019, 06:28:26 pm
content: When creating the sample file, there would be a tendency to want to use ASCII representations of the values. Simply, these are user readable values.At some point, there needs to be logic in the FPGA to read the file, convert the values to binary and store them in a samples table in BlockRAM.It might be worth creating a small CPU core because there will be more to do than just read values. There will be some kind of UI (switches, knobs and dials). I suppose the core might as well be the Xilinx MicroBlaze since there is a set of tools for writing code in C and so forth.Generating the signal, that is, stepping through BlockRAM, grabbing the values and stuffing them into the DAC is the easiest part of the job.Coming up with a highly variable sample clock is going to be a challenge. The alternative is to use a very fast sample clock but that implies a LOT of samples for slow signals. A 1 Hz signal with a 1 GHz sample clock is going to need a billion samples. Yup! Generating the sample clock for various realizable signals and speeds is going to be a bit of work and some arithmetic.

author: gf
author_rank: Super Contributor
timestamp: November 23, 2019, 09:34:45 pm
content: Quote from: rstofer on November 23, 2019, 06:28:26 pm"Classical" DDS generators are usually based on a fixed (fast) clock.[ Some commercial AWGs use more sophisticated algorithms, though, than plain DDS, in order to overcome some limatations of DDS. ]QuoteNot really a problem, though. Just spend a sufficient number of bits for the DDS generator's accumulator and you can even generate sub-Hz signals. You don't need a waveform memory which can store a billion samples, but it can be much smaller (-> keyword "phase truncation").gf

author: ant17
author_rank: Regular Contributor
timestamp: November 23, 2019, 11:37:38 pm
content: ok thanks to all that have contributed i am going tohave to have a look at all the posts and think about it thanks agian

author: rstofer
author_rank: Super Contributor
timestamp: November 23, 2019, 11:58:57 pm
content: Quote from: gf on November 23, 2019, 09:34:45 pmAre you thinking of periodic signals? I'm not... I'm thinking of arbitrary signals with weird patterns. As a trivial example: A car moving down the road with the normal bumps and bruises followed by a chuck-hole and perhaps a curb. Periodic signals are easy, arbitrary maybe not so simple.

author: james_s
author_rank: Super Contributor
timestamp: November 24, 2019, 04:36:22 am
content: AWGs produce periodic signals, at least the few I've played with did. The shape of a cycle is arbitrary but the cycle plays repeatedly as the selected frequency. I don't actually know what people typically use them for, other than playing around I never found a need for anything other than the usual sine, square and triangle waves.

author: gf
author_rank: Super Contributor
timestamp: November 24, 2019, 09:47:42 am
content: Quote from: rstofer on November 23, 2019, 11:58:57 pmWell, the OP talked about 400MHz sawtooth, which is presumedly periodic (For a reasonable reproduction, this will require a pretty high sampling rate in the microwave range, though.)

author: rstofer
author_rank: Super Contributor
timestamp: November 24, 2019, 04:25:14 pm
content: It's common to think about repetitive waveforms but that doesn't have to be the case for an 'arbitrary' waveform. The waveform will repeat but the experiment may be over before it does.In the case of the Siglent SDG2082X, the device supports sample memory from 8 points up to 8 megapoints and sample rates from 1 uSa/s up to 75MSa/s in what they call TrueArb mode. In DDS mode the sample rate is 300 MSa/s. And then they claim a sample rate of 1.2GSa/s using 4x interpolation.TrueArb mode is point by point, every output voltage comes from sample memory.DDS will generate most common waveforms and most AWGs have a large menu of built-in waveforms. TrueArb is different in that there are discrete samples for every time tick.There is some very useful iinformation in the SDG2000 datasheet:https://mediacdn.eu/mage/media/downloads/SDG2000X_DataSheet.pdfAbout page 6, they talk about the EasyWave software which allows for manual drawing, line-drawing, equation-drawing, coordinate-drawing and so forth.User Manual:https://mediacdn.eu/mage/media/downloads/SDG2000X_UserManual.pdfStarting on page 40, there is a list of built-in functions extending for 4 pages. There are a LOT of built-ins.

author: nfmax
author_rank: Super Contributor
timestamp: November 24, 2019, 05:41:13 pm
content: Quote from: james_s on November 24, 2019, 04:36:22 amNot necessarily. You can run in 'triggered burst' mode where an external pulse causes the waveform to play, either just once or for a programmed number of repeats. Recently, I have been using this to play shaped tone bursts, designed using Matlab to have a specified bandwidth, duration, and autocorrelation function, into an ultrasonic transducer. This is what ARBs really shine at.The waveforms are only a few hundred points long. I'm using an Agilent 33522B which lets you set thewaveformsample rate to whatever you want (50 Msps in my case) while interpolating up the actual, fixed DAC sample rate of 250 Msps using a digital filter in the internal FPGA.

author: rstofer
author_rank: Super Contributor
timestamp: November 24, 2019, 06:12:28 pm
content: At some point, generating the waveform is like a side issue to all of the surrounding features. A true AWG can do a lot of really neat things.On the low end, I built a Halloween animation that was simply a skeleton rocking in a chair while snoring. The sound effect was derived from a .wav file that I ripped from somewhere and played by a PIC with an R-2R DAC. It worked really well. It's been a long time, I don't remember how I got from .wav to discrete samples but it was easy, whatever is was.

author: james_s
author_rank: Super Contributor
timestamp: November 24, 2019, 06:14:40 pm
content: A .wav file is nothing more than discrete samples with a header so it's not hard to do.

author: joeqsmith
author_rank: Super Contributor
timestamp: November 24, 2019, 06:39:24 pm
content: Quote from: rstofer on November 23, 2019, 06:18:02 pmI need sub 1 MHz for the simulator. I will collect data off the real setup and feed that into the simulator. It was a fun and useful project. Video showing the basics.https://youtu.be/q_89qoFMivg?list=PLZSS2ajxhiQBvWvqMVLdRQMjGofKpQUJr&t=2202Quote from: rstofer on November 24, 2019, 04:25:14 pmTrue. Running a test right now doing just that.

author: rstofer
author_rank: Super Contributor
timestamp: November 24, 2019, 09:09:48 pm
content: Quote from: james_s on November 24, 2019, 06:14:40 pmSomething along the lines of 'dump the header' and 'keep the samples'. It's been about 15 years and I'm getting old...

author: ant17
author_rank: Regular Contributor
timestamp: November 24, 2019, 09:17:21 pm
content: hi guys thanks so much for all input every body has contributed. i feel like i have been flooded with information i am really going to have to take my time in reading all carefully so thanks so much to all who have contributed to this discussion thanks after i have read it and understood it i will post any questions i have thanks again

author: rstofer
author_rank: Super Contributor
timestamp: November 24, 2019, 09:37:14 pm
content: Quote from: joeqsmith on November 24, 2019, 06:39:24 pmInteresting project and very well done!

author: ant17
author_rank: Regular Contributor
timestamp: November 25, 2019, 05:12:36 am
content: hi guys thanks for all your input cany anyone suggest fpga development board to get experimenting i was thinking a zynq 7000 series fpga development board or other suggested developments with most room to experiment with arbitrary waves

author: james_s
author_rank: Super Contributor
timestamp: November 25, 2019, 08:17:49 pm
content: It doesn't really matter, any FPGA will get you started, you can go a long way before you start pushing the performance envelope.How much experience do you have with FPGA development? To say the learning curve is steep would be an understatement.

author: ant17
author_rank: Regular Contributor
timestamp: November 25, 2019, 09:38:31 pm
content: i have had experience with with a lattice semiconuductor PLD development board it was just a programmable logic device.programmed with hardware description language made at a basic electronics school, about 20 years ago not a fpga so i am a novice.

author: james_s
author_rank: Super Contributor
timestamp: November 25, 2019, 10:33:36 pm
content: Well that's more than most. Either way first step is start learning either VHDL or Verilog, the FPGA choice isn't too important until you have a working prototype.

author: rstofer
author_rank: Super Contributor
timestamp: November 25, 2019, 10:58:34 pm
content: You might check in over at NandLand.com The tutorials are excellent and he offers a reasonably priced FPGA board for his projects.Notice that there are tutorials in both VHDL and Verilog.

author: ant17
author_rank: Regular Contributor
timestamp: November 25, 2019, 11:43:25 pm
content: thank you