예제 #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
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()
	}

}
예제 #3
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
	}

}
예제 #4
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)
}
예제 #5
0
파일: cdma.go 프로젝트: postfix/gocomm
func (cdma *CDMA) DeSpread(InCH gocomm.Complex128Channel, OutCH gocomm.Complex128Channel) {

	despcode := vlib.Conj(cdma.SpreadSequence)
	var result complex128
	for i := 0; i < len(despcode); i++ {
		rxchips := (<-InCH).Ch
		result += rxchips * cmplx.Conj(despcode[i])
	}
	var chdataOut gocomm.SComplex128Obj
	chdataOut.Ch = result
	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)
}
예제 #8
0
파일: cdma.go 프로젝트: postfix/gocomm
func (cdma *CDMA) DeSpreadBlock(expectedInputSize int, chInway gocomm.Complex128AChannel, OutCH gocomm.Complex128Channel) {

	despcode := vlib.Conj(cdma.SpreadSequence)

	SF := len(despcode)

	despcode = despcode.Scale(1. / (float64(SF)))

	if SF == 0 {
		panic("Spreading Code not Set")
	}
	// maxSymbols := expectedInputSize / SF
	// rxsymbols := vlib.NewVectorC(maxSymbols)
	var recentBuffer vlib.VectorC
	for cnt := 0; cnt < expectedInputSize; {

		data := <-chInway
		rxlen := len(data.Ch)
		// log.Printf("\n Received %d samples out of %d/%d ", rxlen, cnt, expectedInputSize)
		cnt += rxlen
		recentBuffer = append(recentBuffer, data.Ch...)
		for {
			if recentBuffer.Size() < SF {

				break

			} else {
				// log.Printf("\n Symbol %d Ready to Despread with %d", sym, cnt)
				rxchips := recentBuffer[0:SF]
				recentBuffer = recentBuffer[SF:]
				rxsymbols := vlib.DotC(despcode, rxchips)
				var chdataOut gocomm.SComplex128Obj
				chdataOut.Ch = rxsymbols
				OutCH <- chdataOut

			}
		}
	}

	close(chInway)
}
예제 #9
0
파일: fft.go 프로젝트: postfix/gocomm
func GoFFTPerK(outputSymbol gocomm.Complex128Channel, inputsamples vlib.VectorC, k, N int, inverse bool) {

	kbyN := float64(k) / float64(N)
	normalize := complex(1.0/math.Sqrt(float64(N)), 0)
	if !inverse {
		kbyN = kbyN * -1.0
	}

	fbins := vlib.NewVectorC(N)

	for n := 0; n < N; n++ {
		scale := kbyN * float64(n)
		binf := complex(0, 2.0*math.Pi*scale)
		fbins[n] = cmplx.Exp(binf)
	}
	result := vlib.GoDotC(inputsamples, fbins, 4) * normalize
	// result := vlib.DotC(inputsamples, fbins) * normalize

	var data gocomm.SComplex128Obj
	data.Ch = result
	outputSymbol <- data
}
예제 #10
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))
}
예제 #11
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
	}

}