虽然“卷积是频域中的乘法”,但从字面上看,它们似乎也是乘法。例如,如果我将内存中相邻的数字连接到一个列表中:
5: (byte) 00000101
22: (byte) 00010110
7: (byte) 00000111
8: (byte) 00001000
Becomes:
(Int32) 00000101000101100000011100001000
然后将此结果列表/数字乘以另一个这样的列表,结果是一个列表与另一个列表的卷积。以下 C# 程序演示了这一点:
using System;
public class Program
{
public static void Main(string[] args)
{
var A = new byte[]{1, 2, 3, 4, 5, 6, 7, 8};
var a = combine_to_Int64(A);
var B = new byte[]{1, 2, 3, 4, 5, 6, 7, 8};
var b = combine_to_Int64(B);
var c = a * b;
var C = separate_to_8_byte(c);
var d = deconvolution(c, b); // not correct
var D = separate_to_8_byte(d);
Console.WriteLine(
"The convolution of (" + to_string(A) + ") with ("
+ to_string(B) + ") is: (" + to_string(C) + ")");
Console.WriteLine(
"The deconvolution of (" + to_string(C) + ") with ("
+ to_string(B) + ") is: (" + to_string(D) + ")");
}
public static Int64 convolution(Int64 a, Int64 b)
{
return a * b;
}
private static Int64 combine_to_Int64(byte[] n)
{
if (n.Length == 4)
return n[0] + 65536 * n[1] + 4294967296 * n[2] +
281474976710656 * n[3];
else if (n.Length == 8)
return n[0] + 256 * n[1] + 65536 * n[2] + 16777216 * n[3] +
4294967296 * n[4] + 1099511627776 * n[5] +
281474976710656 * n[6] + 72057594037927936 * n[7];
else
throw new ArgumentException();
}
private static Int16[] separate_to_4_Int16(Int64 a)
{
return new []{(Int16) a, (Int16) (a >> 0x10),
(Int16) (a >> 0x20), (Int16) (a >> 0x30)};
}
private static byte[] separate_to_8_byte(Int64 a)
{
return new []{(byte) a, (byte) (a >> 8), (byte) (a >> 0x10),
(byte) (a >> 0x18), (byte) (a >> 0x20), (byte) (a >> 0x28),
(byte) (a >> 0x30), (byte) (a >> 0x38)};
}
public static string to_string(byte[] values)
{
string s = "";
foreach (var val in values)
s += (s == "" ? "" : " ") + val;
return s;
}
public static string to_string(Int16[] values)
{
string s = "";
foreach (var val in values)
s += (s == "" ? "" : " ") + val;
return s;
}
// ---
public static Int64 deconvolution(Int64 a, Int64 b)
{
var large = System.Numerics.BigInteger.Parse(
"1000000000000000000000000000000");
return (Int64)(((
(new System.Numerics.BigInteger(a) * large)
/ new System.Numerics.BigInteger(b))
* 72057594037927936) / large);
}
}
试试这个代码:rextester.com/YPKFA14408
输出是:
The convolution of (1 2 3 4 5 6 7 8) with (1 2 3 4 5 6 7 8) is: (1 4 10 20 35 56 84 120)
The deconvolution of (1 4 10 20 35 56 84 120) with (1 2 3 4 5 6 7 8) is: (219 251 194 172 10 94 253 14)
可以在此处找到输出第一行正确的演示:https ://oeis.org/A000292
“整数序列在线百科全书”……“四面体(或三角锥)数”……“自然数与其自身的卷积。——费利克斯·戈德堡”
问:提供的代码中的反卷积函数有什么问题,或者我对结果应该是什么的理解?