From b79b26d1a38dab4ccb6beffa4e497f6bcd439834 Mon Sep 17 00:00:00 2001 From: kbecke23 Date: Tue, 12 Jun 2018 09:55:19 +0200 Subject: [PATCH] updated with standard NLMS --- bin/CS_NLMS_with_UI.exe | Bin 21504 -> 23040 bytes src/c_sharp_implementation/NLMSvariants.cs | 130 ++++++++++++++++++++- 2 files changed, 128 insertions(+), 2 deletions(-) diff --git a/bin/CS_NLMS_with_UI.exe b/bin/CS_NLMS_with_UI.exe index 5f1d56b2617e95f138ffc8e93f8ee1b642f6b272..cbfe658ca1c1c022d8a3152d11e1c371b2b59589 100644 GIT binary patch delta 8960 zcmb_i3wTsjlCE=Z_wDCRa=S@7AtBufBxy)^1eDm9MAt=a*DT0WpPW1pu!D-kaF@+*G0M{Ag@m zLxSjXMhEcKcUFXh-zN%!cXbh!*(WclvztYY{{gm%;k&}VQ`Cx8_5o2N*4igTW%X8g z;Lj3#CAq140W8N83CIQT`9LSpRsl~F>=iN;$OA+ZN~d^es=Y-X7M=EVZH}0Y6Kfzf4NH}fdWWSkwc})5gD-z=OvYV`iO9HHF?lks+mqdIi@o-j z?uYFA^g?m1{ghrAe;@6W7s7YY`Z~iJ-qDHafXJ7A&iJ*kf1}r@#&WOt6ZZ9cP>`@+ zJ@j4SKqPF`R+8!K*MXac9-jaQre8OW=3VR7hJ9ojk+osNG)(UqS2)kin|Mt2p%|`2 z9ERb1Grw*HS@n{(T1_DO-IGu+(|3109`SF%BtD5!pp!W-$F66@E|6oFF(Z#|225Y` zo{_wR*+C1;g1QN5XO9j$^XR+I?JbfDo7~4Bcgt+vmGL@1J_AXu4F}0I(MJ;>?qkRd zO+01>Ggfp)gu`aIE|3O3n->m7!lPeQ^o7Y)N~=4bsTO~^DZ;EX8pRg z@zGoWa})xNGDoREg=XQzAA1usq0l?gATbMEwJ!~rK1YUoKk5CLgRV$3(kn8HX3?3i zzxMP;?UTW9>1;Hr8i+z2hfQri=8Y>Z!Nup=8-10R&4WH1shws<67!iYCbKx+2(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pl$Xz)kRGyHdc?{joal*)fZQ0@ft|3t^d*YqZx5Es4gAm$tH59qWwC>PU6 z8q_|bDmo;-1pdJz=(HN@X*wpyq{Mk~o3B9#d8cEV;6U@lG2!(s5vOUNXNB;~CUK1z ziw5oR`JLPftZ>~WCeTUOV`3`Z;XNvLiBj>Lh{*T6Kcfmc)uz)JS?v?lD7jU)_&d)h zqKYm<<@)JU=NICq*BovRnC_rujHZPm>G&-O74^I&jYvnUX?AV)30QQ zs@D7RYw>|}k~2lZHijOeN!mE<^1Zfkcum<4ETdllE9sZOdipouc!gKcX~?q`zmPtI zyj<~X6mB5DeH`6DR{)bV-`=7k@1WiEkbMW4v=`U|{M$6{rqsXNUs1{_u>*!$x=1gH zGvaGulb6bgafs$^eog#&=@|rq* z^4hhHjcXfd>XyWYwk?Y{wQZfgK0_(vW#;LI5$3-(_=`7hUTSRGxM{7rV`>mW$@Q3+fy7m=ONH^IlxhfxZh){yJSG ze8E7!Ch#XzTS39dk(eT%&!@#G(C;!gFPLi{T@W*U3pbkE7uGIoRQyC|FwpltV(d{7 z`zKqEY05ZPLzYn^wU`uMuVrYl9<9p0l9fQ;ix#)q{A^)WO`E@elQMQV(5xWP-=R6+ z^SB*Y;v^C1zY+fir!0EYHa7Dgu{k4$M?1{TtzCl!%f8a&tCI))SAQx78XW%(OFAR~ diff --git a/src/c_sharp_implementation/NLMSvariants.cs b/src/c_sharp_implementation/NLMSvariants.cs index b6727f1..b8343c1 100644 --- a/src/c_sharp_implementation/NLMSvariants.cs +++ b/src/c_sharp_implementation/NLMSvariants.cs @@ -114,6 +114,10 @@ namespace NMLS_Graphisch switch (comboBox_algorithem.SelectedItem.ToString()) { + case "standard NLMS": + series = standardNLMS(); + break; + case "local mean": series = localMean(); break; @@ -163,6 +167,125 @@ namespace NMLS_Graphisch } + /*--------------------------------------------------- + * standardNLMS() + * + * the algorithem for the standard NLMS + * + * returns a array of Series with the error and prediction for + * displaying in a chart + * + *---------------------------------------------------*/ + + Series[] standardNLMS() + { + + int x_count = 0; + double[] x_error = new double[NumberOfSamples]; + x_error[0] = 0; + + /* Inizilazing series for the main chart */ + Series standardNLMSError = new Series("Standard NLMS Error"); + Series standardNLMSPredict = new Series("Standard NLMS Prediction"); + standardNLMSError.ChartType = SeriesChartType.Spline; + standardNLMSPredict.ChartType = SeriesChartType.Spline; + + /* Main while loop for the prediction and learing */ + + while (x_count < NumberOfSamples - 1) + { + + int _sourceIndex = (x_count > windowSize) ? x_count - windowSize : 0; + int _arrayLength = (x_count > windowSize) ? windowSize : x_count; + + double x_pred = 0.0; + + double[] x_array = _x; + double x_actual = _x[x_count]; + + /* Prediction algorithem */ + + for (int i = 1; i < _arrayLength; i++) + { + x_pred += (w[i, x_count] * (x_array[x_count - i])); + } + + /* If output is checked a file is produced with prediction, actual and the error */ + if (checkBox_output.Checked) + { + File.AppendAllText("standardNLMS.txt", + String.Format("{0}. X_pred {1}\n", x_count, x_pred), + Encoding.UTF8); + + File.AppendAllText("standardNLMS.txt", + String.Format("{0}. X_actual {1}\n", x_count, x_actual), + Encoding.UTF8); + } + + /* Calculating the error */ + x_error[x_count] = x_actual - x_pred; + + + double x_square = 0; + + /* Output */ + if (checkBox_output.Checked) + { + File.AppendAllText("standardNLMS.txt", + String.Format("{0}. X_error {1}\n\n", x_count, x_error[x_count]), + Encoding.UTF8); + } + + /* Calulating the LMS value */ + for (int i = 1; i < _arrayLength; i++) + { + x_square += Math.Pow(x_array[x_count - i], 2); + } + + /* x_square == 0.0, drives to undefined weights therefor we set it to 1 */ + + if (x_square == 0.0) + x_square = 1.0; + + /* Learning algorithem */ + for (int i = 1; i < _arrayLength; i++) + { + w[i, x_count + 1] = w[i, x_count] + learnrate * x_error[x_count] * (x_array[x_count - i] / x_square); + } + + /* Printing error and prediction on the series */ + + standardNLMSError.Points.AddXY(x_count, x_error[x_count]); + standardNLMSPredict.Points.AddXY(x_count, x_pred); + + x_count += 1; + } + + /* Calculating the avearage of the error and the variance of the error */ + double mittel = x_error.Where(d => !double.IsNaN(d)).Skip(windowSize).Sum() / x_error.Length; + double varianz = 0.0; + foreach (double x_e in x_error.Skip(windowSize)) + { + if (!double.IsNaN(x_e)) + varianz += Math.Pow(x_e - mittel, 2); + } + varianz /= x_error.Length; + + /* Displayes both on labels */ + label3.Text = mittel.ToString(); + label5.Text = varianz.ToString(); + + /* Output the result */ + if (checkBox_output.Checked) + { + File.AppendAllText("results_standardNLMS.txt", + String.Format("Squared variance(x_error): {0}\n Average(x_error): {1}\n\n", varianz, mittel), + Encoding.UTF8); + } + + return new Series[] { standardNLMSPredict, standardNLMSError }; + } + /*--------------------------------------------------- * localMean() * @@ -253,7 +376,7 @@ namespace NMLS_Graphisch /* Learning algorithem */ for (int i = 1; i < _arrayLength; i++) { - w[i, x_count + 1] = w[i, x_count] + learnrate * x_error[x_count] * ((x_array[x_count - i] - x_middle) / x_square); + w[i, x_count+1] = w[i, x_count] + learnrate * x_error[x_count] * ((x_array[x_count - i] - x_middle) / x_square); } /* Printing error and prediction on the series */ @@ -626,6 +749,9 @@ namespace NMLS_Graphisch Bitmap img = new Bitmap(openFileDialog.FileName); pixel_array = new double[img.Width * img.Height]; + Console.WriteLine("imgWidth: {0}", img.Width); + Console.WriteLine("imgHeight: {0}", img.Height); + for (int i = 1; i < img.Width; i++) { for (int j = 1; j < img.Height; j++) @@ -636,7 +762,7 @@ namespace NMLS_Graphisch } } - + Console.WriteLine("pixle_array length: {0}", pixel_array.Length); _x = pixel_array; /* Recreating the weights with the new size of NumberOfSamples */