TriangleFit1D

TriangleFit1D#

class TriangleFit1D(rawData)#

Bases: FitData1D

TriangleFit1D fits asymmetric triangle wave functions to 1D data.

Fits triangle wave functions with customizable rise and fall times to experimental data. The function consists of linear rise and fall segments with specified period, phase, and rise time. Inherits from FitData1D.

Formula:

\(u = (x + \phi) \bmod T\)

\(y(u) = \begin{cases} A_{\min} + (A_{\max} - A_{\min})\, \dfrac{u}{T_r}, & 0 \le u < T_r \\ A_{\max} - (A_{\max} - A_{\min})\, \dfrac{u - T_r}{T - T_r}, & T_r \le u < T \end{cases}\)

Coefficients: \(A_{\max}\), \(A_{\min}\), \(\phi\), \(T\), \(T_r\)

Example1:

% Fit triangle wave to experimental data
x = linspace(0, 20, 200);
y = sawtooth(2*pi*0.2*x, 0.3) + 0.1*randn(size(x));
data = [x', y'];
triangleFit = TriangleFit1D(data);
triangleFit.do();
triangleFit.plot();

Example2:

% Access fit coefficients
triangleFit = TriangleFit1D(data);
triangleFit.do();
amax = triangleFit.Coefficient(1); % maximum amplitude
amin = triangleFit.Coefficient(2); % minimum amplitude
phi = triangleFit.Coefficient(3);  % phase
T = triangleFit.Coefficient(4);    % period
Tr = triangleFit.Coefficient(5);   % rise time
Constructor Summary
TriangleFit1D(rawData)#

Construct a TriangleFit1D object.

Parameters:

rawData (double array) – Input data as n x 2 matrix [x, y]

Method Summary
guessCoefficient()#

Automatically estimate initial fit coefficients from data.

Estimates maximum/minimum amplitudes, period, rise time, and phase based on data characteristics and Fourier analysis. Rise time is initially set to half the period.

setFormula()#

Set the asymmetric triangle wave fit formula.

Configures the Func property with a triangle function having independent rise time \(T_r\) and fall time \(T - T_r\).