当前位置: 首页>>代码示例>>Golang>>正文


Golang cmplx.Exp函数代码示例

本文整理汇总了Golang中math/cmplx.Exp函数的典型用法代码示例。如果您正苦于以下问题:Golang Exp函数的具体用法?Golang Exp怎么用?Golang Exp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Exp函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: IDCTOrthogonal

// IDCTOrthogonal returns Inverse DCT (DCT-III) coefficients given a input
// signal.
func IDCTOrthogonal(dctCoef []float64) []float64 {
	n := len(dctCoef)
	nh := n / 2
	array := make([]complex128, n)

	theta := math.Pi / (2.0 * float64(n))

	c0 := math.Sqrt(1.0 / float64(n))
	c1 := math.Sqrt(2.0 / float64(n))

	// -1/4 Shift
	for k := 1; k < nh; k++ {
		w := cmplx.Exp(complex(0, float64(k)*theta))
		wCont := complex(imag(w), real(w))
		array[k] = w * complex(c1*dctCoef[k], 0)
		array[n-k] = wCont * complex(c1*dctCoef[n-k], 0)
	}
	array[0] = complex(c0*dctCoef[0], 0)
	array[nh] = complex(c1*dctCoef[nh], 0) *
		cmplx.Exp(complex(0, float64(nh)*theta))

	y := fft.IFFT(array)

	x := make([]float64, n)
	for i := 0; i < nh; i++ {
		x[2*i] = float64(n) * real(y[i])
		x[2*i+1] = float64(n) * real(y[n-1-i])
	}

	return x
}
开发者ID:adityanatraj,项目名称:gossp,代码行数:33,代码来源:dct.go

示例2: RotationZ

// Rotation about the Z-axis.
func RotationZ(theta float64) *Gate {
	// R_z(theta) = cos(theta/2)I - i sin(theta/2)Z
	t := theta / 2
	nexp := cmplx.Exp(complex(0, -1*t))
	exp := cmplx.Exp(complex(0, t))
	return newOneQubitGate([4]complex128{
		nexp, 0,
		0, exp})
}
开发者ID:hsavit1,项目名称:quantum-computation,代码行数:10,代码来源:gate_defs.go

示例3: BasisTransform

// Function to compute basis transformation matrix
func BasisTransform(th, phi float64) *[2][2]complex128 {

	BTMatrix := new([2][2]complex128)
	th_2, phi_2 := 0.5*th, 0.5*phi
	csn := cmplx.Cos(complex(th_2, 0.0)) * cmplx.Exp(complex(0.0, -1.0*phi_2))
	sn := cmplx.Sin(complex(th_2, 0.0)) * cmplx.Exp(complex(0.0, phi_2))

	BTMatrix[0][0] = cmplx.Conj(csn)
	BTMatrix[0][1] = cmplx.Conj(sn)
	BTMatrix[1][0] = complex(-1.0, 0.0) * sn
	BTMatrix[1][1] = csn

	return BTMatrix
}
开发者ID:ominux,项目名称:negf_mtj,代码行数:15,代码来源:cmplxSparse.go

示例4: Exp

func (self *ComplexV) Exp() *ComplexV {
	r := Zeros(len(*self))
	for k, a := range *self {
		(*r)[k] = cmplx.Exp(a)
	}
	return r
}
开发者ID:a4a881d4,项目名称:gosse,代码行数:7,代码来源:cmplxv.go

示例5: fft

func fft(output []complex128, input []float64, stride int) {
	n := len(output)
	p := n / 2

	if n == 1 {
		if len(input) > 0 {
			output[0] = complex(input[0], 0)
		} else {
			output[0] = complex(0, 0)
		}
		return
	}

	var oddInput []float64
	if len(input) > stride {
		oddInput = input[stride:]
	}

	fft(output[:p], input, stride*2)
	fft(output[p:], oddInput, stride*2)

	for k, t := range output[:p] {
		a := complex(0, -2*math.Pi*float64(k)/float64(n))
		e := cmplx.Exp(a) * output[k+p]
		output[k] = t + e
		output[k+p] = t - e
	}
}
开发者ID:kierdavis,项目名称:gosound,代码行数:28,代码来源:fft.go

示例6: CDF

// CDF computes the value of the cumulative density function at x.
func (w Weibull) CDF(x float64) float64 {
	if x < 0 {
		return 0
	} else {
		return 1 - cmplx.Abs(cmplx.Exp(w.LogCDF(x)))
	}
}
开发者ID:darrenmcc,项目名称:stat,代码行数:8,代码来源:weibull.go

示例7: DCT

// DCT returns DCT-II coefficients given an input signal.
func DCT(x []float64) []float64 {
	n := len(x)
	nh := n / 2

	evenVector := make([]float64, n)
	for i := 0; i < nh; i++ {
		evenVector[i], evenVector[n-1-i] = x[2*i], x[2*i+1]
	}

	array := fft.FFTReal(evenVector)
	theta := math.Pi / (2.0 * float64(n))

	// 1/4 Shift
	for k := 1; k < nh; k++ {
		w := cmplx.Exp(complex(0, -float64(k)*theta))
		wCont := -complex(imag(w), real(w))
		array[k] *= w
		array[n-k] *= wCont
	}
	array[nh] *= complex(math.Cos(theta*float64(nh)), 0.0)

	dctCoef := make([]float64, n)
	for i := range dctCoef {
		dctCoef[i] = real(array[i])
	}

	return dctCoef
}
开发者ID:adityanatraj,项目名称:gossp,代码行数:29,代码来源:dct.go

示例8: ReconstructSpectrum

// ReconstructSpectrum returns complex spectrum from amplitude
// and phase spectrum.
// angle(X(k)) and |X(k)| -> X(k)
func ReconstructSpectrum(amp, phase []float64) []complex128 {
	spec := make([]complex128, len(amp))
	for i := range amp {
		spec[i] = complex(amp[i], 0.0) * cmplx.Exp(complex(0.0, phase[i]))
	}
	return spec
}
开发者ID:adityanatraj,项目名称:gossp,代码行数:10,代码来源:gossp.go

示例9: NewSDFT32

func NewSDFT32(k, n int, window []float32) *SDFT32 {
	var win []complex64
	if len(window) == 0 {
		win = []complex64{complex(1, 0)}
	} else {
		win = make([]complex64, len(window))
		for i, w := range window {
			win[i] = complex(w, 0)
		}
	}
	s := &SDFT32{
		w: win,
		x: make([]complex64, n),
		e: make([]complex64, len(win)),
		s: make([]complex64, len(win)),
	}
	for i := 0; i < len(win); i++ {
		j := k - len(win)/2 + i
		if j < 0 {
			j += n
		} else if j >= n {
			j -= n
		}
		s.e[i] = complex64(cmplx.Exp(complex(0, 2*math.Pi*float64(j)/float64(n))))
	}
	return s
}
开发者ID:joerocklin,项目名称:go-dsp,代码行数:27,代码来源:sdft.go

示例10: modulateFSKComplex

func modulateFSKComplex(bits []bool, sample_rate float64,
	zero_hz, one_hz, baud float64) []complex64 {
	const π = math.Pi
	Δt := 1.0 / sample_rate
	Δφ_one := 2 * π * one_hz * Δt
	Δφ_zero := 2 * π * zero_hz * Δt
	samples_per_bit := sample_rate / baud

	samples := make([]complex64, 0)
	φ := 0.0
	num_samples := 0.0
	for _, b := range bits {
		num_samples += samples_per_bit
		for ; num_samples > 0.5; num_samples -= 1.0 {
			if b {
				φ += Δφ_one
			} else {
				φ += Δφ_zero
			}
			samples = append(samples,
				complex64(cmplx.Exp(complex(0, φ))))
		}
	}
	return samples
}
开发者ID:tstranex,项目名称:carpcomm,代码行数:25,代码来源:afsk1200.go

示例11: NewQubitWithBlochCoords

// Convenience constructor for a qubit, specified by its spherical coordinates
// on the Bloch sphere.
func NewQubitWithBlochCoords(theta, phi float64) *QReg {
	// |psi> = cos(theta/2) + e^{i phi}sin(theta/2)
	t := complex(theta/2, 0)
	p := complex(phi, 0)
	qreg := &QReg{1, []complex128{cmplx.Cos(t),
		cmplx.Exp(complex(0, 1)*p) * cmplx.Sin(t)}}
	return qreg
}
开发者ID:hsavit1,项目名称:quantum-computation,代码行数:10,代码来源:qreg.go

示例12: SelfEnergyEntries

// Function for calculating the self-energy matrices
func SelfEnergyEntries(currEnergy, modeEnergy, delta0, delta1, potential float64, t0 complex128, BT_Mat *[2][2]complex128) *[2][2]complex128 {
	s := new([2][2]complex128)

	SumEnergy := complex(currEnergy-modeEnergy+0.5*potential-delta0, utils.Zplus)
	SumEnergy /= complex(-2.0, 0.0) * t0
	SumEnergy += complex(1.0, 0.0)

	sig_uu := complex(-1.0, 0.0) * t0 * cmplx.Exp(1.0i*cmplx.Acos(SumEnergy))

	SumEnergy = complex(currEnergy-modeEnergy+0.5*potential-delta1, utils.Zplus)
	SumEnergy /= complex(-2.0, 0.0) * t0
	SumEnergy += complex(1.0, 0.0)

	sig_dd := complex(-1.0, 0.0) * t0 * cmplx.Exp(1.0i*cmplx.Acos(SumEnergy))

	s[0][0] = cmplx.Conj(BT_Mat[0][0])*sig_uu*BT_Mat[0][0] + cmplx.Conj(BT_Mat[1][0])*sig_dd*BT_Mat[1][0]
	s[0][1] = cmplx.Conj(BT_Mat[0][0])*sig_uu*BT_Mat[0][1] + cmplx.Conj(BT_Mat[1][0])*sig_dd*BT_Mat[1][1]
	s[1][0] = cmplx.Conj(BT_Mat[0][1])*sig_uu*BT_Mat[0][0] + cmplx.Conj(BT_Mat[1][1])*sig_dd*BT_Mat[1][0]
	s[1][1] = cmplx.Conj(BT_Mat[0][1])*sig_uu*BT_Mat[0][1] + cmplx.Conj(BT_Mat[1][1])*sig_dd*BT_Mat[1][1]

	return s
}
开发者ID:ominux,项目名称:negf_mtj,代码行数:23,代码来源:cmplxSparse.go

示例13: DFT

// Performs a DFT or a partial DFT on in, storing the output in out
// if start == 0 && stride == 1 the DFT is done on the entire array,
// otherwise it is done on every stride elements, starting at start.
func DFT(in, out []complex128, start, stride int) {
	N := len(in) / stride
	if N == 1 {
		out[start] = in[start]
		return
	}
	factor := -2 * math.Pi * complex(0, 1) / complex(float64(N), 0)
	for k := 0; k < N; k++ {
		out[start+k*stride] = 0
		for n := start; n < len(in); n += stride {
			out[start+k*stride] += in[n] * cmplx.Exp(factor*complex(float64(k*(n/stride)), 0))
		}
	}
}
开发者ID:kreshikhin,项目名称:go-fft,代码行数:17,代码来源:fft.go

示例14: genTwiddle

func genTwiddle(stage0, stage1, s int) *Cmplx32v {
	var factor float64 = 32768.
	t := make([]complex128, stage0*stage1*s)
	for s0 := 0; s0 < stage0; s0 += 1 {
		for s1 := 0; s1 < stage1; s1 += 1 {
			for s2 := 0; s2 < s; s2 += 1 {
				p := -1. * math.Pi * 2. * float64(s0) * float64(s1) / float64(stage0*stage1)
				a := complex(factor, 0.) * cmplx.Exp(complex(0., p))
				t[s0*stage1*s+s1*s+s2] = complex(imag(a), real(a))
			}
		}
	}
	return ToM128Buf(t)
}
开发者ID:a4a881d4,项目名称:gosse,代码行数:14,代码来源:fft2048.go

示例15: fft

func fft(input, output []complex64, dir float64, stride int) {
	N := len(output)
	if N == 1 {
		output[0] = input[0]
		return
	}
	N2 := N / 2
	fft(input, output[:N2], dir, stride*2)
	fft(input[stride:], output[N2:], dir, stride*2)
	for fx := 0; fx < N2; fx++ {
		o := output[fx+N2]
		o *= complex64(cmplx.Exp(complex(0.0, dir*float64(fx)/float64(N))))
		output[fx+N2] = output[fx] - o
		output[fx] += o
	}
}
开发者ID:xunatai,项目名称:ft,代码行数:16,代码来源:main.go


注:本文中的math/cmplx.Exp函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。