generating sine-like waveforms

hello everybody,

are there any _simple_ ways of generating a sine waveform, maybe from a reference pulse/saw/triangle signal?

(Thanks to Ray :) I know that there are more complicated ways of doing this, but for now i am interested in the simplest possible way for getting something that looks like a sine.

actually, i am also interested on algorithms for generating any type of periodic signals (both low and high on harmonics) that works well in FPGAs. Jitter and variations are ok (in fact, they are welcome up to some degree).

(for the record, it will be used for sound synthesis)

regards, -Burns

Reply to
burn.sir
Loading thread data ...

What about lookup-tables? After D/A conversion one should get a sine-like signal.

Ralf

Reply to
Ralf Hildebrandt

Simple accumulator (DDS - nothing fancy) and a DAC.

If you want to be simpler, there's a huge number of parameters that determine what's "good" and what isn't. Is the frequency variable across a huge range? Many Decades or half an octave? What kind of harmonics are permitted? ...the purer, the tougher. Noise floor? Power supply rejection? Modulation rate? How about a VCO with a voltage-tuned filter? Maybe just a bunch of resistors from a few output?

There's just too much not known about what's considered "good" for your needs.

Reply to
John_H

wow, that was one quick answer :)

Nop, sorry. LUTs wont do. Too much logic for linear-filtering and the result is still crappy, IMO. There is no D/A, every thing is pure digital. The LUT solution would make it "too" pure.

I was thinking of something like a unstable feedback loop that hopefully doesnt require a multiplier/divider to work.

I had another idea about simple filtering (e.g. next=current + target/2) of a pulse wave, but cant adjust the frequency for it.

-bruns

Ralf Hildebrandt wrote:

Reply to
burn.sir

snipped-for-privacy@gmail.com a écrit :

Hi I once made a _very_ crude sin & cos generator (for short simulations) with only 2 adders :

... signal c, s : signed(SIZE-1 downto 0); ... process (clk, rst) variable ds, dc : signed(SIZE-1 downto 0); begin if rst = '1' then c

Reply to
Nicolas Matringe

Its for sound synthesis, not radar. And its for a hobby project, not job related. Hence, I am looking for the quick and dirty solution for now. If this was serious stuff, I would use DSP blocks or cordic algorithms :)

Frequency range is 40 to 96K Hz, resolution is 12 bits for now (24-32 internal). The sampling frequency is low enough to serialize multipliers for this, but i wanted to check if there were any other solutions first.

No power supply problems, the signal is digital all the way (no DAC). Neither is noise a problem, as long as it is random (thats why i don't like lookup tables).

I have a pulse and a sawtooth running at the same frequency. Is there any way i can use them for this? i can multiply their frequency by a power of two by simple bit-shifting...

bruns

John_H wrote:

Reply to
burn.sir

There are schemes for choosing ladder-style DAC resistor values such that an output ramp generates a sine wave. A quick google turned up a similar idea with illustration at:

formatting link

I seem to recall a recent thread on one of the electronics newsgroups where someone had written a program to select optimal resistor values for this sort of thing.

--
Ben Jackson AD7GD

http://www.ben.com/
Reply to
Ben Jackson

Use a Numerically Controlled Oscillator(NCO). All it really is an 'n' bit accumulator that accumulates phase. The range of the accumulator represents one complete cycle of the waveform you are generating. I.e.

0-360 degrees, or 0 to 2pi. Then use the 'm' most significant bits of the phase(accumulator) to address into a LUT or BRAM lookup table containing the waveform shape.

The phase accumulator clock frequency sets the output jitter. Higher the clock, less jitter. If you want a constant frequency, then accumulate a constant phase each cycle. This constant sets your output frequency.

'n' controls the frequency resolution. I guess 'm' controls the "accuracy" of your waveform shape.

If you want a square wave you don't even need the waveform lookup table, just use the most significant bit.

Reply to
Andrew FPGA

Thats a nice one. It works really well with floating points:

formatting link

the problem is the frequency parameter calculation (your "magic" 8 here).

maybe I can use a clock-enable to vary frequency and do some sort of interpolation on top of that?

Nicolas Matr> snipped-for-privacy@gmail.com a =E9crit :

Reply to
burn.sir

Look for the Xilinx DDS core. If I remember right, you could use it even with Webpack

--
Uwe Bonnes                bon@elektron.ikp.physik.tu-darmstadt.de

Institut fuer Kernphysik  Schlossgartenstrasse 9  64289 Darmstadt
 Click to see the full signature
Reply to
Uwe Bonnes

So you want a full scale, 12-bit, digital output, unpure sinewave with 72 dB harmonic rejection? The frequency range you specified is for analog sample rate, correct? What analog frequency range do you want to produce? Do you want to modulate it at a high rate? What's your system sample rate?

I thing I saw IIRs used for sin/cos generation in an oscillator-like configuration in a textbook 20 years ago, but outside of that there aren't any magic bullets. Perhaps a LUT with super-pure output can be dirtied by adding pseudorandom dither? Perhaps a tiny LUT with simple interpolation? The main clock rate to audio sample rate should give you ample calculation time. Heck - you could even do a taylor series expansion and do it all with multiplies using a DDS accumulator as the phase source.

Reply to
John_H

That sounds a bit like a Goertzel filter (IIR) which does require a multiplier to work:

formatting link

A CORDIC circuit could probably do the job, though requires approximately as many cycles per output as bits of precision you need. No multiplier though.

Cheers,

Andy.

Reply to
Andy Ray

yes, look at the other posts in this thread.

Been there, done that. For physcoacoustic reasons, it doesnt sound "right". The missing higher harmonics are much larger than you can burry in noise. And you will have other problems at the highest and the lowest pitches.

Of course, it depends on how large your LUT is. But I really didnt want to do wavetables in the first place.

Yes, ~300 clocks per sample is a lot of time...

regards, -Burns

Reply to
burn.sir

yes, look at the other posts in this thread.

Been there, done that. For physcoacoustic reasons, it doesnt sound "right". The missing higher harmonics are much larger than you can burry in noise. And you will have other problems at the highest and the lowest pitches.

Of course, it depends on how large your LUT is. But I really didnt want to do wavetables in the first place.

Yes, ~300 clocks per sample is a lot of time...

regards, -Burns

Reply to
burn.sir

"The missing higher harmonics are much larger than you can [bury] in noise."

What in the heck are you asking for here? Dirty sinewaves have harmonics. You suggest you want 72dB (i.e. full) supression of harmonics. Then the missing harmonics are too high? What lower amplitude - in dB full scale - do you need your missing harmonics to be so they aren't too high?

I'd love to help but it sounds like you don't have a clue what you really want. If you do, I certainly haven't gotten a clue what your true need is.

Reply to
John_H

Seems a very sweeping statement - lookup tables have many forms, and so long as they can get to under you noise floor, and with a spectrum outside the band of interest, they should be valid.

It might be better to analyse how large a LUT needs to be, for a given TT quantize in Time, and VV quantize in Voltage, to achieve the desired noise floor.

We've used Triangle waves (up/Down counters) to generate Sine, as the triangle is the closest to sine, so gives smaller tables.

It's a while ago, but I also did some checks on the ideal Time quantize for lowest distortion : ie you choose the dT level not by binary, or angle values, but by what gives the lowest distortion thru a table. From memory, that was close to matching the slopes of Triangle and sine, so that the LUT errors in the straightest portions of sine, were minimized.

A table in a FPGA could easily fetch multiple items, still with very simple support logic.

Voltage LUT is the primary content, but you could have LUT for dT, to control the width of each dV step (thus saving dV precision), and even a third table for INC rate, if you want to move from Step-Tables, to Slope tables.

-jg

Reply to
Jim Granville

Try a google search for "Magic Sinewaves"

Reply to
Mike Harrison

snipped-for-privacy@gmail.com a écrit :

You have to use some maths to calculate this but I didn't have time to do it, and it was enough for me like that. The magic '8' just came out as I typed my reply, it probably isn't very good.

Nicolas

Reply to
Nicolas Matringe

Dear John,

Lets have a more constructive discussion instead of insulting each other.

Lets assume I already have a running counter with the right frequency.

frequencies, to construct a sinewave. Or I can take any bit of the counter, which gives me a pulse wave that i can filter to get a sinewave. There are also other solutions involving unstable feedback loos and such.

All of these cost a lot of hardware, specially if you need 1000+ sine generators to do additive synthesis. I was hoping someone could come up with a quick and dirty variation that doesn't take so much area. Some of the guys on this NG suggested some very interesting ways of generating sine-like waveforms which i am looking into right now. [BIG thanks guys!]

Now lookup tables have some other problems. To understand this, you must first put away your engineering hat and put on your sound technician/psycho-acoustic hat because some of the lingo is not mathematically correct:

Unless you can do some fancy interpolation, your LUT will generate really bad waveforms at the lower frequencies. The way brain interprets your sine (which if it was perfect, would be a first harmonic with no overtones) with a slight frequency modulation (which gives you a lot of unnatural overtones). Or the brain thinks it hears the remaining of a heavily filtered signal and tries to insert its best-guest overtones and sometimes even a fundamental frequency. [this is subject to research and somewhat disputed].

Of course, you could try to bury the "missing" or "extra" harmonics in noise so the brain doesn't freak out. But that has proven out to be hard. Maybe thats why listening to badly compressed music or speech will make your head hurt.

So basically, relative to the amount of memory it requires, the LUT solution doesn't work so well.

regards, - Burns

Reply to
burn.sir

snipped-for-privacy@gmail.com wrote: ...

You talk of audio frequencies. For a DDS, then Sine Lookup is probably the most expensive part. But yoiu can use one Sine Look up for a lot of generatore, when you time multiplex it.

--
Uwe Bonnes                bon@elektron.ikp.physik.tu-darmstadt.de

Institut fuer Kernphysik  Schlossgartenstrasse 9  64289 Darmstadt
 Click to see the full signature
Reply to
Uwe Bonnes

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.