Class ModulatedIrSequence

java.lang.Object
org.harctoolbox.ircore.IrSequence
org.harctoolbox.ircore.ModulatedIrSequence
All Implemented Interfaces:
Serializable, Cloneable

public final class ModulatedIrSequence extends IrSequence
A ModulatedIrSequence is an IrSequence with the additional properties of a modulation frequency and a duty cycle. The name is slightly misleading since the modulation frequency can be 0; it just needs to be present.
See Also:
  • Field Details

  • Constructor Details

    • ModulatedIrSequence

      public ModulatedIrSequence()
    • ModulatedIrSequence

      public ModulatedIrSequence(IrSequence irSequence, Double frequency, Double dutyCycle)
      Constructs a ModulatedIrSequence from its arguments.
      Parameters:
      irSequence - irSequence to be copied from
      frequency -
      dutyCycle -
    • ModulatedIrSequence

      public ModulatedIrSequence(IrSequence irSequence, Double frequency)
      Constructs a ModulatedIrSequence from its arguments.
      Parameters:
      irSequence - irSequence to be copied from
      frequency -
    • ModulatedIrSequence

      public ModulatedIrSequence(ModulatedIrSequence src, int start, int length) throws InvalidArgumentException
      Parameters:
      src -
      start -
      length -
      Throws:
      InvalidArgumentException
    • ModulatedIrSequence

      public ModulatedIrSequence(double[] durations, Double frequency, Double dutyCycle) throws OddSequenceLengthException
      Constructs a ModulatedIrSequence from its arguments.
      Parameters:
      durations -
      frequency -
      dutyCycle -
      Throws:
      OddSequenceLengthException
    • ModulatedIrSequence

      public ModulatedIrSequence(double[] durations, Double frequency) throws OddSequenceLengthException
      Constructs a ModulatedIrSequence from its arguments.
      Parameters:
      durations -
      frequency -
      Throws:
      OddSequenceLengthException - if duration has odd length.
    • ModulatedIrSequence

      public ModulatedIrSequence(int[] durations, Double frequency, Double dutyCycle) throws OddSequenceLengthException
      Constructs a ModulatedIrSequence from its arguments.
      Parameters:
      durations -
      frequency -
      dutyCycle -
      Throws:
      OddSequenceLengthException - if duration has odd length.
    • ModulatedIrSequence

      public ModulatedIrSequence(int[] durations, Double frequency) throws OddSequenceLengthException
      Constructs a ModulatedIrSequence from its arguments.
      Parameters:
      durations -
      frequency -
      Throws:
      OddSequenceLengthException - if duration has odd length.
  • Method Details

    • concatenate

      public static ModulatedIrSequence concatenate(Collection<IrSequence> sequences, double frequency, double dutyCycle)
    • concatenate

      public static ModulatedIrSequence concatenate(ModulatedIrSequence[] seqs)
      Concatenates the IrSequences in the argument to a new sequence. Frequency and duty cycle are set to the average between minimum and maximum values by the components, if it makes sense.
      Parameters:
      seqs - One or more ModulatedIrSequences
      Returns:
    • getFrequencyWithDefault

      public static double getFrequencyWithDefault(Double frequency)
    • isValidDutyCycle

      public static boolean isValidDutyCycle(Double dutyCycle)
      Checks the argument for null or validity of duty cycle (0, 1).
      Parameters:
      dutyCycle - number to be checked. null is allowed.
      Returns:
    • demodulate

      public static ModulatedIrSequence demodulate(IrSequence irSequence, double threshold)
      From a (non-modulated) IrSequence, consisting of on- and off-periods, remove the modulation and determine a modulation frequency and duty cycle, gathered from the statistics of the input IrSequence.
      Parameters:
      irSequence - input signal
      threshold - Gaps less or equal to this quantity are squashed into a modulated flash.
      Returns:
      ModulatedIrSequence
    • demodulate

      public static ModulatedIrSequence demodulate(IrSequence irSequence)
      Equivalent to the two parameter version with a default threshold.
      Parameters:
      irSequence - input signal, modulated
      Returns:
      ModulatedIrSignal
    • frequencyAverage

      public static Double frequencyAverage(Iterable<ModulatedIrSequence> seqs)
    • getFrequency

      public Double getFrequency()
      Returns:
      modulation frequency in Hz.
    • getFrequencyWithDefault

      public double getFrequencyWithDefault()
    • getDutyCycle

      public Double getDutyCycle()
      Returns:
      Duty cycle.
    • getDutyCycleWithDefault

      public double getDutyCycleWithDefault()
    • toStringFrequency

      public String toStringFrequency(boolean alternatingSigns)
    • toStringFrequency

      public String toStringFrequency()
    • toIrSignal

      public IrSignal toIrSignal()
    • setFrequency

      public ModulatedIrSequence setFrequency(Double newFrequency)
    • approximatelyEquals

      public boolean approximatelyEquals(ModulatedIrSequence irSequence, double absoluteTolerance, double relativeTolerance, double frequencyTolerance, double dutyCycleTolerance)
      Compares two ModulatedIrSequences for (approximate) equality.
      Parameters:
      irSequence - to be compared against this.
      absoluteTolerance - tolerance threshold in microseconds.
      relativeTolerance - relative threshold, between 0 and 1.
      frequencyTolerance - tolerance (absolute) for frequency in Hz.
      dutyCycleTolerance - tolerance (absolute) for duty cycle (< 1).
      Returns:
      equality within tolerance.
    • approximatelyEquals

      public boolean approximatelyEquals(ModulatedIrSequence irSequence, double absoluteTolerance, double relativeTolerance, double frequencyTolerance)
      Compares two ModulatedIrSequences for (approximate) equality.
      Parameters:
      irSequence - to be compared against this.
      absoluteTolerance - tolerance threshold in microseconds.
      relativeTolerance - relative threshold, between 0 and 1.
      frequencyTolerance -
      Returns:
      equality within tolerance.
    • approximatelyEquals

      public boolean approximatelyEquals(ModulatedIrSequence irSequence, double absoluteTolerance, double relativeTolerance)
      Compares two ModulatedIrSequences for (approximate) equality.
      Parameters:
      irSequence - to be compared against this.
      absoluteTolerance - tolerance threshold in microseconds.
      relativeTolerance - relative threshold, between 0 and 1.
      Returns:
      equality within tolerance.
    • approximatelyEquals

      public boolean approximatelyEquals(ModulatedIrSequence irSequence)
      Compares two ModulatedIrSequences for (approximate) equality.
      Parameters:
      irSequence - to be compared against this.
      Returns:
      equality within tolerance.
    • isZeroModulated

      public boolean isZeroModulated()
      Returns:
      true if and only iff the modulation frequency is zero (in numerical sense).
    • addNoise

      public ModulatedIrSequence addNoise(double max)
      Description copied from class: IrSequence
      Adds a random number in the interval [-max, max) to each flash, and subtract it from the next gap. For generating test data for decoders etc. NOTE: initRandom must have been called before this call.
      Overrides:
      addNoise in class IrSequence
      Parameters:
      max - max amount to add/subtract, in microseconds.
      Returns:
      new instance
    • append

      public ModulatedIrSequence append(double delay) throws InvalidArgumentException
      Appends a delay to the end of the ModulatedIrSequence. Original is left untouched.
      Overrides:
      append in class IrSequence
      Parameters:
      delay - microseconds of silence to be appended to the IrSequence.
      Returns:
      Copy of object with additional delay at end.
      Throws:
      InvalidArgumentException
    • append

      Throws:
      InvalidArgumentException
    • chop

      public List<IrSequence> chop(double amount)
      Description copied from class: IrSequence
      Chops a IrSequence in parts. Every gap of length ≥ threshold cause a cut.
      Overrides:
      chop in class IrSequence
      Parameters:
      amount - minimal gap in microseconds to cause a cut.
      Returns:
      List of IrSequences
    • clone

      public ModulatedIrSequence clone()
      Description copied from class: IrSequence
      Creates and returns a copy of this object.
      Overrides:
      clone in class IrSequence
      Returns:
      A copy of this IrSequence.
    • modulate

      public IrSequence modulate()
      Generates a IrSequence, consisting of on- and off-periods, containing the modulation, as per the modulation frequency and duty cycle. If the latter is not present in the calling object, a default (currently 0.4 = 40%) is used.
      Returns:
      (non-modulated) IrSequence