func (b *Matcher) findProbableMatch(wave []float64, frameIndex int) *frame.Frame {

	frame := &frame.Frame{}

	nfft := math.Pow(2, float64(b.options.NFFTPower))

	//topCandidate := b.frames[0]

	// Perform Pwelch on wave
	fs := float64(b.options.SampleRate)
	opts := &spectral.PwelchOptions{
		NFFT: int(nfft),
	}

	guardOffset := int((float64(len(wave)) / 100.0) * 0.0)

	guardedWave := wave[guardOffset : len(wave)-1]

	powers, frequencies := spectral.Pwelch(guardedWave, fs, opts)

	carriers := b.options.Carriers()
	numberOfCarriers := len(carriers)

	minimumCarrierAdjusted := float64(carriers[0] - 5)
	maximumCarrierAdjusted := float64(carriers[numberOfCarriers-1] + 5)

	carriersFound := 0
	minimumDistance := float64(-1)
	searchingCarrier := carriers[0]

	locatedCarrierValues := make([]float64, numberOfCarriers)

	for i, frequency := range frequencies {

		if frequency < maximumCarrierAdjusted && frequency > minimumCarrierAdjusted {

			distance := math.Abs(frequency - float64(searchingCarrier))

			headerPacket := frameIndex <= 1
			power := powers[i-1]

			if minimumDistance < distance && minimumDistance != float64(-1) {

				if headerPacket {
					evenFrame := frameIndex%2 == 0
					evenCarrier := carriersFound%2 == 0

					if evenFrame && evenCarrier || !evenFrame && !evenCarrier {
						carrierActive[carriersFound] = power
					} else {
						carrierResting[carriersFound] = power
					}
				} else {
					activePower := carrierActiveAvg // carrierActive[carriersFound]
					inactivePower := carrierRestingAvg

					activeCarrierDistance := math.Abs(activePower - power)
					restingCarrierDistance := math.Abs(inactivePower - power)

					value := 1

					if activeCarrierDistance/2 > restingCarrierDistance {
						value = 0
					}

					frame.Data = append(frame.Data, value)
				}

				locatedCarrierValues[carriersFound] = powers[i-1]

				carriersFound++
				if carriersFound < numberOfCarriers {
					searchingCarrier = carriers[carriersFound]
					minimumDistance = float64(-1)
				} else {
					break
				}
			} else {
				minimumDistance = distance
			}

		}
	}

	//fmt.Println(frame.Data)

	//ioutil.WriteFile("data.csv", []byte(csvData), 0644)

	return frame
}
// FindProbableMatch returns the most likely match for a wave
FindProbableMatch returns the most likely match for a wave
// FindProbableMatch returns the most likely match for a wave
func (b *Matcher) findProbableMatch(wave []float64, frameIndex int) *frame.Frame {
	frame := &frame.Frame{}
	nfft := math.Pow(2, float64(b.options.NFFTPower))
	fs := float64(b.options.SampleRate)
	opts := &spectral.PwelchOptions{
		NFFT: int(nfft),
	}
	guardOffset := int((float64(len(wave)) / 100.0) * 0.0)
	guardedWave := wave[guardOffset : len(wave)-1]
	powers, frequencies := spectral.Pwelch(guardedWave, fs, opts)
	carriers := b.options.Carriers()
	numberOfCarriers := len(carriers)
	minimumCarrierAdjusted := float64(carriers[0] - 5)
	maximumCarrierAdjusted := float64(carriers[numberOfCarriers-1] + 5)
	carriersFound := 0
	minimumDistance := float64(-1)
	searchingCarrier := carriers[0]
	locatedCarrierValues := make([]float64, numberOfCarriers)
	for i, frequency := range frequencies {
		if frequency < maximumCarrierAdjusted && frequency > minimumCarrierAdjusted {
			distance := math.Abs(frequency - float64(searchingCarrier))
			headerPacket := frameIndex <= 1
			power := powers[i-1]
			if minimumDistance < distance && minimumDistance != float64(-1) {
				if headerPacket {
					evenFrame := frameIndex%2 == 0
					evenCarrier := carriersFound%2 == 0
					if evenFrame && evenCarrier || !evenFrame && !evenCarrier {
						carrierActive[carriersFound] = power
					} else {
						carrierResting[carriersFound] = power
					}
				} else {
					activePower := carrierActiveAvg 
					inactivePower := carrierRestingAvg
					activeCarrierDistance := math.Abs(activePower - power)
					restingCarrierDistance := math.Abs(inactivePower - power)
					value := 1
					if activeCarrierDistance/2 > restingCarrierDistance {
						value = 0
					}
					frame.Data = append(frame.Data, value)
				}
				locatedCarrierValues[carriersFound] = powers[i-1]
				carriersFound++
				if carriersFound < numberOfCarriers {
					searchingCarrier = carriers[carriersFound]
					minimumDistance = float64(-1)
				} else {
					break
				}
			} else {
				minimumDistance = distance
			}
		}
	}
	return frame
}
func ( b * Matcher ) findProbableMatch ( wave [ ] float64 , frameIndex int ) * frame . Frame { frame := & frame . Frame { } nfft := math . Pow ( 2 , float64 ( b . options . NFFTPower ) ) fs := float64 ( b . options . SampleRate ) opts := & spectral . PwelchOptions { NFFT : int ( nfft ) , } guardOffset := int ( ( float64 ( len ( wave ) ) / 100.0 ) * 0.0 ) guardedWave := wave [ guardOffset : len ( wave ) - 1 ] powers , frequencies := spectral . Pwelch ( guardedWave , fs , opts ) carriers := b . options . Carriers ( ) numberOfCarriers := len ( carriers ) minimumCarrierAdjusted := float64 ( carriers [ 0 ] - 5 ) maximumCarrierAdjusted := float64 ( carriers [ numberOfCarriers - 1 ] + 5 ) carriersFound := 0 minimumDistance := float64 ( - 1 ) searchingCarrier := carriers [ 0 ] locatedCarrierValues := make ( [ ] float64 , numberOfCarriers ) for i , frequency := range frequencies { if frequency < maximumCarrierAdjusted && frequency > minimumCarrierAdjusted { distance := math . Abs ( frequency - float64 ( searchingCarrier ) ) headerPacket := frameIndex <= 1 power := powers [ i - 1 ] if minimumDistance < distance && minimumDistance != float64 ( - 1 ) { if headerPacket { evenFrame := frameIndex % 2 == 0 evenCarrier := carriersFound % 2 == 0 if evenFrame && evenCarrier || ! evenFrame && ! evenCarrier { carrierActive [ carriersFound ] = power } else { carrierResting [ carriersFound ] = power } } else { activePower := carrierActiveAvg inactivePower := carrierRestingAvg activeCarrierDistance := math . Abs ( activePower - power ) restingCarrierDistance := math . Abs ( inactivePower - power ) value := 1 if activeCarrierDistance / 2 > restingCarrierDistance { value = 0 } frame . Data = append ( frame . Data , value ) } locatedCarrierValues [ carriersFound ] = powers [ i - 1 ] carriersFound ++ if carriersFound < numberOfCarriers { searchingCarrier = carriers [ carriersFound ] minimumDistance = float64 ( - 1 ) } else { break } } else { minimumDistance = distance } } } return frame }
FindProbableMatch returns the most likely match for a wave
FindProbableMatch returns the most likely match for a wave
//topCandidate := b.frames[0] // Perform Pwelch on wave // carrierActive[carriersFound] //fmt.Println(frame.Data) //ioutil.WriteFile("data.csv", []byte(csvData), 0644)