From 745e8742b7d21dc2ed31d17d067cf503ee630899 Mon Sep 17 00:00:00 2001 From: stormofice <58337328+stormofice@users.noreply.github.com> Date: Wed, 25 Aug 2021 17:52:22 +0200 Subject: [PATCH 01/18] Add C# implemenation for 1D Convolutions --- contents/convolutions/1d/1d.md | 14 +++ .../convolutions/code/csharp/1DConvolution.cs | 109 ++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100755 contents/convolutions/code/csharp/1DConvolution.cs diff --git a/contents/convolutions/1d/1d.md b/contents/convolutions/1d/1d.md index 3a3ca0cf6..10bb0b038 100644 --- a/contents/convolutions/1d/1d.md +++ b/contents/convolutions/1d/1d.md @@ -54,6 +54,8 @@ With this in mind, we can almost directly transcribe the discrete equation into {% method %} {% sample lang="jl" %} [import:29-48, lang:"julia"](../code/julia/1d_convolution.jl) +{% sample lang="cs" %} +[import:63-84, lang:"csharp"](../code/csharp/1DConvolution.cs) {% endmethod %} The easiest way to reason about this code is to read it as you might read a textbook. @@ -185,6 +187,8 @@ Here it is again for clarity: {% method %} {% sample lang="jl" %} [import:29-48, lang:"julia"](../code/julia/1d_convolution.jl) +{% sample lang="cs" %} +[import:63-84, lang:"csharp"](../code/csharp/1DConvolution.cs) {% endmethod %} Here, the main difference between the bounded and unbounded versions is that the output array size is smaller in the bounded case. @@ -193,6 +197,8 @@ For an unbounded convolution, the function would be called with a the output arr {% method %} {% sample lang="jl" %} [import:60-61, lang:"julia"](../code/julia/1d_convolution.jl) +{% sample lang="cs" %} +[import:96-97, lang:"csharp"](../code/csharp/1DConvolution.cs) {% endmethod %} On the other hand, the bounded call would set the output array size to simply be the length of the signal @@ -200,6 +206,8 @@ On the other hand, the bounded call would set the output array size to simply be {% method %} {% sample lang="jl" %} [import:63-64, lang:"julia"](../code/julia/1d_convolution.jl) +{% sample lang="cs" %} +[import:98-99, lang:"csharp"](../code/csharp/1DConvolution.cs) {% endmethod %} Finally, as we mentioned before, it is possible to center bounded convolutions by changing the location where we calculate the each point along the filter. @@ -208,6 +216,8 @@ This can be done by modifying the following line: {% method %} {% sample lang="jl" %} [import:37-37, lang:"julia"](../code/julia/1d_convolution.jl) +{% sample lang="cs" %} +[import:71-71, lang:"csharp"](../code/csharp/1DConvolution.cs) {% endmethod %} Here, `j` counts from `i-length(filter)` to `i`. @@ -240,6 +250,8 @@ In code, this typically amounts to using some form of modulus operation, as show {% method %} {% sample lang="jl" %} [import:4-27, lang:"julia"](../code/julia/1d_convolution.jl) +{% sample lang="cs" %} +[import:38-61, lang:"csharp"](../code/csharp/1DConvolution.cs) {% endmethod %} This is essentially the same as before, except for the modulus operations, which allow us to work on a periodic domain. @@ -255,6 +267,8 @@ For the code associated with this chapter, we have used the convolution to gener {% method %} {% sample lang="jl" %} [import, lang:"julia"](../code/julia/1d_convolution.jl) +{% sample lang="cs" %} +[import, lang:"csharp"](../code/csharp/1DConvolution.cs) {% endmethod %} At a test case, we have chosen to use two sawtooth functions, which should produce the following images: diff --git a/contents/convolutions/code/csharp/1DConvolution.cs b/contents/convolutions/code/csharp/1DConvolution.cs new file mode 100755 index 000000000..231a433a8 --- /dev/null +++ b/contents/convolutions/code/csharp/1DConvolution.cs @@ -0,0 +1,109 @@ +using System; +using System.IO; + +namespace Convolution1D +{ + public class Convolution1D + { + // Creates a sawtooth function with the given length + static double[] CreateSawtooth(int length) + { + var array = new double[length]; + for (var i = 0; i < length; i++) + array[i] = (i + 1) / 200f; + return array; + } + + // Normalizes the given array + static void Normalize(double[] array) + { + var norm = Norm(array); + for (var i = 0; i < array.Length; i++) + array[i] /= norm; + } + + // Calculates the norm of the array + static double Norm(double[] array) + { + var sum = 0.0; + for (var i = 0; i < array.Length; i++) + sum += Math.Pow(array[i], 2); + return Math.Sqrt(sum); + } + + // Julia like modulus function which handles negative values properly + // Assumes that y >= 0 + static int Mod(int x, int y) => ((x % y) + y) % y; + + static double[] ConvolveCyclic(double[] signal, double[] filter) + { + var outputSize = Math.Max(signal.Length, filter.Length); + + // Convolutional output + var output = new double[outputSize]; + var sum = 0.0; + + for (var i = 0; i < outputSize; i++) + { + for (var j = 0; j < outputSize; j++) + { + if (Mod(i - j, outputSize) < filter.Length) + { + sum += signal[Mod(j, outputSize)] * filter[Mod(i - j, outputSize)]; + } + } + + output[i] = sum; + sum = 0.0; + } + + return output; + } + + static double[] ConvolveLinear(double[] signal, double[] filter, int outputSize) + { + // Convolutional output + var output = new double[outputSize]; + var sum = 0.0; + + for (var i = 0; i < outputSize; i++) + { + for (var j = Math.Max(0, i - filter.Length); j <= i; j++) + { + if (j < signal.Length && (i - j + 1) < filter.Length) + { + sum += signal[j] * filter[i - j + 1]; + } + } + + output[i] = sum; + sum = 0.0; + } + + return output; + } + + static void Main() + { + // Create sawtooth functions for x and y + var x = CreateSawtooth(200); + var y = CreateSawtooth(200); + + // Normalization is not strictly necessary, but good practice + Normalize(x); + Normalize(y); + + // Full convolution, output will be the size of x + y + var fullLinearOutput = ConvolveLinear(x, y, x.Length + y.Length); + // Simple boundaries + var simpleLinearOutput = ConvolveLinear(x, y, x.Length); + // Cyclic convolution + var cyclicOutput = ConvolveCyclic(x, y); + + // Output convolutions to different files for plotting + File.WriteAllText("full_linear.dat", String.Join(Environment.NewLine, fullLinearOutput)); + File.WriteAllText("simple_linear.dat", String.Join(Environment.NewLine, simpleLinearOutput)); + File.WriteAllText("cyclic.dat", String.Join(Environment.NewLine, cyclicOutput)); + } + } +} \ No newline at end of file From 47f854174574cf603306ef23969a1dcc667af258 Mon Sep 17 00:00:00 2001 From: stormofice <58337328+stormofice@users.noreply.github.com> Date: Fri, 3 Sep 2021 20:19:36 +0200 Subject: [PATCH 02/18] Fix off by one error and julia line numbers --- contents/convolutions/1d/1d.md | 12 ++++++------ contents/convolutions/code/csharp/1DConvolution.cs | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/contents/convolutions/1d/1d.md b/contents/convolutions/1d/1d.md index 10bb0b038..b061941c1 100644 --- a/contents/convolutions/1d/1d.md +++ b/contents/convolutions/1d/1d.md @@ -53,7 +53,7 @@ With this in mind, we can almost directly transcribe the discrete equation into {% method %} {% sample lang="jl" %} -[import:29-48, lang:"julia"](../code/julia/1d_convolution.jl) +[import:27-46, lang:"julia"](../code/julia/1d_convolution.jl) {% sample lang="cs" %} [import:63-84, lang:"csharp"](../code/csharp/1DConvolution.cs) {% endmethod %} @@ -186,7 +186,7 @@ Here it is again for clarity: {% method %} {% sample lang="jl" %} -[import:29-48, lang:"julia"](../code/julia/1d_convolution.jl) +[import:27-46, lang:"julia"](../code/julia/1d_convolution.jl) {% sample lang="cs" %} [import:63-84, lang:"csharp"](../code/csharp/1DConvolution.cs) {% endmethod %} @@ -196,7 +196,7 @@ For an unbounded convolution, the function would be called with a the output arr {% method %} {% sample lang="jl" %} -[import:60-61, lang:"julia"](../code/julia/1d_convolution.jl) +[import:58-59, lang:"julia"](../code/julia/1d_convolution.jl) {% sample lang="cs" %} [import:96-97, lang:"csharp"](../code/csharp/1DConvolution.cs) {% endmethod %} @@ -205,7 +205,7 @@ On the other hand, the bounded call would set the output array size to simply be {% method %} {% sample lang="jl" %} -[import:63-64, lang:"julia"](../code/julia/1d_convolution.jl) +[import:61-62, lang:"julia"](../code/julia/1d_convolution.jl) {% sample lang="cs" %} [import:98-99, lang:"csharp"](../code/csharp/1DConvolution.cs) {% endmethod %} @@ -215,7 +215,7 @@ This can be done by modifying the following line: {% method %} {% sample lang="jl" %} -[import:37-37, lang:"julia"](../code/julia/1d_convolution.jl) +[import:35-35, lang:"julia"](../code/julia/1d_convolution.jl) {% sample lang="cs" %} [import:71-71, lang:"csharp"](../code/csharp/1DConvolution.cs) {% endmethod %} @@ -249,7 +249,7 @@ In code, this typically amounts to using some form of modulus operation, as show {% method %} {% sample lang="jl" %} -[import:4-27, lang:"julia"](../code/julia/1d_convolution.jl) +[import:4-25, lang:"julia"](../code/julia/1d_convolution.jl) {% sample lang="cs" %} [import:38-61, lang:"csharp"](../code/csharp/1DConvolution.cs) {% endmethod %} diff --git a/contents/convolutions/code/csharp/1DConvolution.cs b/contents/convolutions/code/csharp/1DConvolution.cs index 231a433a8..e067c83ab 100755 --- a/contents/convolutions/code/csharp/1DConvolution.cs +++ b/contents/convolutions/code/csharp/1DConvolution.cs @@ -49,7 +49,7 @@ static double[] ConvolveCyclic(double[] signal, double[] filter) { if (Mod(i - j, outputSize) < filter.Length) { - sum += signal[Mod(j, outputSize)] * filter[Mod(i - j, outputSize)]; + sum += signal[Mod(j - 1, outputSize)] * filter[Mod(i - j, outputSize)]; } } From a19b1a3aef2a7dbbcb93e16130baa6362301ca69 Mon Sep 17 00:00:00 2001 From: stormofice <58337328+stormofice@users.noreply.github.com> Date: Mon, 6 Sep 2021 01:49:39 +0200 Subject: [PATCH 03/18] Fix off by one error for linear convolutions --- contents/convolutions/code/csharp/1DConvolution.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contents/convolutions/code/csharp/1DConvolution.cs b/contents/convolutions/code/csharp/1DConvolution.cs index e067c83ab..1e916daf6 100755 --- a/contents/convolutions/code/csharp/1DConvolution.cs +++ b/contents/convolutions/code/csharp/1DConvolution.cs @@ -70,9 +70,9 @@ static double[] ConvolveLinear(double[] signal, double[] filter, int outputSize) { for (var j = Math.Max(0, i - filter.Length); j <= i; j++) { - if (j < signal.Length && (i - j + 1) < filter.Length) + if (j < signal.Length && (i - j) < filter.Length) { - sum += signal[j] * filter[i - j + 1]; + sum += signal[j] * filter[i - j]; } } From 5d15a92a46372d6023cb5d40b185dbd3ca1f10af Mon Sep 17 00:00:00 2001 From: stormofice <58337328+stormofice@users.noreply.github.com> Date: Mon, 6 Sep 2021 02:09:02 +0200 Subject: [PATCH 04/18] Fix trailing zero --- contents/convolutions/code/csharp/1DConvolution.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contents/convolutions/code/csharp/1DConvolution.cs b/contents/convolutions/code/csharp/1DConvolution.cs index 1e916daf6..37f8e53a6 100755 --- a/contents/convolutions/code/csharp/1DConvolution.cs +++ b/contents/convolutions/code/csharp/1DConvolution.cs @@ -93,8 +93,8 @@ static void Main() Normalize(x); Normalize(y); - // Full convolution, output will be the size of x + y - var fullLinearOutput = ConvolveLinear(x, y, x.Length + y.Length); + // Full convolution, output will be the size of x + y - 1 + var fullLinearOutput = ConvolveLinear(x, y, x.Length + y.Length - 1); // Simple boundaries var simpleLinearOutput = ConvolveLinear(x, y, x.Length); // Cyclic convolution From 7e14eb6258c4f703db959e3a52dbdc592dd79ad3 Mon Sep 17 00:00:00 2001 From: stormofice <58337328+stormofice@users.noreply.github.com> Date: Wed, 15 Sep 2021 00:30:43 +0200 Subject: [PATCH 05/18] Update contents/convolutions/code/csharp/1DConvolution.cs Co-authored-by: Trashtalk217 --- contents/convolutions/code/csharp/1DConvolution.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contents/convolutions/code/csharp/1DConvolution.cs b/contents/convolutions/code/csharp/1DConvolution.cs index 37f8e53a6..7cccbdb87 100755 --- a/contents/convolutions/code/csharp/1DConvolution.cs +++ b/contents/convolutions/code/csharp/1DConvolution.cs @@ -31,7 +31,7 @@ static double Norm(double[] array) return Math.Sqrt(sum); } - // Julia like modulus function which handles negative values properly + // Modulus function which handles negative values properly. // Assumes that y >= 0 static int Mod(int x, int y) => ((x % y) + y) % y; From 85b259bd527ede422367a1e1bbb96fddd2650c37 Mon Sep 17 00:00:00 2001 From: stormofice <58337328+stormofice@users.noreply.github.com> Date: Wed, 15 Sep 2021 00:30:48 +0200 Subject: [PATCH 06/18] Update contents/convolutions/code/csharp/1DConvolution.cs Co-authored-by: Trashtalk217 --- contents/convolutions/code/csharp/1DConvolution.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contents/convolutions/code/csharp/1DConvolution.cs b/contents/convolutions/code/csharp/1DConvolution.cs index 7cccbdb87..898b96a1d 100755 --- a/contents/convolutions/code/csharp/1DConvolution.cs +++ b/contents/convolutions/code/csharp/1DConvolution.cs @@ -32,7 +32,7 @@ static double Norm(double[] array) } // Modulus function which handles negative values properly. - // Assumes that y >= 0 + // Assumes that y >= 0. static int Mod(int x, int y) => ((x % y) + y) % y; static double[] ConvolveCyclic(double[] signal, double[] filter) From 78a179a9b48ba69d22bef7e65acde6c7d30f9dde Mon Sep 17 00:00:00 2001 From: stormofice <58337328+stormofice@users.noreply.github.com> Date: Wed, 15 Sep 2021 00:30:52 +0200 Subject: [PATCH 07/18] Update contents/convolutions/code/csharp/1DConvolution.cs Co-authored-by: Trashtalk217 --- contents/convolutions/code/csharp/1DConvolution.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contents/convolutions/code/csharp/1DConvolution.cs b/contents/convolutions/code/csharp/1DConvolution.cs index 898b96a1d..1d5a6f6e5 100755 --- a/contents/convolutions/code/csharp/1DConvolution.cs +++ b/contents/convolutions/code/csharp/1DConvolution.cs @@ -5,7 +5,7 @@ namespace Convolution1D { public class Convolution1D { - // Creates a sawtooth function with the given length + // Creates a sawtooth function with the given length. static double[] CreateSawtooth(int length) { var array = new double[length]; From 6dd35c7bfbc8a773e8a941f26789b9bced205198 Mon Sep 17 00:00:00 2001 From: stormofice <58337328+stormofice@users.noreply.github.com> Date: Wed, 15 Sep 2021 00:30:59 +0200 Subject: [PATCH 08/18] Update contents/convolutions/code/csharp/1DConvolution.cs Co-authored-by: Trashtalk217 --- contents/convolutions/code/csharp/1DConvolution.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contents/convolutions/code/csharp/1DConvolution.cs b/contents/convolutions/code/csharp/1DConvolution.cs index 1d5a6f6e5..1c4de5fb7 100755 --- a/contents/convolutions/code/csharp/1DConvolution.cs +++ b/contents/convolutions/code/csharp/1DConvolution.cs @@ -14,7 +14,7 @@ static double[] CreateSawtooth(int length) return array; } - // Normalizes the given array + // Normalizes the given array. static void Normalize(double[] array) { var norm = Norm(array); From d9a3ad5f66f70ce7b41aa02825558bb3cc89a73f Mon Sep 17 00:00:00 2001 From: stormofice <58337328+stormofice@users.noreply.github.com> Date: Wed, 15 Sep 2021 00:31:04 +0200 Subject: [PATCH 09/18] Update contents/convolutions/code/csharp/1DConvolution.cs Co-authored-by: Trashtalk217 --- contents/convolutions/code/csharp/1DConvolution.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contents/convolutions/code/csharp/1DConvolution.cs b/contents/convolutions/code/csharp/1DConvolution.cs index 1c4de5fb7..1218b0f99 100755 --- a/contents/convolutions/code/csharp/1DConvolution.cs +++ b/contents/convolutions/code/csharp/1DConvolution.cs @@ -22,7 +22,7 @@ static void Normalize(double[] array) array[i] /= norm; } - // Calculates the norm of the array + // Calculates the norm of the array. static double Norm(double[] array) { var sum = 0.0; From 3afd1b8e10735e769bbfbee48b06f5a6019395db Mon Sep 17 00:00:00 2001 From: stormofice <58337328+stormofice@users.noreply.github.com> Date: Wed, 15 Sep 2021 00:31:08 +0200 Subject: [PATCH 10/18] Update contents/convolutions/code/csharp/1DConvolution.cs Co-authored-by: Trashtalk217 --- contents/convolutions/code/csharp/1DConvolution.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contents/convolutions/code/csharp/1DConvolution.cs b/contents/convolutions/code/csharp/1DConvolution.cs index 1218b0f99..5001ef532 100755 --- a/contents/convolutions/code/csharp/1DConvolution.cs +++ b/contents/convolutions/code/csharp/1DConvolution.cs @@ -93,7 +93,7 @@ static void Main() Normalize(x); Normalize(y); - // Full convolution, output will be the size of x + y - 1 + // Full convolution, output will be the size of x + y - 1. var fullLinearOutput = ConvolveLinear(x, y, x.Length + y.Length - 1); // Simple boundaries var simpleLinearOutput = ConvolveLinear(x, y, x.Length); From 2b837d511d9991e3a939a50f1e1b265c841c5de6 Mon Sep 17 00:00:00 2001 From: stormofice <58337328+stormofice@users.noreply.github.com> Date: Wed, 15 Sep 2021 00:31:16 +0200 Subject: [PATCH 11/18] Update contents/convolutions/code/csharp/1DConvolution.cs Co-authored-by: Trashtalk217 --- contents/convolutions/code/csharp/1DConvolution.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contents/convolutions/code/csharp/1DConvolution.cs b/contents/convolutions/code/csharp/1DConvolution.cs index 5001ef532..fec5e86fb 100755 --- a/contents/convolutions/code/csharp/1DConvolution.cs +++ b/contents/convolutions/code/csharp/1DConvolution.cs @@ -39,7 +39,7 @@ static double[] ConvolveCyclic(double[] signal, double[] filter) { var outputSize = Math.Max(signal.Length, filter.Length); - // Convolutional output + // Convolutional output. var output = new double[outputSize]; var sum = 0.0; From 0ab262e679741214e2dbc226ea9fe171b2135236 Mon Sep 17 00:00:00 2001 From: stormofice <58337328+stormofice@users.noreply.github.com> Date: Wed, 15 Sep 2021 00:31:25 +0200 Subject: [PATCH 12/18] Update contents/convolutions/code/csharp/1DConvolution.cs Co-authored-by: Trashtalk217 --- contents/convolutions/code/csharp/1DConvolution.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contents/convolutions/code/csharp/1DConvolution.cs b/contents/convolutions/code/csharp/1DConvolution.cs index fec5e86fb..4ebfd1ea4 100755 --- a/contents/convolutions/code/csharp/1DConvolution.cs +++ b/contents/convolutions/code/csharp/1DConvolution.cs @@ -62,7 +62,7 @@ static double[] ConvolveCyclic(double[] signal, double[] filter) static double[] ConvolveLinear(double[] signal, double[] filter, int outputSize) { - // Convolutional output + // Convolutional output. var output = new double[outputSize]; var sum = 0.0; From 56f0ebe9a7131d64dbe4301860fc22bf57263526 Mon Sep 17 00:00:00 2001 From: stormofice <58337328+stormofice@users.noreply.github.com> Date: Wed, 15 Sep 2021 00:33:04 +0200 Subject: [PATCH 13/18] Update contents/convolutions/code/csharp/1DConvolution.cs Co-authored-by: Trashtalk217 --- contents/convolutions/code/csharp/1DConvolution.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contents/convolutions/code/csharp/1DConvolution.cs b/contents/convolutions/code/csharp/1DConvolution.cs index 4ebfd1ea4..fa166c0b7 100755 --- a/contents/convolutions/code/csharp/1DConvolution.cs +++ b/contents/convolutions/code/csharp/1DConvolution.cs @@ -85,7 +85,7 @@ static double[] ConvolveLinear(double[] signal, double[] filter, int outputSize) static void Main() { - // Create sawtooth functions for x and y + // Create sawtooth functions for x and y. var x = CreateSawtooth(200); var y = CreateSawtooth(200); From 306c81edd7d042f2f3ac336595aff76197b5cae5 Mon Sep 17 00:00:00 2001 From: stormofice <58337328+stormofice@users.noreply.github.com> Date: Wed, 15 Sep 2021 00:33:09 +0200 Subject: [PATCH 14/18] Update contents/convolutions/code/csharp/1DConvolution.cs Co-authored-by: Trashtalk217 --- contents/convolutions/code/csharp/1DConvolution.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contents/convolutions/code/csharp/1DConvolution.cs b/contents/convolutions/code/csharp/1DConvolution.cs index fa166c0b7..cb84dbb37 100755 --- a/contents/convolutions/code/csharp/1DConvolution.cs +++ b/contents/convolutions/code/csharp/1DConvolution.cs @@ -95,7 +95,7 @@ static void Main() // Full convolution, output will be the size of x + y - 1. var fullLinearOutput = ConvolveLinear(x, y, x.Length + y.Length - 1); - // Simple boundaries + // Simple boundaries. var simpleLinearOutput = ConvolveLinear(x, y, x.Length); // Cyclic convolution var cyclicOutput = ConvolveCyclic(x, y); From 35f4c11740d470e7080015d047a2677440de3440 Mon Sep 17 00:00:00 2001 From: stormofice <58337328+stormofice@users.noreply.github.com> Date: Wed, 15 Sep 2021 00:33:13 +0200 Subject: [PATCH 15/18] Update contents/convolutions/code/csharp/1DConvolution.cs Co-authored-by: Trashtalk217 --- contents/convolutions/code/csharp/1DConvolution.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contents/convolutions/code/csharp/1DConvolution.cs b/contents/convolutions/code/csharp/1DConvolution.cs index cb84dbb37..20f187bec 100755 --- a/contents/convolutions/code/csharp/1DConvolution.cs +++ b/contents/convolutions/code/csharp/1DConvolution.cs @@ -97,7 +97,7 @@ static void Main() var fullLinearOutput = ConvolveLinear(x, y, x.Length + y.Length - 1); // Simple boundaries. var simpleLinearOutput = ConvolveLinear(x, y, x.Length); - // Cyclic convolution + // Cyclic convolution. var cyclicOutput = ConvolveCyclic(x, y); // Output convolutions to different files for plotting From 99d1bdb408a970ca426e125bb3a36c41e4e659cc Mon Sep 17 00:00:00 2001 From: stormofice <58337328+stormofice@users.noreply.github.com> Date: Wed, 15 Sep 2021 00:33:18 +0200 Subject: [PATCH 16/18] Update contents/convolutions/code/csharp/1DConvolution.cs Co-authored-by: Trashtalk217 --- contents/convolutions/code/csharp/1DConvolution.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contents/convolutions/code/csharp/1DConvolution.cs b/contents/convolutions/code/csharp/1DConvolution.cs index 20f187bec..8113593b5 100755 --- a/contents/convolutions/code/csharp/1DConvolution.cs +++ b/contents/convolutions/code/csharp/1DConvolution.cs @@ -100,7 +100,7 @@ static void Main() // Cyclic convolution. var cyclicOutput = ConvolveCyclic(x, y); - // Output convolutions to different files for plotting + // Output convolutions to different files for plotting. File.WriteAllText("full_linear.dat", String.Join(Environment.NewLine, fullLinearOutput)); File.WriteAllText("simple_linear.dat", String.Join(Environment.NewLine, simpleLinearOutput)); File.WriteAllText("cyclic.dat", String.Join(Environment.NewLine, cyclicOutput)); From 52b16ca36d86634c1db38b075b34b777475d92c9 Mon Sep 17 00:00:00 2001 From: stormofice <58337328+stormofice@users.noreply.github.com> Date: Wed, 15 Sep 2021 00:33:28 +0200 Subject: [PATCH 17/18] Update contents/convolutions/code/csharp/1DConvolution.cs Co-authored-by: Trashtalk217 --- contents/convolutions/code/csharp/1DConvolution.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contents/convolutions/code/csharp/1DConvolution.cs b/contents/convolutions/code/csharp/1DConvolution.cs index 8113593b5..b06f9a3af 100755 --- a/contents/convolutions/code/csharp/1DConvolution.cs +++ b/contents/convolutions/code/csharp/1DConvolution.cs @@ -89,7 +89,7 @@ static void Main() var x = CreateSawtooth(200); var y = CreateSawtooth(200); - // Normalization is not strictly necessary, but good practice + // Normalization is not strictly necessary, but good practice. Normalize(x); Normalize(y); From 16e75cf166a3ab19df5c1b218e2e94872a2f549e Mon Sep 17 00:00:00 2001 From: stormofice <58337328+stormofice@users.noreply.github.com> Date: Wed, 15 Sep 2021 00:37:43 +0200 Subject: [PATCH 18/18] Add trailing new line --- contents/convolutions/code/csharp/1DConvolution.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contents/convolutions/code/csharp/1DConvolution.cs b/contents/convolutions/code/csharp/1DConvolution.cs index b06f9a3af..c4c1016c6 100755 --- a/contents/convolutions/code/csharp/1DConvolution.cs +++ b/contents/convolutions/code/csharp/1DConvolution.cs @@ -106,4 +106,5 @@ static void Main() File.WriteAllText("cyclic.dat", String.Join(Environment.NewLine, cyclicOutput)); } } -} \ No newline at end of file +} +