001 package util.wavelet; 002 import java.util.List; 003 004 /** Wrapper for an array of signal values and an array of noise values and their multiplier. 005 * @author John Talbot 006 */ 007 public class Signal extends SimpleSignal { 008 009 /** Noise for this signal. */ 010 float[] noise; 011 012 /** The noise multiplier (when sigmas = 3.0 confidence = 99.9 percent) */ 013 float noiseMultiplier = 1f; // Should not be changed once set in constructor 014 015 /** 016 * Construct using signal array, the noise multiplier equal to 1 and the noise array must be set at a later time. 017 * 018 * @param value signal array 019 */ 020 public Signal(float[] value) { 021 this(value, new float[value.length]); 022 } 023 024 /** 025 * Copy constructor, the noise multiplier equal to 1 and the noise array must be set at a later time. 026 * 027 * @param signal the signal 028 */ 029 public Signal(SimpleSignal signal) { 030 super(signal); 031 } 032 033 /** 034 * Construct using signal and noise array, the noise multiplier equal to 1. 035 * Pre-condition: arrays must be of equal size. 036 * 037 * @param value the signal value 038 * @param noise the noise 039 */ 040 public Signal(float[] value, float[] noise) { 041 this(value, noise, 1f); 042 } 043 044 /** 045 * Construct using signal and noise array, the noise multiplier equal to 1. 046 * Pre-condition: arrays must be of equal size. 047 * 048 * @param signal the signal 049 * @param noise the noise 050 */ 051 public Signal(SimpleSignal signal, float[] noise) { 052 this(signal, noise, 1f); 053 } 054 055 /** Construct using signal and noise array and the given noise multiplier. 056 * Pre-condition: arrays must be of equal size. 057 * 058 * @param value the signal array 059 * @param noise the noise array 060 * @param noiseMultiplier the noise multiplier (when sigmas = 3.0 confidence = 99.9 percent) 061 */ 062 public Signal(float[] value, float[] noise, float noiseMultiplier) { 063 super(value); 064 this.noise = noise; 065 this.noiseMultiplier = noiseMultiplier; 066 } 067 068 /** Construct using signal and noise array and the given noise multiplier. 069 * Pre-condition: arrays must be of equal size. 070 * 071 * @param signal the signal 072 * @param noise the noise array 073 * @param noiseMultiplier the noise multiplier (when sigmas = 3.0 confidence = 99.9 percent) 074 */ 075 public Signal(SimpleSignal signal, float[] noise, float noiseMultiplier) { 076 super(signal); 077 this.noise = noise; 078 this.noiseMultiplier = noiseMultiplier; 079 } 080 081 /** Get the noise value at the given position and deal with boundary conditions when position is out of range. 082 * @param position the position 083 * @return noise at the given position or extrapolated value if position is out of range 084 */ 085 public float getNoise(int position) { 086 return noise[boundaryCondition.test(position, size())]; 087 } 088 089 /** Get a defensive copy of the noise for this signal. 090 * @return a copy of the noise 091 */ 092 public SimpleSignal getNoise() { 093 return new SimpleSignal(noise); 094 } 095 096 /** Set the noise for this signal (using defensive copy). 097 * @param noiseSignal the noise signal 098 */ 099 public void setNoise(SimpleSignal noiseSignal) { 100 System.arraycopy(noiseSignal.values, 0, noise, 0, size()); 101 } 102 103 /** Set the noise value at the given position and deal with boundary conditions when position is out of range. 104 * Precondition : 0 ≥ <code>index</code> ≤ size(). 105 * @param position the position 106 * @param noiseValue the value to set the signal to 107 */ 108 public void setNoise(int position, float noiseValue) { 109 noise[boundaryCondition.test(position, size())] = noiseValue; 110 } 111 112 /** Get the noise multiplier. 113 * @return noise multiplier at the given position 114 */ 115 public float getNoiseMultiplier() { 116 return noiseMultiplier; 117 } 118 119 /** Test if the signal at the given position is above the noise times times the noise multiplier. 120 * @param position the position 121 * @return true if the signal is above the noise times the noise multiplier 122 */ 123 public boolean isAboveNoise(int position) { 124 return (getValue(position) > noiseMultiplier * getNoise(position)); 125 } 126 127 /** Test if the signal at the given position is below the noise times times a given noise multiplier. 128 * @param position the position 129 * @return true if the signal is below the noise times the noise multiplier 130 */ 131 public boolean isBelowNoise(int position) { 132 return (getValue(position) < - noiseMultiplier * getNoise(position)); 133 } 134 135 136 }