Electronics-Related.com
Forums

LT Spice FFT scaling

Started by John Larkin July 9, 2018
On 07/10/18 13:26, John Larkin wrote:
> On Tue, 10 Jul 2018 09:28:02 -0400, Phil Hobbs > <pcdhSpamMeSenseless@electrooptical.net> wrote: > >> On 07/09/18 22:53, Jim Thompson wrote: >>> On Mon, 09 Jul 2018 17:00:27 -0700, John Larkin >>> <jjlarkin@highland_snip_technology.com> wrote: >>> >>>> On Mon, 09 Jul 2018 16:47:06 -0700, Jim Thompson >>>> <To-Email-Use-The-Envelope-Icon@On-My-Web-Site.com> wrote: >>>> >>>>> On Mon, 09 Jul 2018 16:03:54 -0700, John Larkin >>>>> <jjlarkin@highland_snip_technology.com> wrote: >>>>> >>>>>> On Mon, 09 Jul 2018 13:06:15 -0700, boB <boB@K7IQ.com> wrote: >>>>>> >>>>>>> On Mon, 09 Jul 2018 12:00:24 -0700, John Larkin >>>>>>> <jjlarkin@highland_snip_technology.com> wrote: >>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> Suppose I create a current source that's a sine wave, amplitude 1, >>>>>>>> frequency 1, and then run a transient response. Then plot current and >>>>>>>> FFT. On a linear scale, it has some harmonics (no surprise) but the >>>>>>>> amplitude of the fundamental is 690 mA. >>>>>>>> >>>>>>>> Why 690? Is that a bad approximation of 707? >>>>>>>> >>>>>>>> Update: if I set the time step to 10 us, it runs slow but the FFT >>>>>>>> amplitude is 706.9 mA. So the FFT reports RMS. >>>>>>> >>>>>>> >>>>>>> Try it also with the alternate solver ? Will probably be the same as >>>>>>> decreasing the step size though I imagine. Not a lot to go wrong... >>>>>>> go wrong.... go wrong... >>>>>> >>>>>> It's just a sinewave current source. There's really nothing to solve! >>>>>> I think LT Spice just picks an ambitiously small delta-T by default. >>>>> >>>>> Nope. It's a cockpit set-up error >:-} >>>>> >>>>> ...Jim Thompson >>>> >>>> There's no operator error at all. LT Spice gives one a choice of >>>> solver, a choice of dt, and several other params to tweak to trade off >>>> speed against accuracy. What's wrong with that? >>>> >>>> I needed to know what units the FFT uses when it displays current. The >>>> answer is RMS amps. Sinewave sources, voltage or current, use peak >>>> amps. >>> >>> Except that the waveform simulated is NOT sin(wt), it's >>> u_1(t)*sin(wt). >>> >>> From which the DC offset arises. >>> >>> ...Jim Thompson >>> >> >> The DFT/FFT only applies to periodic sequences. For a sequence periodic >> in the FFT interval and having compact support in the frequency domain, >> the FFT produces correct samples of the underlying continuous-time >> transform. >> >> Real data, or in this case interpolated simulation data, doesn't fit >> those conditions exactly, which leads to errors. It's not very >> difficult to compute an error bound in any given case. >> >> Cheers >> >> Phil Hobbs > > I tried a couple of windowing functions (there is a huge list > available) but they didn't change the FFT much. Smaller time steps > really do.
Yup. With that many cycles, the window function just smears out the peaks by a few bins. The interpolation problem remains. Using smaller time steps improves the interpolation accuracy by some power like deltaT**3 depending on the method. Cheers Phil Hobbs -- Dr Philip C D Hobbs Principal Consultant ElectroOptical Innovations LLC / Hobbs ElectroOptics Optics, Electro-optics, Photonics, Analog Electronics Briarcliff Manor NY 10510 http://electrooptical.net http://hobbs-eo.com
On Mon, 9 Jul 2018 23:16:12 -0400, bitrex <user@example.net> wrote:

>On 07/09/2018 11:09 PM, bitrex wrote: >> On 07/09/2018 08:00 PM, John Larkin wrote: >>> On Mon, 09 Jul 2018 16:47:06 -0700, Jim Thompson >>> <To-Email-Use-The-Envelope-Icon@On-My-Web-Site.com> wrote: >>> >>>> On Mon, 09 Jul 2018 16:03:54 -0700, John Larkin >>>> <jjlarkin@highland_snip_technology.com> wrote: >>>> >>>>> On Mon, 09 Jul 2018 13:06:15 -0700, boB <boB@K7IQ.com> wrote: >>>>> >>>>>> On Mon, 09 Jul 2018 12:00:24 -0700, John Larkin >>>>>> <jjlarkin@highland_snip_technology.com> wrote: >>>>>> >>>>>>> >>>>>>> >>>>>>> Suppose I create a current source that's a sine wave, amplitude 1, >>>>>>> frequency 1, and then run a transient response. Then plot current and >>>>>>> FFT. On a linear scale, it has some harmonics (no surprise) but the >>>>>>> amplitude of the fundamental is 690 mA. >>>>>>> >>>>>>> Why 690? Is that a bad approximation of 707? >>>>>>> >>>>>>> Update: if I set the time step to 10 us, it runs slow but the FFT >>>>>>> amplitude is 706.9 mA. So the FFT reports RMS. >>>>>> >>>>>> >>>>>> Try it also with the alternate solver ?&#4294967295; Will probably be the same as >>>>>> decreasing the step size though I imagine.&#4294967295; Not a lot to go wrong... >>>>>> go wrong.... go wrong... >>>>> >>>>> It's just a sinewave current source. There's really nothing to solve! >>>>> I think LT Spice just picks an ambitiously small delta-T by default. >>>> >>>> Nope.&#4294967295; It's a cockpit set-up error >:-} >>>> >>>> &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295; ...Jim Thompson >>> >>> There's no operator error at all. LT Spice gives one a choice of >>> solver, a choice of dt, and several other params to tweak to trade off >>> speed against accuracy. What's wrong with that? >>> >>> I needed to know what units the FFT uses when it displays current. The >>> answer is RMS amps. Sinewave sources, voltage or current, use peak >>> amps. >>> >> >> I think I see the problem. How many cycles at 1 Hz did you let the >> simulation run for? If you set the transient sim to 1 second at 1 Hz it >> hits 707 mA on the linear FFT just about on the money. 10 seconds, it's >> worse. 100 seconds a lot worse. >> >> Floating point roundoff errors are accumulating cycle by cycle and a >> small step size makes it worse.
Except, of course, that setting a smaller step size make the FFT better. The sine is starting at 0 amplitude at 0
>> seconds, but after "exactly" say 100 cycles it's not ending there. And >> the end-point error is throwing off the RMS calculation. >> > >That is to say if you are seeing higher harmonics at all then by >Parseval's theorem/energy conservation the fundamental definitely cannot >have its mathematically ideal pure sinewave maximum amplitude.
The physical universe has to conserve energy. A computer simulation doesn't. -- John Larkin Highland Technology, Inc picosecond timing precision measurement jlarkin att highlandtechnology dott com http://www.highlandtechnology.com
On 07/10/2018 01:33 PM, John Larkin wrote:
> On Mon, 9 Jul 2018 23:16:12 -0400, bitrex <user@example.net> wrote: > >> On 07/09/2018 11:09 PM, bitrex wrote: >>> On 07/09/2018 08:00 PM, John Larkin wrote: >>>> On Mon, 09 Jul 2018 16:47:06 -0700, Jim Thompson >>>> <To-Email-Use-The-Envelope-Icon@On-My-Web-Site.com> wrote: >>>> >>>>> On Mon, 09 Jul 2018 16:03:54 -0700, John Larkin >>>>> <jjlarkin@highland_snip_technology.com> wrote: >>>>> >>>>>> On Mon, 09 Jul 2018 13:06:15 -0700, boB <boB@K7IQ.com> wrote: >>>>>> >>>>>>> On Mon, 09 Jul 2018 12:00:24 -0700, John Larkin >>>>>>> <jjlarkin@highland_snip_technology.com> wrote: >>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> Suppose I create a current source that's a sine wave, amplitude 1, >>>>>>>> frequency 1, and then run a transient response. Then plot current and >>>>>>>> FFT. On a linear scale, it has some harmonics (no surprise) but the >>>>>>>> amplitude of the fundamental is 690 mA. >>>>>>>> >>>>>>>> Why 690? Is that a bad approximation of 707? >>>>>>>> >>>>>>>> Update: if I set the time step to 10 us, it runs slow but the FFT >>>>>>>> amplitude is 706.9 mA. So the FFT reports RMS. >>>>>>> >>>>>>> >>>>>>> Try it also with the alternate solver ?&nbsp; Will probably be the same as >>>>>>> decreasing the step size though I imagine.&nbsp; Not a lot to go wrong... >>>>>>> go wrong.... go wrong... >>>>>> >>>>>> It's just a sinewave current source. There's really nothing to solve! >>>>>> I think LT Spice just picks an ambitiously small delta-T by default. >>>>> >>>>> Nope.&nbsp; It's a cockpit set-up error >:-} >>>>> >>>>> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ...Jim Thompson >>>> >>>> There's no operator error at all. LT Spice gives one a choice of >>>> solver, a choice of dt, and several other params to tweak to trade off >>>> speed against accuracy. What's wrong with that? >>>> >>>> I needed to know what units the FFT uses when it displays current. The >>>> answer is RMS amps. Sinewave sources, voltage or current, use peak >>>> amps. >>>> >>> >>> I think I see the problem. How many cycles at 1 Hz did you let the >>> simulation run for? If you set the transient sim to 1 second at 1 Hz it >>> hits 707 mA on the linear FFT just about on the money. 10 seconds, it's >>> worse. 100 seconds a lot worse. >>> >>> Floating point roundoff errors are accumulating cycle by cycle and a >>> small step size makes it worse. > > Except, of course, that setting a smaller step size make the FFT > better. > > > The sine is starting at 0 amplitude at 0 >>> seconds, but after "exactly" say 100 cycles it's not ending there. And >>> the end-point error is throwing off the RMS calculation. >>> >> >> That is to say if you are seeing higher harmonics at all then by >> Parseval's theorem/energy conservation the fundamental definitely cannot >> have its mathematically ideal pure sinewave maximum amplitude. > > The physical universe has to conserve energy. A computer simulation > doesn't. > >
That total signal energy is conserved when taking the Fourier transform is implied by the mathematical fact that the Fourier transform is a unitary transform. It has to behave that way in a computer simulation as well or it's not the Fourier transform!
On 07/10/2018 08:41 AM, Phil Hobbs wrote:
> On 07/09/18 15:00, John Larkin wrote: >> >> >> Suppose I create a current source that's a sine wave, amplitude 1, >> frequency 1, and then run a transient response. Then plot current and >> FFT. On a linear scale, it has some harmonics (no surprise) but the >> amplitude of the fundamental is 690 mA. >> >> Why 690? Is that a bad approximation of 707? >> >> Update: if I set the time step to 10 us, it runs slow but the FFT >> amplitude is 706.9 mA. So the FFT reports RMS. > > LTspice, like most simulators apart from FDTD EM simulators, uses a > variable time step.&nbsp; That means that it has to interpolate to get > regularly-spaced samples for the FFT.&nbsp; That interpolation introduces > significant amounts of truncation error, which is probably what's > responsible for both the harmonics and the reduced fundamental. > > Cheers > > Phil Hobbs > >
the fact that the fundamental is 690 instead of 707 is not a "bad approximation" it's a perfectly valid and correct Fourier transform of some other sequence of samples generated through a given interpolation algorithm, that's not a mathematically abstract pure sine wave. SPICE doesn't "know" anything about sine waves or that they should be treated any different than any other random sequence of samples. The implication by the OP seems to be that the FFT in LTSpice is somehow a wrong or "sloppy" implementation, maybe so but I don't think that follows from the observed symptoms at all.
On Tue, 10 Jul 2018 17:10:54 -0400, bitrex <user@example.net> wrote:

>On 07/10/2018 01:33 PM, John Larkin wrote: >> On Mon, 9 Jul 2018 23:16:12 -0400, bitrex <user@example.net> wrote: >> >>> On 07/09/2018 11:09 PM, bitrex wrote: >>>> On 07/09/2018 08:00 PM, John Larkin wrote: >>>>> On Mon, 09 Jul 2018 16:47:06 -0700, Jim Thompson >>>>> <To-Email-Use-The-Envelope-Icon@On-My-Web-Site.com> wrote: >>>>> >>>>>> On Mon, 09 Jul 2018 16:03:54 -0700, John Larkin >>>>>> <jjlarkin@highland_snip_technology.com> wrote: >>>>>> >>>>>>> On Mon, 09 Jul 2018 13:06:15 -0700, boB <boB@K7IQ.com> wrote: >>>>>>> >>>>>>>> On Mon, 09 Jul 2018 12:00:24 -0700, John Larkin >>>>>>>> <jjlarkin@highland_snip_technology.com> wrote: >>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> Suppose I create a current source that's a sine wave, amplitude 1, >>>>>>>>> frequency 1, and then run a transient response. Then plot current and >>>>>>>>> FFT. On a linear scale, it has some harmonics (no surprise) but the >>>>>>>>> amplitude of the fundamental is 690 mA. >>>>>>>>> >>>>>>>>> Why 690? Is that a bad approximation of 707? >>>>>>>>> >>>>>>>>> Update: if I set the time step to 10 us, it runs slow but the FFT >>>>>>>>> amplitude is 706.9 mA. So the FFT reports RMS. >>>>>>>> >>>>>>>> >>>>>>>> Try it also with the alternate solver ?&#4294967295; Will probably be the same as >>>>>>>> decreasing the step size though I imagine.&#4294967295; Not a lot to go wrong... >>>>>>>> go wrong.... go wrong... >>>>>>> >>>>>>> It's just a sinewave current source. There's really nothing to solve! >>>>>>> I think LT Spice just picks an ambitiously small delta-T by default. >>>>>> >>>>>> Nope.&#4294967295; It's a cockpit set-up error >:-} >>>>>> >>>>>> &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295; ...Jim Thompson >>>>> >>>>> There's no operator error at all. LT Spice gives one a choice of >>>>> solver, a choice of dt, and several other params to tweak to trade off >>>>> speed against accuracy. What's wrong with that? >>>>> >>>>> I needed to know what units the FFT uses when it displays current. The >>>>> answer is RMS amps. Sinewave sources, voltage or current, use peak >>>>> amps. >>>>> >>>> >>>> I think I see the problem. How many cycles at 1 Hz did you let the >>>> simulation run for? If you set the transient sim to 1 second at 1 Hz it >>>> hits 707 mA on the linear FFT just about on the money. 10 seconds, it's >>>> worse. 100 seconds a lot worse. >>>> >>>> Floating point roundoff errors are accumulating cycle by cycle and a >>>> small step size makes it worse. >> >> Except, of course, that setting a smaller step size make the FFT >> better. >> >> >> The sine is starting at 0 amplitude at 0 >>>> seconds, but after "exactly" say 100 cycles it's not ending there. And >>>> the end-point error is throwing off the RMS calculation. >>>> >>> >>> That is to say if you are seeing higher harmonics at all then by >>> Parseval's theorem/energy conservation the fundamental definitely cannot >>> have its mathematically ideal pure sinewave maximum amplitude. >> >> The physical universe has to conserve energy. A computer simulation >> doesn't. >> >> > >That total signal energy is conserved when taking the Fourier transform >is implied by the mathematical fact that the Fourier transform is a >unitary transform. It has to behave that way in a computer simulation as >well or it's not the Fourier transform!
The it's not. The LT Spice FFT clearly has spectral lines coming from a pure sine wave current source. -- John Larkin Highland Technology, Inc picosecond timing precision measurement jlarkin att highlandtechnology dott com http://www.highlandtechnology.com
On Tue, 10 Jul 2018 17:27:54 -0400, bitrex <user@example.net> wrote:

>On 07/10/2018 08:41 AM, Phil Hobbs wrote: >> On 07/09/18 15:00, John Larkin wrote: >>> >>> >>> Suppose I create a current source that's a sine wave, amplitude 1, >>> frequency 1, and then run a transient response. Then plot current and >>> FFT. On a linear scale, it has some harmonics (no surprise) but the >>> amplitude of the fundamental is 690 mA. >>> >>> Why 690? Is that a bad approximation of 707? >>> >>> Update: if I set the time step to 10 us, it runs slow but the FFT >>> amplitude is 706.9 mA. So the FFT reports RMS. >> >> LTspice, like most simulators apart from FDTD EM simulators, uses a >> variable time step.&#4294967295; That means that it has to interpolate to get >> regularly-spaced samples for the FFT.&#4294967295; That interpolation introduces >> significant amounts of truncation error, which is probably what's >> responsible for both the harmonics and the reduced fundamental. >> >> Cheers >> >> Phil Hobbs >> >> > >the fact that the fundamental is 690 instead of 707 is not a "bad >approximation" it's a perfectly valid and correct Fourier transform of >some other sequence of samples generated through a given interpolation >algorithm, that's not a mathematically abstract pure sine wave. SPICE >doesn't "know" anything about sine waves or that they should be treated >any different than any other random sequence of samples. > >The implication by the OP seems to be that the FFT in LTSpice is somehow >a wrong or "sloppy" implementation, maybe so but I don't think that >follows from the observed symptoms at all.
That's your implication, not mine. I didn't use your terms "wrong" or "sloppy." 690 is a fairly bad approximation of 707. I did note that the default settings of LT Spice had the FFT fundamental spectral line amplitude at 690 mA, and lots of harmonics. And that setting a small time step improves things greatly. What's wrong with that? -- John Larkin Highland Technology, Inc picosecond timing precision measurement jlarkin att highlandtechnology dott com http://www.highlandtechnology.com
On 07/10/2018 03:03 AM, Martin Brown wrote:
> On 09/07/2018 20:00, John Larkin wrote: >> >> >> Suppose I create a current source that's a sine wave, amplitude 1, >> frequency 1, and then run a transient response. Then plot current and >> FFT. On a linear scale, it has some harmonics (no surprise) but the >> amplitude of the fundamental is 690 mA. >> >> Why 690? Is that a bad approximation of 707? > > Very probably. > > If you want to get a better approximation relatively cheaply then use > three simulations to compute it for 2dt, dt, dt/2 and use Richardson > extrapolation to remove the leading error term. > > https://en.wikipedia.org/wiki/Richardson_extrapolation >> >> Update: if I set the time step to 10 us, it runs slow but the FFT >> amplitude is 706.9 mA. So the FFT reports RMS. > > <sin^2(x)> = 1/2 > > Hence amplitude = 1/sqrt(2) > > It is common in numerical FFTs for the scaling to be done only in one > direction as a shortcut rather than symmetrically as in symbolic maths. > >
My copy of LTSpice gets it almost exactly right at 707 mA if I let a 1 Hz sine wave sim for 1 cycle, with the default settings. I definitely couldn't tell ya what information there is to be gained from letting a FFT sim of a sine wave run any longer than that. Everything you need to know about the spectrum of an infinitely-repeating waveform defined by a closed-form mathematical expression is contained in one cycle, like why would one think DTFT/FFT transform of a signal like that is going to get _more_ accurate over ten cycles, or a hundred? It's not calculating some cycle-by-cycle average. The DTFT/FFT doesn't "know" anything at all about cycles, in fact.
On 07/10/2018 05:37 PM, John Larkin wrote:
> On Tue, 10 Jul 2018 17:10:54 -0400, bitrex <user@example.net> wrote: > >> On 07/10/2018 01:33 PM, John Larkin wrote: >>> On Mon, 9 Jul 2018 23:16:12 -0400, bitrex <user@example.net> wrote: >>> >>>> On 07/09/2018 11:09 PM, bitrex wrote: >>>>> On 07/09/2018 08:00 PM, John Larkin wrote: >>>>>> On Mon, 09 Jul 2018 16:47:06 -0700, Jim Thompson >>>>>> <To-Email-Use-The-Envelope-Icon@On-My-Web-Site.com> wrote: >>>>>> >>>>>>> On Mon, 09 Jul 2018 16:03:54 -0700, John Larkin >>>>>>> <jjlarkin@highland_snip_technology.com> wrote: >>>>>>> >>>>>>>> On Mon, 09 Jul 2018 13:06:15 -0700, boB <boB@K7IQ.com> wrote: >>>>>>>> >>>>>>>>> On Mon, 09 Jul 2018 12:00:24 -0700, John Larkin >>>>>>>>> <jjlarkin@highland_snip_technology.com> wrote: >>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> Suppose I create a current source that's a sine wave, amplitude 1, >>>>>>>>>> frequency 1, and then run a transient response. Then plot current and >>>>>>>>>> FFT. On a linear scale, it has some harmonics (no surprise) but the >>>>>>>>>> amplitude of the fundamental is 690 mA. >>>>>>>>>> >>>>>>>>>> Why 690? Is that a bad approximation of 707? >>>>>>>>>> >>>>>>>>>> Update: if I set the time step to 10 us, it runs slow but the FFT >>>>>>>>>> amplitude is 706.9 mA. So the FFT reports RMS. >>>>>>>>> >>>>>>>>> >>>>>>>>> Try it also with the alternate solver ?&nbsp; Will probably be the same as >>>>>>>>> decreasing the step size though I imagine.&nbsp; Not a lot to go wrong... >>>>>>>>> go wrong.... go wrong... >>>>>>>> >>>>>>>> It's just a sinewave current source. There's really nothing to solve! >>>>>>>> I think LT Spice just picks an ambitiously small delta-T by default. >>>>>>> >>>>>>> Nope.&nbsp; It's a cockpit set-up error >:-} >>>>>>> >>>>>>> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ...Jim Thompson >>>>>> >>>>>> There's no operator error at all. LT Spice gives one a choice of >>>>>> solver, a choice of dt, and several other params to tweak to trade off >>>>>> speed against accuracy. What's wrong with that? >>>>>> >>>>>> I needed to know what units the FFT uses when it displays current. The >>>>>> answer is RMS amps. Sinewave sources, voltage or current, use peak >>>>>> amps. >>>>>> >>>>> >>>>> I think I see the problem. How many cycles at 1 Hz did you let the >>>>> simulation run for? If you set the transient sim to 1 second at 1 Hz it >>>>> hits 707 mA on the linear FFT just about on the money. 10 seconds, it's >>>>> worse. 100 seconds a lot worse. >>>>> >>>>> Floating point roundoff errors are accumulating cycle by cycle and a >>>>> small step size makes it worse. >>> >>> Except, of course, that setting a smaller step size make the FFT >>> better. >>> >>> >>> The sine is starting at 0 amplitude at 0 >>>>> seconds, but after "exactly" say 100 cycles it's not ending there. And >>>>> the end-point error is throwing off the RMS calculation. >>>>> >>>> >>>> That is to say if you are seeing higher harmonics at all then by >>>> Parseval's theorem/energy conservation the fundamental definitely cannot >>>> have its mathematically ideal pure sinewave maximum amplitude. >>> >>> The physical universe has to conserve energy. A computer simulation >>> doesn't. >>> >>> >> >> That total signal energy is conserved when taking the Fourier transform >> is implied by the mathematical fact that the Fourier transform is a >> unitary transform. It has to behave that way in a computer simulation as >> well or it's not the Fourier transform! > > The it's not. The LT Spice FFT clearly has spectral lines coming from > a pure sine wave current source. >
The _transform_ itself is working just fine. The floating-point error non-idealites are causing it return a perfectly valid and correct transform of some other signal. That probably sounds like splitting hairs. Okay fine. But the DTFT/FFT is just an algorithm that takes bytes in and spits out a different bunch of bytes according to a cookbook list of instructions. It doesn't "know" anything about cycles or sines or floating points or current sources or RMS-es or any damn thing.
On 07/10/2018 05:46 PM, John Larkin wrote:
> On Tue, 10 Jul 2018 17:27:54 -0400, bitrex <user@example.net> wrote: > >> On 07/10/2018 08:41 AM, Phil Hobbs wrote: >>> On 07/09/18 15:00, John Larkin wrote: >>>> >>>> >>>> Suppose I create a current source that's a sine wave, amplitude 1, >>>> frequency 1, and then run a transient response. Then plot current and >>>> FFT. On a linear scale, it has some harmonics (no surprise) but the >>>> amplitude of the fundamental is 690 mA. >>>> >>>> Why 690? Is that a bad approximation of 707? >>>> >>>> Update: if I set the time step to 10 us, it runs slow but the FFT >>>> amplitude is 706.9 mA. So the FFT reports RMS. >>> >>> LTspice, like most simulators apart from FDTD EM simulators, uses a >>> variable time step.&nbsp; That means that it has to interpolate to get >>> regularly-spaced samples for the FFT.&nbsp; That interpolation introduces >>> significant amounts of truncation error, which is probably what's >>> responsible for both the harmonics and the reduced fundamental. >>> >>> Cheers >>> >>> Phil Hobbs >>> >>> >> >> the fact that the fundamental is 690 instead of 707 is not a "bad >> approximation" it's a perfectly valid and correct Fourier transform of >> some other sequence of samples generated through a given interpolation >> algorithm, that's not a mathematically abstract pure sine wave. SPICE >> doesn't "know" anything about sine waves or that they should be treated >> any different than any other random sequence of samples. >> >> The implication by the OP seems to be that the FFT in LTSpice is somehow >> a wrong or "sloppy" implementation, maybe so but I don't think that >> follows from the observed symptoms at all. > > That's your implication, not mine. I didn't use your terms "wrong" or > "sloppy." > > 690 is a fairly bad approximation of 707. > > I did note that the default settings of LT Spice had the FFT > fundamental spectral line amplitude at 690 mA, and lots of harmonics. > And that setting a small time step improves things greatly. > > What's wrong with that? >
Here's what I get, alternate solver, 2 amp P2P into 1 ohm @ 1 Hz for 1 second, linear scale FFT, all other default settings: <https://imgur.com/a/xRAKMpz> One harmonic with a peak value of just about 0.707 right on the nose. Seems OK to me! It's a periodic function all the frequency-domain information it will ever have is contained in one period. And there it is.
On Tue, 10 Jul 2018 14:37:59 -0700, John Larkin
<jjlarkin@highland_snip_technology.com> wrote:

>On Tue, 10 Jul 2018 17:10:54 -0400, bitrex <user@example.net> wrote: > >>On 07/10/2018 01:33 PM, John Larkin wrote: >>> On Mon, 9 Jul 2018 23:16:12 -0400, bitrex <user@example.net> wrote: >>> >>>> On 07/09/2018 11:09 PM, bitrex wrote: >>>>> On 07/09/2018 08:00 PM, John Larkin wrote: >>>>>> On Mon, 09 Jul 2018 16:47:06 -0700, Jim Thompson >>>>>> <To-Email-Use-The-Envelope-Icon@On-My-Web-Site.com> wrote: >>>>>> >>>>>>> On Mon, 09 Jul 2018 16:03:54 -0700, John Larkin >>>>>>> <jjlarkin@highland_snip_technology.com> wrote: >>>>>>> >>>>>>>> On Mon, 09 Jul 2018 13:06:15 -0700, boB <boB@K7IQ.com> wrote: >>>>>>>> >>>>>>>>> On Mon, 09 Jul 2018 12:00:24 -0700, John Larkin >>>>>>>>> <jjlarkin@highland_snip_technology.com> wrote: >>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> Suppose I create a current source that's a sine wave, amplitude 1, >>>>>>>>>> frequency 1, and then run a transient response. Then plot current and >>>>>>>>>> FFT. On a linear scale, it has some harmonics (no surprise) but the >>>>>>>>>> amplitude of the fundamental is 690 mA. >>>>>>>>>> >>>>>>>>>> Why 690? Is that a bad approximation of 707? >>>>>>>>>> >>>>>>>>>> Update: if I set the time step to 10 us, it runs slow but the FFT >>>>>>>>>> amplitude is 706.9 mA. So the FFT reports RMS. >>>>>>>>> >>>>>>>>> >>>>>>>>> Try it also with the alternate solver ?&#4294967295; Will probably be the same as >>>>>>>>> decreasing the step size though I imagine.&#4294967295; Not a lot to go wrong... >>>>>>>>> go wrong.... go wrong... >>>>>>>> >>>>>>>> It's just a sinewave current source. There's really nothing to solve! >>>>>>>> I think LT Spice just picks an ambitiously small delta-T by default. >>>>>>> >>>>>>> Nope.&#4294967295; It's a cockpit set-up error >:-} >>>>>>> >>>>>>> &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295; ...Jim Thompson >>>>>> >>>>>> There's no operator error at all. LT Spice gives one a choice of >>>>>> solver, a choice of dt, and several other params to tweak to trade off >>>>>> speed against accuracy. What's wrong with that? >>>>>> >>>>>> I needed to know what units the FFT uses when it displays current. The >>>>>> answer is RMS amps. Sinewave sources, voltage or current, use peak >>>>>> amps. >>>>>> >>>>> >>>>> I think I see the problem. How many cycles at 1 Hz did you let the >>>>> simulation run for? If you set the transient sim to 1 second at 1 Hz it >>>>> hits 707 mA on the linear FFT just about on the money. 10 seconds, it's >>>>> worse. 100 seconds a lot worse. >>>>> >>>>> Floating point roundoff errors are accumulating cycle by cycle and a >>>>> small step size makes it worse. >>> >>> Except, of course, that setting a smaller step size make the FFT >>> better. >>> >>> >>> The sine is starting at 0 amplitude at 0 >>>>> seconds, but after "exactly" say 100 cycles it's not ending there. And >>>>> the end-point error is throwing off the RMS calculation. >>>>> >>>> >>>> That is to say if you are seeing higher harmonics at all then by >>>> Parseval's theorem/energy conservation the fundamental definitely cannot >>>> have its mathematically ideal pure sinewave maximum amplitude. >>> >>> The physical universe has to conserve energy. A computer simulation >>> doesn't. >>> >>> >> >>That total signal energy is conserved when taking the Fourier transform >>is implied by the mathematical fact that the Fourier transform is a >>unitary transform. It has to behave that way in a computer simulation as >>well or it's not the Fourier transform! > >The it's not. The LT Spice FFT clearly has spectral lines coming from >a pure sine wave current source.
What kind of window function did you use ?