Reply by Phil Hobbs July 16, 20182018-07-16
On 07/16/2018 09:17 AM, Martin Brown wrote:
> On 13/07/2018 09:49, Phil Hobbs wrote: >> On 07/12/18 04:05, Martin Brown wrote: >>> On 10/07/2018 18: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 ?&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 >:-} >>>>>>>> >>>>>>>> ...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. >>>>> >>>>> The DFT/FFT only applies to periodic sequences.&nbsp; 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.&nbsp; It's not >>>>> very difficult to compute an error bound in any given case. >>> >>> There is a way to make an FFT give a very good approximation to a DFT >>> in the case of unequally spaced data provided that the data is >>> reasonably compact on the new uniform grid. You convolve the raw data >>> with an interpolation function on compact support (Jodrell used to >>> use truncated Gaussian, VLA used a variant prolate spheroidal >>> bessel). >> >> Hmm.&nbsp; How do you compute the discrete convolution without >> interpolating first? > > You compute the coordinate of the point on the new uniform grid and take > the integer part, then you use the remainder to look up into a prepared > table of the interpolation function which by smearing the wanted > frequency across a series of nearby bins makes a very good approximation > to the right frequency multiplied by a smooth frequency dependent fiddle > factor in the frequency domain. It is a variant of: > > &nbsp;sin(Nx) + sin((N+1)x) = 2sin((N+1/2)x)cos(x/2) > > But obviously in practice taking a few more terms and other weights. > > Usually done over an odd numbered region of support typically 7 or 9 and > capable of removing aliases and delivering DFT quality results from FFT. > There is a more sophisticated version that came later and deliberately > throws away results too close to the edge of the transform to get the > very best possible accuracy on the part that is being kept. It is > routine in almost all indirect FFT based imaging these days. > > IOW you interpolate on the convolving function to match what you want by > way of frequency. A bit of normalisation to sort out the sampling > non-uniformities and you are done. > > The devil *is* in the detail. Any kind of error in the implementation > and you can end up with truly horrible artefacts. > >>> The paper you want is Schwab 1984 from there >>> >>> http://adsabs.harvard.edu/abs/1984iimp.conf..333S >>> >>> Probably no help to the OP but I think Phil will enjoy it! >> >> Sounds interesting, but I can't find it online anyplace--just the >> adsabs.harvard.edu listing. > > It is something that really only interests very serious FFT geeks mostly > in radio astronomy but also MRI and SAR. You can get away with cruder > methods but to get ultimate dynamic range then you have to use all the > right tricks.
FFTs are so efficient at generating reasonable-looking wrong answers that techniques to prevent that are super useful. 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 https://hobbs-eo.com
Reply by Martin Brown July 16, 20182018-07-16
On 13/07/2018 09:37, Phil Hobbs wrote:
> On 07/11/18 22:24, bitrex wrote: >> On 07/09/2018 03:00 PM, 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. >>> >>> >>> >> >> >> After some research here is a quick guide on how to get very low >> spurious harmonic energy FFT plots in LTSpice: >> >> 1. Turn off simulation data compression using the directive on the >> schematic ".options plotwinsize=0" >> >> 2. Make the maximum timestep under "Edit Simulation Command" an >> appropriate reciprocal power of two e.g. 1/65536. >> >> 3. Simulate for an integer number of cycles at least 8x reciprocal of >> Nyquist frequency for given signal. >> >> 4. In the FFT setup make "Number of data point samples in time" the >> same power of two as above e.g. 65536. >> >> 5. Turn off "quadratic interpolate uncompressed data." >> >> 6. Select windowing function "Blackman." >> >> Using that setup here's what I get for a linear-scale FFT of 100 >> cycles of 1 Hz 2 amp p2p sine wave: >> >> <https://imgur.com/a/natdJhq> > > The trouble is that you don't know to do that when you're simulating > something more complicated, so you can get snookered. > > How important was each item?&nbsp; I can well believe that turning off > compression helped a lot, but I doubt that the window did anything > except smear out the spectrum by a few samples.
+1 Provided that the waveform matched periodic boundary conditions exactly applying a windowing function merely broadens the peak. The idea of windowing is to avoid a discontinuity across the wrap around of data. -- Regards, Martin Brown
Reply by Martin Brown July 16, 20182018-07-16
On 13/07/2018 09:49, Phil Hobbs wrote:
> On 07/12/18 04:05, Martin Brown wrote: >> On 10/07/2018 18: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 ?&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 >:-} >>>>>>> >>>>>>> ...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. >>>> >>>> The DFT/FFT only applies to periodic sequences.&nbsp; 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.&nbsp; It's not >>>> very difficult to compute an error bound in any given case. >> >> There is a way to make an FFT give a very good approximation to a DFT >> in the case of unequally spaced data provided that the data is >> reasonably compact on the new uniform grid. You convolve the raw data >> with an interpolation function on compact support (Jodrell used to >> use truncated Gaussian, VLA used a variant prolate spheroidal >> bessel). > > Hmm.&nbsp; How do you compute the discrete convolution without interpolating > first?
You compute the coordinate of the point on the new uniform grid and take the integer part, then you use the remainder to look up into a prepared table of the interpolation function which by smearing the wanted frequency across a series of nearby bins makes a very good approximation to the right frequency multiplied by a smooth frequency dependent fiddle factor in the frequency domain. It is a variant of: sin(Nx) + sin((N+1)x) = 2sin((N+1/2)x)cos(x/2) But obviously in practice taking a few more terms and other weights. Usually done over an odd numbered region of support typically 7 or 9 and capable of removing aliases and delivering DFT quality results from FFT. There is a more sophisticated version that came later and deliberately throws away results too close to the edge of the transform to get the very best possible accuracy on the part that is being kept. It is routine in almost all indirect FFT based imaging these days. IOW you interpolate on the convolving function to match what you want by way of frequency. A bit of normalisation to sort out the sampling non-uniformities and you are done. The devil *is* in the detail. Any kind of error in the implementation and you can end up with truly horrible artefacts.
>> The paper you want is Schwab 1984 from there >> >> http://adsabs.harvard.edu/abs/1984iimp.conf..333S >> >> Probably no help to the OP but I think Phil will enjoy it! > > Sounds interesting, but I can't find it online anyplace--just the > adsabs.harvard.edu listing.
It is something that really only interests very serious FFT geeks mostly in radio astronomy but also MRI and SAR. You can get away with cruder methods but to get ultimate dynamic range then you have to use all the right tricks. -- Regards, Martin Brown
Reply by Phil Hobbs July 13, 20182018-07-13
On 07/12/18 04:05, Martin Brown wrote:
> On 10/07/2018 18: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. >>> >>> 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. > > There is a way to make an FFT give a very good approximation to a DFT > in the case of unequally spaced data provided that the data is > reasonably compact on the new uniform grid. You convolve the raw data > with an interpolation function on compact support (Jodrell used to > use truncated Gaussian, VLA used a variant prolate spheroidal > bessel).
Hmm. How do you compute the discrete convolution without interpolating first?
> This means that your final result is then multiplied by a scale > factor that has to be corrected out but by keeping track of how much > contribution is put into each cell and the cumulative value you can > get a pretty good FFT out of data that are not uniformly spaced with > minimal artefacts.
I can well believe that the problems can be reduced if you actually do the math properly. ;)
> > See https://github.com/mrbell/gfft/wiki/Gridding > > The paper you want is Schwab 1984 from there > > http://adsabs.harvard.edu/abs/1984iimp.conf..333S > > Probably no help to the OP but I think Phil will enjoy it!
Sounds interesting, but I can't find it online anyplace--just the adsabs.harvard.edu listing. 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
Reply by Phil Hobbs July 13, 20182018-07-13
On 07/11/18 22:24, bitrex wrote:
> On 07/09/2018 03:00 PM, 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. >> >> >> > > > After some research here is a quick guide on how to get very low > spurious harmonic energy FFT plots in LTSpice: > > 1. Turn off simulation data compression using the directive on the > schematic ".options plotwinsize=0" > > 2. Make the maximum timestep under "Edit Simulation Command" an > appropriate reciprocal power of two e.g. 1/65536. > > 3. Simulate for an integer number of cycles at least 8x reciprocal of > Nyquist frequency for given signal. > > 4. In the FFT setup make "Number of data point samples in time" the same > power of two as above e.g. 65536. > > 5. Turn off "quadratic interpolate uncompressed data." > > 6. Select windowing function "Blackman." > > Using that setup here's what I get for a linear-scale FFT of 100 cycles > of 1 Hz 2 amp p2p sine wave: > > <https://imgur.com/a/natdJhq>
The trouble is that you don't know to do that when you're simulating something more complicated, so you can get snookered. How important was each item? I can well believe that turning off compression helped a lot, but I doubt that the window did anything except smear out the spectrum by a few samples. 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
Reply by Martin Brown July 12, 20182018-07-12
On 11/07/2018 15:08, John Larkin wrote:
> On Wed, 11 Jul 2018 09:19:04 +0300, upsidedown@downunder.com wrote: > >> 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: >>> >>>> 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 ? > > LT Spice has a huge list of hyphenated-name window functions. I tried > a few at random and they didn't change the spectrum much. > > What does clean up the spectrum (of a pure sine wave source!) is > running more cycles and setting smaller dT. > > Try it.
Try a power of two number of cycles and I think some of your artefacts will spontaneously vanish. It will probably keep on improving until dT is O(2*sqrt(eps)) but it will get very very slow and tedious. Checking the actual harmonic content by simulating a couple of the stronger harmonics cos & sin and computing their products explicitly in spice would show if it is FFT artefact ot numerical. -- Regards, Martin Brown
Reply by Martin Brown July 12, 20182018-07-12
On 10/07/2018 22:37, 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.
A picture is worth a thousand words here. Odd or even harmonics? Try doing 128 cycles or 64 cycles and does the harmonic content vanish? -- Regards, Martin Brown
Reply by Martin Brown July 12, 20182018-07-12
On 10/07/2018 18: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. >> >> 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.
There is a way to make an FFT give a very good approximation to a DFT in the case of unequally spaced data provided that the data is reasonably compact on the new uniform grid. You convolve the raw data with an interpolation function on compact support (Jodrell used to use truncated Gaussian, VLA used a variant prolate spheroidal bessel). This means that your final result is then multiplied by a scale factor that has to be corrected out but by keeping track of how much contribution is put into each cell and the cumulative value you can get a pretty good FFT out of data that are not uniformly spaced with minimal artefacts. See https://github.com/mrbell/gfft/wiki/Gridding The paper you want is Schwab 1984 from there http://adsabs.harvard.edu/abs/1984iimp.conf..333S Probably no help to the OP but I think Phil will enjoy it!
> > 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.
Windowing functions just alter the sidebands caused by the discontinuity between the start and end of your time series data. If your signal is exactly periodic on the FFT length it should be irrelevant (and will only make things worse). You might find that choosing a timescale that is an exact power of two will give less side effects depending on exactly how LT spice does it internally. Modern FFT packages can do most sizes efficiently. I suspect you are suffering amplitude drift. We used to optimise FFT recurrence relations to the extent of tabulating the discrete roots of rN = (-1)(1/2^N) that gave least error when rN^(2^N) was computed by the recurrence algorithm. It was never quite the same as theory. -- Regards, Martin Brown
Reply by bitrex July 11, 20182018-07-11
On 07/09/2018 03:00 PM, 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. > > >
After some research here is a quick guide on how to get very low spurious harmonic energy FFT plots in LTSpice: 1. Turn off simulation data compression using the directive on the schematic ".options plotwinsize=0" 2. Make the maximum timestep under "Edit Simulation Command" an appropriate reciprocal power of two e.g. 1/65536. 3. Simulate for an integer number of cycles at least 8x reciprocal of Nyquist frequency for given signal. 4. In the FFT setup make "Number of data point samples in time" the same power of two as above e.g. 65536. 5. Turn off "quadratic interpolate uncompressed data." 6. Select windowing function "Blackman." Using that setup here's what I get for a linear-scale FFT of 100 cycles of 1 Hz 2 amp p2p sine wave: <https://imgur.com/a/natdJhq>
Reply by Phil Hobbs July 11, 20182018-07-11
On 07/10/18 17:27, bitrex 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,
So what? I didn't complain that it was a "bad approximation", just that it depended on numerical details that were irrelevant to the problem at hand. Correctly coding a poor algorithm doesn't make your program "perfectly valid and correct" unless you're scrambling to keep your job.
> 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.
So what? We're not talking about Volkswagen's engine management software here. The use of interpolation to force variable-step results onto the FFT's uniform grid introduces truncation error, so the resulting frequency-domain plots can very easily exhibit artifacts.
> > 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.
The FFT isn't the issue. As you say, it's an algorithm to turn discrete time-domain samples into samples of the Fourier transform of the input sequence. But when the assumptions underlying the theorems aren't met, the algos will produce wrong answers to the question the user is asking. Unit tests can ensure that the code is doing what it's supposed to, but they're powerless if the design is wrong. 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