[Home] DMelt member access. Java source code: flanagan.circuits.ImpedSpecRegression
/* Class ImpedSpecRegression
*
* Non-linear regression procedures for fitting impedance
* spectroscopy and electrochemical impedance spectroscopy
* data to user supplied circuit or one of a range of precompiled
* circuit models.
*
* User supplied circuit models require the interface ImpedSpecModel
*
* WRITTEN BY: Dr Michael Thomas Flanagan
*
* DATE: 9 June 2007 (Derived from impedance spectroscopy programs, 2004 - 2007)
* UPDATE: 16 October 2007, 5 July 2008
*
* DOCUMENTATION:
* See Michael T Flanagan's Java library on-line web pages:
* http://www.ee.ucl.ac.uk/~mflanaga/java/
* http://www.ee.ucl.ac.uk/~mflanaga/java/ImpedSpecRegression.html
*
* Copyright (c) June 2007 Michael Thomas Flanagan
*
* PERMISSION TO COPY:
* Permission to use, copy and modify this software and its documentation for
* NON-COMMERCIAL purposes is granted, without fee, provided that an acknowledgement
* to the author, Michael Thomas Flanagan at www.ee.ucl.ac.uk/~mflanaga, appears in all copies.
*
* Dr Michael Thomas Flanagan makes no representations about the suitability
* or fitness of the software for any or for a particular purpose.
* Michael Thomas Flanagan shall not be liable for any damages suffered
* as a result of using, modifying or distributing this software or its derivatives.
*
****************************************************************************************/
package flanagan.circuits;
import flanagan.io.*;
import flanagan.complex.Complex;
import flanagan.complex.ComplexErrorProp;
import flanagan.analysis.ErrorProp;
import flanagan.analysis.Regression;
import flanagan.analysis.RegressionFunction2;
import flanagan.analysis.Stat;
import flanagan.math.Fmath;
import flanagan.math.Conv;
import flanagan.plot.*;
import java.lang.reflect.Array;
import java.text.*;
import java.util.*;
import java.lang.Object;
public class ImpedSpecRegression extends Regression{
private String regressionTitle = null; // Title for output graphs and text file
private boolean fileType = false; // = true if 'n' number to be added to file name
private Complex appliedVoltage = null; // magnitude of the applied voltage as complex
private boolean appliedVoltageSet = false; // = true when applied voltage entered
private Complex appliedVoltageError = null; // error of the applied voltage as complex
private boolean voltageErrorSet = false; // = true when applied voltage error entered
private Complex referenceImpedance = null; // reference impedance
private boolean referenceSet = false; // = true when reference impedance entered
private double[] frequencies = null; // frequencies [Hz]
private double[] omegas = null; // radial frequencies
private double[] log10frequencies = null; // log10[frequencies/Hz]
private double[] log10omegas = null; // log10[radial frequencies]
private int numberOfFrequencies = 0; // number of points in the simulation
private boolean frequenciesSet = false; // = true when frequencies entered
private Complex[] voltages = null; // voltages
private Complex[] voltageWeights = null; // voltage weights
private double[] voltageMagnitudes = null; // magnitude of the voltages
private double[] voltageMagnitudeWeights = null; // voltage magnitude weights
private double[] voltagePhasesRad = null; // voltage phases [radians]of the voltages
private double[] voltagePhaseWeightsRad = null; // voltage phase weights [radians]
private double[] voltagePhasesDeg = null; // voltage phases [degrees]of the voltages
private double[] voltagePhaseWeightsDeg = null; // voltage phase weights [degrees]
private double[] realV = null; // real part of the voltage
private double[] realVweights = null; // real part of the voltage - weights
private double[] imagV = null; // imaginary part of the voltages
private double[] imagVweights = null; // imaginary part of the voltage - weights
private boolean weightsSet = true; // = false if no weights provided
private int dataEnteredTypePointer = -1; // = 0; real and imag voltage
// = 1: complex voltage
// = 2: voltage magnitude and radians
// = 3: voltage magnitude and degreees
// = 4; real and imag impedance
// = 5: complex mpedance
// = 6: mpedance magnitude and radians
// = 7: mpedance magnitude and degreees
// Entered data type
private String[] dataEnteredType = {"Complex voltage (as real and imaginary parts)", "Complex voltage (as Complex)", "Voltage Magnitude and phase (in radians)", "Voltage Magnitude and phase (in degrees)", "Complex impedance (as real and imaginary parts)", "Complex impedance (as Complex)", "Magnitude and phase (in radians)", "Magnitude and phase (in degrees)"};
private boolean voltageOrImpedance = true; // = true: data entered as test circuit voltages
// = false: data entered as test circuit impedances
private Complex[] impedances = null; // model impedances
private Complex[] impedanceWeights = null; // model impedance weights
private double[] impedanceMagnitudes = null; // magnitude of the impedances
private double[] impedanceMagnitudeWeights = null; // impedance magnitude weights
private double[] impedancePhasesRad = null; // impedance phases [radians]of the impedances
private double[] impedancePhaseWeightsRad = null; // impedance phase weights [radians]
private double[] impedancePhasesDeg = null; // impedance phases [degrees]of the impedances
private double[] impedancePhaseWeightsDeg = null; // impedance phase weights [degrees]
private double[] realZ = null; // real part of the model impedance
private double[] realZweights = null; // real part of the model impedance - weights
private double[] imagZ = null; // imaginary part of the model impedance
private double[] imagZweights = null; // imaginary part of the model impedance - weights
private boolean impedancesSet = false; // = true when impedances calculated
private double[] xRegression = null; // regression x-axis data
private double[][] yRegression = null; // regression y-axis data
private double[][] wRegression = null; // regression weights
private int modelNumber = 0; // model number
private int numberOfParameters = 0; // number of model parameters
private String[] parameterSymbols = null; // model parameter symbols
private boolean modelSet = false; // = true when a model number is entered
private boolean estimatesNeeded = false; // = true when a no estimates are to be entered and they are yet to be calculated
private boolean supressDefaultConstraints = false; // = true when in-built constraints on parameters supressed
private boolean supressAddedConstraints = false; // = true when added constraints on parameters supressed
private boolean supressAllConstraints = false; // = true when all constraints on parameters supressed
private ArrayList