func main() { var channel core.MPChannel channel.InitializeChip() N := 100 param := core.NewIIDChannel() param.Ts = 4 pdp := vlib.VectorF{1, .1} param.SetPDP(pdp) param.Mode = "" channel.InitParam(param) // samples := vlib.VectorC(sources.RandNCVec(N, 1)) samples := vlib.NewOnesC(N) var data gocomm.SComplex128Obj data.Ts = 2 for i := 0; i < N; i++ { data.Ch = samples[i] // fmt.Printf("\n Input %d = %v", i, data) chout := channel.ChannelFn(data) fmt.Printf("\n %d I/O : %v ==> %v", i, data.Ch, chout.Ch) data.UpdateTimeStamp() } }
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 }