示例#1
0
文件: fft_test.go 项目: gonuts/go-dsp
func TestFFT2(t *testing.T) {
	for _, ft := range fft2Tests {
		v := FFT2Real(ft.in)
		if !dsputils.PrettyClose2(v, ft.out) {
			t.Error("FFT2 error\ninput:", ft.in, "\noutput:", v, "\nexpected:", ft.out)
		}

		vi := IFFT2(ft.out)
		if !dsputils.PrettyClose2(vi, dsputils.ToComplex2(ft.in)) {
			t.Error("IFFT2 error\ninput:", ft.out, "\noutput:", vi, "\nexpected:", dsputils.ToComplex2(ft.in))
		}
	}
}
示例#2
0
func makeKSpaceData() [][]complex64 {
	nX, nY := 256, 128
	square := make([][]float64, nY)
	for y := 0; y < nY; y++ {
		square[y] = make([]float64, nX)
		for x := 0; x < nX; x++ {
			if (x > nX/4) && (x < 3*nX/4) && (y > nY/8) && (y < 7*nY/8) {
				square[y][x] = 1.0
			} else {
				square[y][x] = 0.0
			}
		}
	}

	saveFloat64Image(square, "square.png")

	squarec := dsputils.ToComplex2(square)

	shift := fftshift2(squarec)
	saveCmplx128Image(shift, "shifted.png")

	fft_square := fftshift2(fft.FFT2(fftshift2(squarec)))

	data := make([][]complex64, nY)
	for a := 0; a < nY; a++ {
		data[a] = make([]complex64, nX)
		for b := 0; b < nX; b++ {
			data[a][b] = complex64(fft_square[a][b])
		}
	}

	return data
}
示例#3
0
文件: fft.go 项目: rfielding/go-dsp
// IFFT2Real returns the 2-dimensional, inverse FFT of the real-valued matrix.
func IFFT2Real(x [][]float64) [][]complex128 {
	return IFFT2(dsputils.ToComplex2(x))
}