示例#1
0
文件: modem.go 项目: postfix/gocomm
func (m *Modem) Modulate(bitchan gocomm.BitChannel, symbolChannel gocomm.Complex128Channel) {
	// fmt.Printf("\n Reading bits from  %v", bitchan.Ch)
	var chdataIn gocomm.SBitObj
	var chdataOut gocomm.SComplex128Obj

	// fmt.Printf("\n MaxSymbols expected is %d , message = %v", bitchan.MaxExpected, bitchan.Message)

	var bits []uint8
	bits = make([]uint8, m.bitsPerSymbol)
	length := m.bitsPerSymbol
	N := m.bitsPerSymbol

	for i := 0; i < length; i++ {
		chdataIn = <-bitchan
		chdataOut.MaxExpected = chdataIn.MaxExpected / 2
		bits[i] = chdataIn.Ch
	}

	key := toStr(bits[0:N])
	chdataOut.Ch = m.constellationTable[key]
	symbolChannel <- chdataOut

	// fmt.Printf("\n Writing symbols to  %v", symbolChannel.Ch)

}
示例#2
0
文件: awgn.go 项目: postfix/gocomm
/// Fading/AWGN Channel that operates on each sample
func (m *ChannelEmulator) FadingChannel(InCH gocomm.Complex128Channel) {
	outCH := m.Pins["symbolOut"].Channel.(gocomm.Complex128Channel)
	NextSize := 1
	N0 := .01 /// 10dB SNR
	var chdataOut gocomm.SComplex128Obj
	var chdataIn gocomm.SComplex128Obj
	for i := 0; i < NextSize; i++ {

		chdataIn = <-InCH
		sample := chdataIn.Ch
		chdataOut.Message = chdataIn.Message
		chdataOut.MaxExpected = chdataIn.MaxExpected
		NextSize = chdataIn.MaxExpected

		var hn complex128
		if chdataIn.Message == "BYPASS" {
			hn = 1
			chdataOut.Ch = sample
		} else {
			hn = sources.RandNC(N0)
			psample := sample * hn
			chdataOut.Ch = psample
		}

		outCH <- chdataOut
	}

}
示例#3
0
文件: modem.go 项目: postfix/gocomm
func (m *Modem) ModulateBlock(OutBlockSize int, bitchan gocomm.BitChannel, symbolChannel gocomm.Complex128Channel) {

	for i := 0; i < OutBlockSize; i++ {
		var chdataIn gocomm.SBitObj
		var chdataOut gocomm.SComplex128Obj

		// fmt.Printf("\n MaxSymbols expected is %d , message = %v", bitchan.MaxExpected, bitchan.Message)

		var bits []uint8
		bits = make([]uint8, m.bitsPerSymbol)
		length := m.bitsPerSymbol
		N := m.bitsPerSymbol

		for i := 0; i < length; i++ {
			chdataIn = <-bitchan
			chdataOut.MaxExpected = chdataIn.MaxExpected / 2
			chdataOut.Message = chdataIn.Message
			bits[i] = chdataIn.Ch
			OutBlockSize = chdataIn.MaxExpected

		}

		key := toStr(bits[0:N])
		chdataOut.Ch = m.constellationTable[key]

		symbolChannel <- chdataOut
	}
	// close(bitchan.Ch)
}
示例#4
0
文件: cdma.go 项目: postfix/gocomm
func main() {

	N := 20 /// 20 samples
	L := 4  /// 5tap channel
	begin := time.Now()

	var cdma core.CDMA
	cdma.InitializeChip()
	cdma.SetSpreadCode(vlib.NewOnesC(L), true)

	samples := vlib.VectorC(sources.RandNCVec(N, 1))
	var data gocomm.SComplex128Obj
	/// METHOD A
	data.Ts = 1
	data.TimeStamp = 0
	data.MaxExpected = N
	data.Message = ""
	for i := 0; i < N; i++ {
		data.Next(samples[i])
		chips := cdma.SpreadFn(data)
		output := cdma.DeSpreadFn(chips)
		fmt.Printf("\nTxSymbol %v ", data)
		// fmt.Printf("\nTx %v ", chips)
		fmt.Printf("\nRxSymbol %v ", output)
	}

	/// METHOD B
	// dataArray.MaxExpected = samples.Size()
	// inCHA := gocomm.NewComplex128Channel()
	// outputPin := filter.PinByID(1)

	// go filter.Filter(inCHA)
	// go chipset.Sink(outputPin)
	// /// Actual data pushing
	// for i := 0; i < N; i++ {
	// 	dataArray.MaxExpected = N
	// 	dataArray.Ch = samples[i]
	// 	inCHA <- dataArray
	// }

	//fmt.Printf("\nFilter Residues %v", filter.FilterMemory)

	//  Of code
	fmt.Printf("\nTime Elapsed : %v\n", time.Since(begin))
}
示例#5
0
文件: awgn.go 项目: postfix/gocomm
func (m *ChannelEmulator) AWGNChannel(dummy gocomm.Complex128Channel) {
	// fmt.Printf("\n Noise ready to Input %v", dummy)
	outCH := m.Pins["symbolOut"].Channel.(gocomm.Complex128Channel)
	// fmt.Printf("\n Output ready to Output %v", outCH)
	var chdataOut gocomm.SComplex128Obj
	var chdataIn gocomm.SComplex128Obj
	samples := 1
	// result := make([]complex64, samples)
	var StdDev float64 = math.Sqrt(m.noise * .5)
	var Mean float64 = m.Mean
	var noise complex128
	// var noisevector vlib.VectorC
	for i := 0; i < samples; i++ {

		chdataIn = <-dummy
		chdataOut.MaxExpected = chdataIn.MaxExpected
		samples = chdataIn.MaxExpected

		// fmt.Printf("\nAWGN expects %d samples @ %v", samples, dummy)
		chdataOut.Message = chdataIn.Message
		chdataOut.Ts = chdataIn.Ts
		chdataOut.TimeStamp = chdataIn.TimeStamp
		if !strings.Contains(chdataIn.Message, "BYPASS") {

			if Mean == 0 && StdDev == 1 {
				noise = complex128(complex(rand.NormFloat64(), rand.NormFloat64()))
			} else {
				noise = complex128(complex(rand.NormFloat64()*StdDev+Mean, rand.NormFloat64()*StdDev+Mean))

			}
			// noisevector = append(noisevector, noise)
			chdataOut.Ch = chdataIn.Ch + noise

		} else {
			chdataOut.Ch = chdataIn.Ch

		}
		//fmt.Printf("\nNoise%f=%f", StdDev, noisevector)
		outCH <- chdataOut
	}

}
示例#6
0
文件: wire.go 项目: postfix/gocomm
func ChannelDuplexer(InCH gocomm.Complex128Channel, OutCHA []gocomm.Complex128Channel) {
	Nchanels := len(OutCHA)
	var chdataIn gocomm.SComplex128Obj
	var chdataOut gocomm.SComplex128Obj
	NextSize := 1
	for cnt := 0; cnt < NextSize; cnt++ {
		chdataIn = <-InCH
		data := chdataIn.Ch
		NextSize = chdataIn.MaxExpected

		// fmt.Printf("%d InputDuplexer : %v ", cnt, data)
		for i := 0; i < Nchanels; i++ {
			chdataOut.Ch = data
			chdataOut.MaxExpected = NextSize
			chdataOut.Message = chdataIn.Message
			OutCHA[i] <- chdataOut
		}
	}
	close(InCH)
}
示例#7
0
文件: modem.go 项目: postfix/gocomm
func (m *Modem) DeModulateBlock(OutBlockSize int, InCH gocomm.Complex128Channel, outCH gocomm.Complex128Channel) {
	var chdataIn gocomm.SComplex128Obj
	var chdataOut gocomm.SComplex128Obj

	for i := 0; i < OutBlockSize; i++ {
		chdataIn = <-InCH
		symbol := chdataIn.Ch
		OutBlockSize = chdataIn.MaxExpected

		bits := m.DeModulateBits(symbol)
		result := complex(float64(bits[0]), float64(bits[1]))

		chdataOut.Ch = result
		chdataOut.MaxExpected = OutBlockSize
		chdataOut.Message = chdataIn.Message
		// fmt.Printf("\n Writing demod bits to  %v ", outCH.Ch)
		outCH <- chdataOut
	}
	// close(InCH.Ch)
}