Exemplo n.º 1
0
func main() {

	rand.Seed(time.Now().Unix())
	rand.Seed(1)

	// for i := 0; i < 256; i++ {
	// 	fmt.Printf("\n %d %c ", i, i)
	// }

	var N = 10
	bits2 := vlib.NewOnesB(10)

	fmt.Print("\nRandBits  = ", vlib.Randsrc(N, 2))

	fmt.Print("\nRandNoise  = ", vlib.RandNCVec(N, 1))
	// msg := sources.RandChars(N)
	msg := vlib.RandReadableChars(N)
	strmsg := string(msg)
	// strmsg = "Hello world, this is a message sent"

	// var msg = "HELLO SENDIL"

	fmt.Printf("\nRandChars = %s ", strmsg)
	fmt.Print("\nBit messages  = ", sources.BitsFromMessage(strmsg))
	bits3 := sources.BitsFromMessage(strmsg)
	fmt.Printf("\nBits  : %v", bits2)
	fmt.Printf("\nBits  : %v ", bits3)

	bpskModem := core.NewModem()
	// bpskModem.Init(1)
	fmt.Printf("\n%v", bpskModem)
	fmt.Printf("\n%f", bpskModem.Constellation)

	print("\n") // Legacy
	// qpskModem := modem.NewModem(2, "QPSK")

	qpskModem := new(core.Modem)
	qpskModem.Init(2, "QPSK")
	fmt.Printf("\n%v", qpskModem)
	fmt.Printf("\n%f", qpskModem.Constellation)
	qpskModem.ModulateBits(bits2)
}
Exemplo n.º 2
0
func main() {

	fmt.Print("GOPROCS:=", runtime.GOMAXPROCS(6))
	runtime.SetCPUProfileRate(-1)
	start := time.Now()

	user1 := NewSetup()
	user2 := NewSetup()
	user3 := NewSetup()
	// user4 := NewSetup()
	// user5 := NewSetup()
	// fmt.Printf("\nLink %v", user1)
	// fmt.Printf("\nLink %v", user2)
	data, err := ioutil.ReadFile("settings.json")
	if err != nil {
		log.Print("Unable to Read File : ", err)
	}
	result := chipset.GetMetaInfo(data, "Modem1")
	fmt.Print("Found Setting : ", result, "len = ", len(result))
	var jsons string = `{"NBlocks":100,"snr":"0:2:16","SF":1}`
	var mymodem core.Modem
	mymodem.SetName("Modem2")
	mymodem.SetJson(data)

	fmt.Print("SOMETHING", string(mymodem.GetJson()))
	user1.Set(jsons)
	user2.Set(jsons)
	user3.Set(jsons)
	// user3.Set(jsons)
	// user4.Set(jsons)
	// user5.Set(jsons)
	fmt.Printf("Starting simulation ...")

	fmt.Printf("\n started user 1")
	go user1.Run()
	fmt.Printf("\n started user 2")
	go user2.Run()
	// go user3.Run()
	// go user4.Run()

	// 	user1.Run()
	// 	user2.Run()
	// 	user3.Run()
	// 	user4.Run()
	fmt.Printf("\n started user 3")
	user3.Run()

	// time.Sleep(10 * time.Second)
	fmt.Print("\n Elapsed : ", time.Since(start))

}
Exemplo n.º 3
0
func (s *setup) SimulateLink(SNR float64, pdp vlib.VectorF, spcode vlib.VectorC, uid int) float64 {
	var cdma core.CDMA
	bitTs := 1.0
	cdma.InitializeChip()

	cdma.SetSpreadCode(spcode, true)
	var mpchannel core.MPChannel
	mpchannel.InitializeChip()
	///
	param := core.NewIIDChannel()
	param.SetPDP(pdp)
	param.Mode = "iid"
	symbolTs := 2 * bitTs
	param.Ts = 5 * symbolTs // bitTs // dataArray.Ts * float64(BlockSize)
	mpchannel.InitParam(param)

	var modem core.Modem

	modem.InitializeChip()
	modem.InitModem(2)

	feedback := make(gocomm.Complex128AChannel, 10)
	mpchannel.SetFeedbackChannel(feedback)
	modem.SetFeedbackChannel(feedback)

	bitsample := vlib.VectorB(sources.RandB(s.BlockSize))
	bitChannel := gocomm.NewBitChannel()
	var dataArray gocomm.SBitObj
	dataArray.MaxExpected = bitsample.Size()
	dataArray.Message = fmt.Sprintf("Src %f  ", SNR)
	dataArray.Ts = bitTs
	dataArray.MaxExpected = s.BlockSize
	// fmt.Printf("bits=%v", bitsample)

	go (func(bitChannel gocomm.BitChannel) {
		for i := 0; i < s.BlockSize; i++ {
			dataArray.Ch = bitsample[i]

			// fmt.Printf("\n Transmitting .. %v", dataArray)
			bitChannel <- dataArray

			// modem.ModulateFn(dataArray)
			// symCH <- dataArray
			dataArray.TimeStamp += dataArray.Ts
		}
	})(bitChannel)

	go modem.Modulate(bitChannel)
	// fmt.Printf("Generated Bits", samples)
	symCH := chipset.ToComplexCH(modem.PinByName("outputPin0"))
	go cdma.Spread(symCH)

	OutCH := chipset.ToComplexACH(cdma.PinByID(2))
	ch1 := gocomm.NewComplex128Channel()
	go gocomm.ComplexA2Complex(OutCH, ch1)
	/// Add Multipath channel
	go mpchannel.Channel(ch1)
	ch2 := chipset.ToComplexCH(mpchannel.PinByName("outputPin0"))
	/// Add Noise
	noiseDb := 1.0 / dsp.InvDb(SNR)
	// fmt.Printf("\n %f AWGN Noise : %f", SNR, noiseDb)
	var awgn channel.ChannelEmulator
	awgn.SetNoise(0, noiseDb)
	awgn.InitializeChip()

	go awgn.AWGNChannel(ch2)
	ch3 := chipset.ToComplexCH(awgn.PinByID(1))

	// go awgn. (1/noiseDb, samples)

	go cdma.DeSpread(ch3)
	ch4 := chipset.ToComplexCH(cdma.PinByID(3))
	//go sink.CROremote(cdma.PinByID(3))

	go modem.DeModulate(ch4)
	ch5 := chipset.ToComplexCH(modem.PinByID(3)) // .Channel.(gocomm.Complex128Channel)
	// gocomm.WGroup.Add(1)

	// gocomm.WGroup.Add(1)
	// go gocomm.SinkComplex(ch4, "")
	// ///
	// bitsample
	var BER core.BER
	BER.TrueBits = bitsample
	BER.InitializeChip()
	ch6 := gocomm.NewBitChannel()
	BER.Reset()
	go BER.BERCount(ch6)
	go (func(ch6 gocomm.BitChannel) {
		count := 1
		for i := 0; i < count; i++ {
			data := <-ch5
			count = data.MaxExpected
			//fmt.Printf("\n sym received %#v", data)
			rxbits := gocomm.Complex2Bits(data)
			// fmt.Printf("\n bits converted received %#v", rxbits)
			ch6 <- rxbits[0]
			ch6 <- rxbits[1]
			// dec := gocomm.Complex2Bits(data)
			// result[2*i] = dec[0]
			// result[2*i+1] = dec[1]

			// fmt.Printf("\n %v", gocomm.Complex2Bits(data))

		}

	})(ch6)
	ch7 := chipset.ToFloatCH(BER.PinByName("outputPin0"))
	count := 1
	// result := vlib.NewVectorB(BlockSize)
	var result float64 = 0
	for i := 0; i < count; i++ {

		err := <-ch7
		count = err.MaxExpected
		// fmt.Printf("\nerr=(%f,%v) %#v", err.TimeStamp, err.Ch, err)
		result = err.Ch
	}
	// err := float64(bitsample.CountErrors(result)) / float64(BlockSize)
	// fmt.Printf("\ntxbits=%v", bitsample)
	// fmt.Printf("\nrxbits=%v", result)
	// fmt.Printf("\nErr=%v %v", bitsample.CountErrors(result), err)
	// gocomm.WGroup.Wait()
	if uid == 0 {
		s.snr_ber[SNR] += result
	} else {
		s.snr_ber1[SNR] += result
	}

	// snr_ber[SNR] /= s.snr_block[SNR]
	s.updateTable()
	// fmt.Printf("\r BLOCK %v \n BER : %v", s.snr_block, snr_ber)
	return result
}
Exemplo n.º 4
0
func main() {

	rand.Seed(time.Now().Unix())
	// rand.Seed(1)

	start := time.Now()
	var N = 10
	var N0 float64 = 1.0 / 10
	txbits := vlib.VectorB(sources.RandB(N))

	qpskModem := new(core.Modem)
	var BitsPerSymbol = 2
	qpskModem.Init(BitsPerSymbol, "")
	fmt.Printf("\n%v", qpskModem)

	/// Take every N-bit and push to modem-channel-demod

	length := len(txbits)
	// slength := length / BitsPerSymbol

	//var result = make([]complex128, slength)
	/// Actual Modulation happens here

	cnt := 0
	// rxcnt := 0
	// symCH := make([]chan complex128, length)
	COUNT := length / 2
	rxCH := make([]chan []uint8, COUNT)

	for i := 0; i < COUNT; i++ {
		rxCH[i] = make(chan []uint8)
	}

	for i := 0; i < length; i += BitsPerSymbol {

		symCH := make(chan complex128)

		go qpskModem.GenerateSymbolCH(cnt, txbits[i:i+BitsPerSymbol], symCH)
		go func(twowayChannel chan complex128, cnt int) {

			symbol := <-twowayChannel
			noise := sources.RandNC(N0)
			fmt.Printf("\n Added Noise %d %v", cnt, noise)
			rxsymbol := symbol + noise
			twowayChannel <- rxsymbol
		}(symCH, cnt)
		go qpskModem.DemodSymbolCH(cnt, symCH, rxCH[cnt])

		cnt++
	}

	ORDER := true
	//// UNORDERED receiver bits...
	for i := 0; i < COUNT; i++ {

		if ORDER {
			func(cnt int, tmpRxCh chan []uint8) {
				for rxbits := range tmpRxCh {
					fmt.Printf("\n Unordered Loop Detected bits %d %v", cnt, rxbits)
				}

			}(i, rxCH[i])
		} else {
			go func(cnt int, tmpRxCh chan []uint8) {
				for rxbits := range tmpRxCh {
					fmt.Printf("\n Unordered Loop Detected bits %d %v", cnt, rxbits)
				}

			}(i, rxCH[i])
			fmt.Printf("Waiting for routines to finish")
			time.Sleep(2 * time.Second)

		}
	}

	/// Ordered read from the Receiver channels
	// cnt = 0
	// for _, channel := range rxCH {

	// 	for rxbits := range channel {
	// 		fmt.Printf("\n Outer Loop Detected bits %d %v", cnt, rxbits)
	// 	}
	// 	cnt++
	// }

	// txsymbols := qpskModem.ModulateBits(txbits)
	// rxsymbols := vlib.ElemAddCmplx(txsymbols, sources.Noise(len(txsymbols), N0))
	// rxbits := qpskModem.DeModulateBits(rxsymbols)

	// // fmt.Printf("\nTx=%v", txbits)
	// // fmt.Printf("\nRx=%v", rxbits)
	// fmt.Printf("\nERR=%v/%d = %f", txbits.CountErrors(rxbits), len(txbits), float64(txbits.CountErrors(rxbits))/float64(len(txbits)))
	fmt.Printf("\n\n Elapsed %v \n", time.Since(start).String())
}