Electronics-Related.com
Forums

LT Spice FFT scaling

Started by John Larkin July 9, 2018
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
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
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
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