Exemplo n.º 1
0
func GoIFFT_C(samples vlib.VectorC, N int) vlib.VectorC {
	n := runtime.GOMAXPROCS(8)
	if N != samples.Size() {
		samples.Resize(N)
	}
	// fbins := vlib.NewVectorC(N)
	result := vlib.NewVectorC(N)
	NChannels := make([]gocomm.Complex128Channel, N)

	//bigChannel := make(gocomm.Complex128Channel, N)

	for i := 0; i < N; i++ {
		NChannels[i] = gocomm.NewComplex128Channel()
		go GoFFTPerK(NChannels[i], samples, i, N, true)
		//go GoFFTPerK(bigChannel, samples, i, N, false)
	}

	//for i := 0; i < N; i++ {
	//	result[i] = (<-bigChannel).Ch
	//}
	for i := 0; i < N; i++ {
		result[i] = (<-NChannels[i]).Ch
	}

	runtime.GOMAXPROCS(n)
	return result

}
Exemplo n.º 2
0
func (m *ChannelEmulator) InitPins() {
	m.isInitialized = true
	totalpins := m.InPinCount() + m.OutPinCount()
	m.Pins = make(map[string]chipset.PinInfo, totalpins)
	m.PinNames = make(map[int]string, totalpins)
	// b := [...]string{"Penn", "Teller"}
	strlist := [4]string{"symbolIn", "symbolOut"}
	for i := 0; i < totalpins; i++ {
		m.PinNames[i] = strlist[i]
	}

	for i := 0; i < totalpins; i++ {
		var pinfo chipset.PinInfo
		// pinfo.CreateComplex128Channel()
		pinfo.Name = m.PinNames[i]
		if i < m.InPinCount() {
			pinfo.InputPin = true
		} else {
			pinfo.InputPin = false
		}
		m.Pins[m.PinNames[i]] = pinfo

	}

	testcch := gocomm.NewComplex128Channel()

	var dummypin chipset.PinInfo

	/// all Input Pins
	dummypin = m.Pins["symbolIn"]
	dummypin.Id = 0
	dummypin.DataType = reflect.TypeOf(testcch)
	m.Pins["symbolIn"] = dummypin

	/// All output pins
	dummypin = m.Pins["symbolOut"]
	dummypin.Id = 1
	dummypin.SourceName = "fadingchannel/awgn"
	dummypin.DataType = reflect.TypeOf(testcch)
	dummypin.CreateComplex128Channel()
	m.Pins["symbolOut"] = dummypin

}
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
}