Commit Graph

429 Commits

Author SHA1 Message Date
Meisam Bahadori 79ba4be561 * Enhancement-306: ngspice — the E-241 twin in the fft expression function
Enhancement-241 fixed an amplitude normalization that divided by the ZERO-PADDED
transform size instead of the number of input samples -- in the `fft` COMMAND
(frontend/com_fft.c). The identical mistake survived in maths/cmaths/cmath4.c, the
vector-expression function reached by `let F = fft(v)`: a separate implementation of
the same computation.

Found by continuing the oracle campaign that produced E-241, and located with E-241's
own discriminator, the DC bin. One signal, 4001 samples padded to 4096, DC offset 2.0:

  fft s          ; the COMMAND    ->  mag(s)[0] = 2.000000    correct
  let F = fft(s) ; the FUNCTION   ->  mag(F)[0] = 1.953613    = 2.0 * 4001/4096

X[0] is the sum of the samples, D*length for a DC offset D, so dividing by the padded N
reads back D*length/N. As E-241 put it: a DC value cannot depend on how many samples
were taken.

This is a contradiction, not a matter of convention. cx_fft holds TWO complete
implementations -- one for complex input, one for real -- and each has an FFTW branch
and a Green's radix-2 branch. In BOTH, the FFTW branch already used the input length
while Green's used the padded size:

  real branch     FFTW: scale = ((double)length)/2.0    Green: ((double)N)/2   <- wrong
  complex branch  FFTW: scale = (double) fpts           Green: (double) N      <- wrong

the correct version sitting a few lines from the wrong one inside the same function --
the same shape as `avg` disagreeing with `integ` in E-302. HAVE_LIBFFTW3 is undefined in
this build, so Green's is the live path and the defect was reachable.

  oracle                              before      after       closed form
  real-input, DC bin                  1.953613    2.000000    2.0
  real-input, ifft(fft(x))            2.3e-02     1.1e-16     0
  complex-input, bin 0                0.9766780   0.9998683   0.9998683

The round trip is an INDEPENDENT confirmation: nothing here touches ifft, so its going
from 2.3% error to machine precision is evidence from a direction the fix did not aim
at -- the pair only inverts when the forward normalization is right. cx_ifft was
audited and deliberately left alone for that reason.

Every caller of the Green's radix-2 kernel was audited, not only the one that failed:
com_fft.c's fft (x2) and spec/PSD (x2) are correct from E-241; cx_ifft is correct;
trannoise/1-f-code.c cannot pad at all, since n_pts is grown to 2^n_exp by construction;
and fft/ifft are the only transform functions in the expression table, so there is no
spec twin to miss.

Verification: examples/fftexpr_examples/verify_fftexpr.py -- 6 checks under both
solvers, all against closed form (DC bin on both paths, round trip padded and unpadded,
complex-input bin 0 against the analytic mean of an RC response). It scores 3/6 on the
pre-fix binary, so it is a real regression guard. E-241's own suite (fftnorm_examples)
and ifftreal_examples pass unchanged. Full sweep 241/241 OK.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-02 19:56:26 +02:00
Brian Taylor abcbcbd724 Completed and cleaned up memory leak fixes in:
inpc_probe.c outitf.c inpcom.c niiter.c
cherry-pick of this one commit should be OK.
2026-05-19 10:50:35 +02:00
Holger Vogt 19217bf018 Fix a bug reported by Dmitriy, take 2: use 1 to length-1 2026-05-08 10:53:02 +02:00
Holger Vogt 288b2808ab Fix a bug reported by Dmitriy: use length-1 2026-05-06 16:14:10 +02:00
Holger Vogt c9aac14fc1 Fix a bug reported by Dmitriy, replace = by == 2026-04-24 20:59:35 +02:00
Holger Vogt 24240d0e9a All paths return a value 2026-04-24 19:52:22 +02:00
Holger Vogt 665a4944eb Fix a bug, reported by Dmitriy 2026-04-24 17:58:09 +02:00
Keith OHara 0638aaa160 Continue Newton iteration until currents settle.
For each type of device, a *convTest function determines if the
current through that device is converged within tolerance,
and sets CKTnoncon if the current is not yet converged.

ASCRconvTest() erroneously subtracted old current from old,
rather than old from new, when evaluating convergence.

Also, since at least 3f5, the calling function NIconvTest assumed
that the worker functions indicated non-convergence through their
return value, so was ignoring the reports of current nonconvergence.
2026-04-06 00:01:12 +02:00
geraldfournier 65e5ccb7bb Make fft scaling independent from rounding behaviour for odd data.
Add a time slot to fft span.
2026-03-20 13:37:06 +01:00
dwarning b3a78b02cc Special Nyquist scaling only for even length.
Let nyquist bin not empty for odd vector
2026-03-20 13:33:39 +01:00
Holger Vogt 417c52ee5c Remove compiler warnings 2026-02-03 15:05:24 +01:00
Holger Vogt b25ff08307 Moving window filtering with function 'newvec = mtimeavg(vec)'
Window of fixed time width given by 'set mtimeavgwindow=400u'
Length and scale of newvec resembles the original vetor vec.
Large vec and large mtimeavgwindow take their time.
OpenMP is used if available.
2026-02-03 14:23:32 +01:00
Holger Vogt 8737839f41 Add a function m3avg(vector) for filtering of trap ringing.
Moving average with D(n) = (C(n-1)/2 + C(n) + C(n+1)/2)/2
2026-02-03 14:20:08 +01:00
Brian Taylor 47d7f7aa62 Allocating arrays of double* should use sizeof double* not double, even though they may be the same. Avoid potential divide by zero. 2025-07-29 11:03:28 +02:00
Holger Vogt 612a924ea3 Reformat spoutput.c
Replace tabs by spaces
2025-05-24 11:22:47 +02:00
Holger Vogt 46e4a67079 Some cosmetics for readability:
replace tabs by spaces
2025-05-24 11:22:37 +02:00
Holger Vogt 243bdff377 Formatting: tabs to spaces 2025-05-24 11:22:01 +02:00
Holger Vogt 72d70e3471 bool definition is in stdbool.h, no local definition required 2024-12-15 10:27:29 +01:00
Holger Vogt deb3cd9809 Replace all BOOLEAN, BOOL, _Bool by bool
Remove all #undef bool (set in conjunction with #iclude <Windows.h>)
2024-12-15 10:25:28 +01:00
dwarning 54865ed39d bring the KLU_malloc() in right order, ticket #717 2024-12-06 22:48:56 +01:00
dwarning 7b815c743e intel cc see obsolete }; as empty declaration 2024-12-06 22:35:49 +01:00
Brian Taylor 3528156d14 Fix bug #680. Check that src/dest memcpy arguments are non-NULL. 2024-11-02 22:35:57 +01:00
Holger Vogt f495431509 Add a comment 2024-11-02 22:33:52 +01:00
Holger Vogt 83e8cb3715 Remove VS compiler warning 2024-07-05 13:53:04 +02:00
Brian Taylor d01868b725 Cleanup gcc compiler warnings. 2024-06-22 14:23:50 +02:00
dwarning adaa3d39fc no use for grouping in cx_fft and cx_ifft 2024-02-16 13:56:43 +01:00
dwarning 8aa20cfc98 fft window functions back to correct scaling - no need need for post scaling step 2024-01-24 23:16:44 +01:00
dwarning 9e41383dd9 window weightings between 0 and 1 for fft vector function and command 2024-01-22 17:37:27 +01:00
dwarning aafd7bbb42 correct bartlett/triangle fft window formulae 2024-01-21 21:58:43 +01:00
Holger Vogt 0141473aa4 Don't derefence Matrix->SMPkluMatrix->KLUmatrixCommon if it is NULL.
Test for NULL moved upwards in front of dereferencing.
2024-01-14 15:12:03 +01:00
Holger Vogt f4c560ba71 Add more KLU headers to enable their distribution 2023-12-27 16:42:37 +01:00
Giles Atkinson 3cf8fe8c41 Stop after last data point, preventing read overrun of nscale. 2023-12-01 12:26:58 +00:00
Giles Atkinson d82f948832 Fix a crash found by Brian Taylor: when .plot attempts to plot digital
node history, interpolation may produce an infinite value at digital edges.
Remove vertical edges when interpolating and make some other improvements:
do not calculate a polynomial approximation for unused frames;
center the target x-value in the frame; and do not propogate a reduction
in degree to later frames.
2023-11-30 17:23:32 +00:00
Holger Vogt 0735b8d0a5 fix previous commit on repeating error messages 2023-11-15 22:54:53 +01:00
Holger Vogt 55ba927973 If nan occurs during op calculation, issue the warning
no more than 10 times.
2023-11-14 16:57:14 +01:00
dwarning 2cf2693706 few code cleanings 2023-11-12 17:04:36 +01:00
Holger Vogt 0a087809d6 If both node names are the same, just print them once in the error message. 2023-11-08 13:12:06 +01:00
Holger Vogt a6d5ce8ea6 Some KLU warnings are useless for the normal user, as she or he
does not have any means to further analyze or repair the issue:
Warning: KLU ReFactor failed. Factoring again...
Warning (ReFactor Complex): KLU Matrix is SINGULAR
    Numerical Rank: %d\n
    Singular Node: %d\n
So print these messages only in debug mode.
2023-09-10 14:41:16 +02:00
Holger Vogt 4864f0a118 Remove crash in CIDER example meclgate.cir 2023-08-16 11:14:25 +02:00
Francesco Lannutti 05aa9f0927 Better fix for previous commit 2023-08-16 11:14:24 +02:00
Francesco Lannutti 13e74751cc Fixed a MLK for XSPICE and commented out an unused array 2023-08-16 11:14:24 +02:00
Francesco Lannutti cab5e8cd37 Added the case of VSRCport to VSRC model for KLU 2023-08-16 11:14:24 +02:00
Francesco Lannutti b08eb2266a Added initial KLU support for node collapsing 2023-08-16 11:14:24 +02:00
Francesco Lannutti 470cd4a514 Fixed KLU SINGULAR matrix handling and messaging 2023-08-16 11:14:24 +02:00
Francesco Lannutti d68e83be78 Fixed VBIC model for KLU
Fixed SMPfindElt messages
2023-08-16 11:14:23 +02:00
Francesco Lannutti 8123fde6f7 Handled properly KLU messages when XSPICE is purely digital 2023-08-16 11:14:23 +02:00
Francesco Lannutti 4200362f42 Fixed Empty Matrix handling in KLU 2023-08-16 11:14:23 +02:00
Francesco Lannutti 937325e2ce Handled an empty circuit with KLU 2023-08-16 11:14:23 +02:00
Holger Vogt 6b6e9bb7cb Enable log output (warning and error messages) on the Windows GUI 2023-08-16 11:14:22 +02:00
Francesco Lannutti caf1ee7c47 Fixed a crash when SPARSE is used 2023-08-16 11:14:21 +02:00