Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
30
Task/Deconvolution-1D/Go/deconvolution-1d-1.go
Normal file
30
Task/Deconvolution-1D/Go/deconvolution-1d-1.go
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
h := []float64{-8, -9, -3, -1, -6, 7}
|
||||
f := []float64{-3, -6, -1, 8, -6, 3, -1, -9, -9, 3, -2, 5, 2, -2, -7, -1}
|
||||
g := []float64{24, 75, 71, -34, 3, 22, -45, 23, 245, 25, 52, 25, -67, -96,
|
||||
96, 31, 55, 36, 29, -43, -7}
|
||||
fmt.Println(h)
|
||||
fmt.Println(deconv(g, f))
|
||||
fmt.Println(f)
|
||||
fmt.Println(deconv(g, h))
|
||||
}
|
||||
|
||||
func deconv(g, f []float64) []float64 {
|
||||
h := make([]float64, len(g)-len(f)+1)
|
||||
for n := range h {
|
||||
h[n] = g[n]
|
||||
var lower int
|
||||
if n >= len(f) {
|
||||
lower = n - len(f) + 1
|
||||
}
|
||||
for i := lower; i < n; i++ {
|
||||
h[n] -= h[i] * f[n-i]
|
||||
}
|
||||
h[n] /= f[0]
|
||||
}
|
||||
return h
|
||||
}
|
||||
65
Task/Deconvolution-1D/Go/deconvolution-1d-2.go
Normal file
65
Task/Deconvolution-1D/Go/deconvolution-1d-2.go
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"math/cmplx"
|
||||
)
|
||||
|
||||
func main() {
|
||||
h := []float64{-8, -9, -3, -1, -6, 7}
|
||||
f := []float64{-3, -6, -1, 8, -6, 3, -1, -9, -9, 3, -2, 5, 2, -2, -7, -1}
|
||||
g := []float64{24, 75, 71, -34, 3, 22, -45, 23, 245, 25, 52, 25, -67, -96,
|
||||
96, 31, 55, 36, 29, -43, -7}
|
||||
fmt.Printf("%.1f\n", h)
|
||||
fmt.Printf("%.1f\n", deconv(g, f))
|
||||
fmt.Printf("%.1f\n", f)
|
||||
fmt.Printf("%.1f\n", deconv(g, h))
|
||||
}
|
||||
|
||||
func deconv(g, f []float64) []float64 {
|
||||
n := 1
|
||||
for n < len(g) {
|
||||
n *= 2
|
||||
}
|
||||
g2 := make([]complex128, n)
|
||||
for i, x := range g {
|
||||
g2[i] = complex(x, 0)
|
||||
}
|
||||
f2 := make([]complex128, n)
|
||||
for i, x := range f {
|
||||
f2[i] = complex(x, 0)
|
||||
}
|
||||
gt := fft(g2)
|
||||
ft := fft(f2)
|
||||
for i := range gt {
|
||||
gt[i] /= ft[i]
|
||||
}
|
||||
ht := fft(gt)
|
||||
it := 1 / float64(n)
|
||||
out := make([]float64, len(g)-len(f)+1)
|
||||
out[0] = real(ht[0]) * it
|
||||
for i := 1; i < len(out); i++ {
|
||||
out[i] = real(ht[n-i]) * it
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func fft(in []complex128) []complex128 {
|
||||
out := make([]complex128, len(in))
|
||||
ditfft2(in, out, len(in), 1)
|
||||
return out
|
||||
}
|
||||
|
||||
func ditfft2(x, y []complex128, n, s int) {
|
||||
if n == 1 {
|
||||
y[0] = x[0]
|
||||
return
|
||||
}
|
||||
ditfft2(x, y, n/2, 2*s)
|
||||
ditfft2(x[s:], y[n/2:], n/2, 2*s)
|
||||
for k := 0; k < n/2; k++ {
|
||||
tf := cmplx.Rect(1, -2*math.Pi*float64(k)/float64(n)) * y[k+n/2]
|
||||
y[k], y[k+n/2] = y[k]+tf, y[k]-tf
|
||||
}
|
||||
}
|
||||
36
Task/Deconvolution-1D/Go/deconvolution-1d-3.go
Normal file
36
Task/Deconvolution-1D/Go/deconvolution-1d-3.go
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"gonum.org/v1/gonum/mat"
|
||||
)
|
||||
|
||||
var (
|
||||
h = []float64{-8, -9, -3, -1, -6, 7}
|
||||
f = []float64{-3, -6, -1, 8, -6, 3, -1, -9, -9, 3, -2, 5, 2, -2, -7, -1}
|
||||
g = []float64{24, 75, 71, -34, 3, 22, -45, 23, 245, 25, 52, 25, -67, -96,
|
||||
96, 31, 55, 36, 29, -43, -7}
|
||||
)
|
||||
|
||||
func band(g, f []float64) *mat.Dense {
|
||||
nh := len(g) - len(f) + 1
|
||||
b := mat.NewDense(len(g), nh, nil)
|
||||
for j := 0; j < nh; j++ {
|
||||
for i, fi := range f {
|
||||
b.Set(i+j, j, fi)
|
||||
}
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func deconv(g, f []float64) mat.Matrix {
|
||||
z := mat.NewDense(len(g)-len(f)+1, 1, nil)
|
||||
z.Solve(band(g, f), mat.NewVecDense(len(g), g))
|
||||
return z
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Printf("deconv(g, f) =\n%.1f\n\n", mat.Formatted(deconv(g, f)))
|
||||
fmt.Printf("deconv(g, h) =\n%.1f\n", mat.Formatted(deconv(g, h)))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue