// Path: lib/src/main/java/hrv/lib/hrv/calc/psd/PowerSpectrum.java
// public class PowerSpectrum {
// 
//     private double[] power;
//     private double[] frequency;
//     private TimeUnit unit;
// 
//     public PowerSpectrum(double[] power, double[] frequency) {
//         this.power = power;
//         this.frequency = frequency;
//     }
// 
//     public double[] getPower() {
//         return power;
//     }
// 
//     public void setPower(double[] power) {
//         this.power = power;
//     }
// 
//     public double[] getFrequency() {
//         return frequency;
//     }
// 
//     public void setFrequency(double[] frequency) {
//         this.frequency = frequency;
//     }
// 
//     public TimeUnit getUnit() {
//         return unit;
//     }
// 
//     public void setIncomingUnit(TimeUnit unit) {
//         this.unit = unit;
//     }
// 
//     /**
//      * Adds the power of the given {@code PowerSpectrum} to this {@code PowerSpectrum}.
//      * If one of the {@code PowerSpectrum's} has more entries summation stops when the shorter
//      * {@code PowerSpectrum} reached its end. It is assumed, that the frequencies start at
//      * the same values and that they increase with the same rate.
//      *
//      * @param ps {@code PowerSpectrum} to add.
//      */
//     public void add(PowerSpectrum ps) {
//         //Use the shorter length to avoid array out of bounds.
//         int shorterLength = Math.min(ps.getPower().length, this.power.length);
// 
//         for (var i = 0; i < shorterLength; i++) {
//             this.power[i] += ps.getPower()[i];
//         }
//     }
// }
// 
// Path: lib/src/main/java/hrv/lib/hrv/calc/psd/PowerSpectrumIntegralCalculator.java
// public class PowerSpectrumIntegralCalculator implements HRVPowerSpectrumProcessor {
// 
//     private final double lowerIntegrationLimit;
//     private final double upperIntegrationLimit;
// 
//     public PowerSpectrumIntegralCalculator(double lowerIntegrationLimit, double upperIntegrationLimit) {
//         this.lowerIntegrationLimit = lowerIntegrationLimit;
//         this.upperIntegrationLimit = upperIntegrationLimit;
//     }
// 
//     @Override
//     public HRVParameter process(PowerSpectrum ps) {
//         var psAdapter = new PowerSpectrumUnivariateFunctionAdapter(ps);
//         var integrator = new TrapezoidIntegrator();
//         return new HRVParameter(HRVParameterEnum.NON,
//                 integrator.integrate(BaseAbstractUnivariateIntegrator.DEFAULT_MAX_ITERATIONS_COUNT,
//                         psAdapter,
//                         lowerIntegrationLimit,
//                         upperIntegrationLimit),
//                 ps.getUnit() + "*" + ps.getUnit());
//     }
// }


import hrv.lib.hrv.calc.psd.PowerSpectrum;
import hrv.lib.hrv.calc.psd.PowerSpectrumIntegralCalculator;
package hrv.lib.hrv.calc.parameter;


/**
 * Calculates the normalized unit of the spectral lf indices. Like defined in
 * https://www.ncbi.nlm.nih.gov/pmc/articles/PMC1978375/
 * 
 * @author Julian
 *
 */
public class LFnuCalculator implements HRVPowerSpectrumProcessor {
	
	private final double lfLowerLimit;
	private final double lfUpperLimit;
	private final double hfLowerLimit;
	private final double hfUpperLimit;
	
	public LFnuCalculator(double lfLowerLimit, double lfUpperLimit, double hfLowerLimit, double hfUpperLimit) {
		this.lfLowerLimit = lfLowerLimit;
		this.lfUpperLimit = lfUpperLimit;
		this.hfLowerLimit = hfLowerLimit;
		this.hfUpperLimit = hfUpperLimit;
	}
	@Override
// Path: lib/src/main/java/hrv/lib/hrv/calc/psd/PowerSpectrum.java
// public class PowerSpectrum {
// 
//     private double[] power;
//     private double[] frequency;
//     private TimeUnit unit;
// 
//     public PowerSpectrum(double[] power, double[] frequency) {
//         this.power = power;
//         this.frequency = frequency;
//     }
// 
//     public double[] getPower() {
//         return power;
//     }
// 
//     public void setPower(double[] power) {
//         this.power = power;
//     }
// 
//     public double[] getFrequency() {
//         return frequency;
//     }
// 
//     public void setFrequency(double[] frequency) {
//         this.frequency = frequency;
//     }
// 
//     public TimeUnit getUnit() {
//         return unit;
//     }
// 
//     public void setIncomingUnit(TimeUnit unit) {
//         this.unit = unit;
//     }
// 
//     /**
//      * Adds the power of the given {@code PowerSpectrum} to this {@code PowerSpectrum}.
//      * If one of the {@code PowerSpectrum's} has more entries summation stops when the shorter
//      * {@code PowerSpectrum} reached its end. It is assumed, that the frequencies start at
//      * the same values and that they increase with the same rate.
//      *
//      * @param ps {@code PowerSpectrum} to add.
//      */
//     public void add(PowerSpectrum ps) {
//         //Use the shorter length to avoid array out of bounds.
//         int shorterLength = Math.min(ps.getPower().length, this.power.length);
// 
//         for (var i = 0; i < shorterLength; i++) {
//             this.power[i] += ps.getPower()[i];
//         }
//     }
// }
// 
// Path: lib/src/main/java/hrv/lib/hrv/calc/psd/PowerSpectrumIntegralCalculator.java
// public class PowerSpectrumIntegralCalculator implements HRVPowerSpectrumProcessor {
// 
//     private final double lowerIntegrationLimit;
//     private final double upperIntegrationLimit;
// 
//     public PowerSpectrumIntegralCalculator(double lowerIntegrationLimit, double upperIntegrationLimit) {
//         this.lowerIntegrationLimit = lowerIntegrationLimit;
//         this.upperIntegrationLimit = upperIntegrationLimit;
//     }
// 
//     @Override
//     public HRVParameter process(PowerSpectrum ps) {
//         var psAdapter = new PowerSpectrumUnivariateFunctionAdapter(ps);
//         var integrator = new TrapezoidIntegrator();
//         return new HRVParameter(HRVParameterEnum.NON,
//                 integrator.integrate(BaseAbstractUnivariateIntegrator.DEFAULT_MAX_ITERATIONS_COUNT,
//                         psAdapter,
//                         lowerIntegrationLimit,
//                         upperIntegrationLimit),
//                 ps.getUnit() + "*" + ps.getUnit());
//     }
// }


// Path: lib/src/main/java/hrv/lib/hrv/calc/parameter/LFnuCalculator.java
import hrv.lib.hrv.calc.psd.PowerSpectrum;
import hrv.lib.hrv.calc.psd.PowerSpectrumIntegralCalculator;

package hrv.lib.hrv.calc.parameter;


/**
 * Calculates the normalized unit of the spectral lf indices. Like defined in
 * https://www.ncbi.nlm.nih.gov/pmc/articles/PMC1978375/
 * 
 * @author Julian
 *
 */
public class LFnuCalculator implements HRVPowerSpectrumProcessor {
	
	private final double lfLowerLimit;
	private final double lfUpperLimit;
	private final double hfLowerLimit;
	private final double hfUpperLimit;
	
	public LFnuCalculator(double lfLowerLimit, double lfUpperLimit, double hfLowerLimit, double hfUpperLimit) {
		this.lfLowerLimit = lfLowerLimit;
		this.lfUpperLimit = lfUpperLimit;
		this.hfLowerLimit = hfLowerLimit;
		this.hfUpperLimit = hfUpperLimit;
	}
	@Override
	public HRVParameter process(PowerSpectrum ps) {