Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!gem.mps.ohio-state.edu!apple!motcsd!hpda!hpcuhc!edwardm From: edwardm@hpcuhc.HP.COM (Edward McClanahan) Newsgroups: comp.dsp Subject: Re: Sine curve fit algorithms Message-ID: <9630001@hpcuhc.HP.COM> Date: 29 Sep 89 00:39:03 GMT References: <2421@radio.oakhill.UUCP> Organization: Hewlett Packard, Cupertino Lines: 35 Wm Randolph Franklin writes: > In <2421@radio.oakhill.UUCP> charlie@oakhill.UUCP (Charlie Thompson) writes: > >I am looking for C source code for sine wave curve fitting algorithms. Such > >an algorithm can be used to compute THD/Noise in a digitized sine wave. He goes on to discuss fast ways to compute sines of angles. First of all, I don't know how Charlie is computing THD/Noise in a digitized sine wave, but it doesn't sound like he is trying to generate a sine wave. Maybe I'm all wet. Maybe he knows the "exact" frequency and amplitude and all he needs to do is quickly calculate the sine wave. If it has a constant freq/amp, then it is far easier to simply step through a table. In fact, even if the frequency is different (than the one in your lookup table), you just change your step size. Finally, even if the amplitude is different (than the one in your lookup table), you can easily scale the values read from the table by: 1 - A quick multiplication (if that operation is quick enough), or 2 - Use a sine function rule which states: sin(a-b) + sin(a+b) = f(b) * sin(a) where a is the current angle you are trying to compute the sine value of and b is a constant "delta" (hence f(b) is also a constant). Sorry, I don't know what the formula for f(b) is off the top of my head. It can be derived quite easily, however. If there is any interest, I can look it up... =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Edward McClanahan Hewlett Packard Company Mail Stop 47UE -or- edwardm%hpda@hplabs.hp.com 19447 Pruneridge Avenue Cupertino, CA 95014 Phone: (408)447-5651