diff --git a/EcomAnalysis/Form1.Designer.cs b/EcomAnalysis/Form1.Designer.cs index acf0724..2d93eed 100644 --- a/EcomAnalysis/Form1.Designer.cs +++ b/EcomAnalysis/Form1.Designer.cs @@ -274,9 +274,9 @@ this.listView2.Font = new System.Drawing.Font("MS UI Gothic", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(128))); this.listView2.GridLines = true; this.listView2.HideSelection = false; - this.listView2.Location = new System.Drawing.Point(414, 243); + this.listView2.Location = new System.Drawing.Point(414, 222); this.listView2.Name = "listView2"; - this.listView2.Size = new System.Drawing.Size(297, 125); + this.listView2.Size = new System.Drawing.Size(297, 146); this.listView2.TabIndex = 24; this.listView2.UseCompatibleStateImageBehavior = false; this.listView2.View = System.Windows.Forms.View.Details; @@ -308,7 +308,7 @@ // this.label13.AutoSize = true; this.label13.Font = new System.Drawing.Font("MS UI Gothic", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(128))); - this.label13.Location = new System.Drawing.Point(410, 219); + this.label13.Location = new System.Drawing.Point(410, 198); this.label13.Name = "label13"; this.label13.Size = new System.Drawing.Size(91, 21); this.label13.TabIndex = 25; diff --git a/EcomAnalysis/Form1.cs b/EcomAnalysis/Form1.cs index c2a8088..8c4f217 100644 --- a/EcomAnalysis/Form1.cs +++ b/EcomAnalysis/Form1.cs @@ -25,8 +25,8 @@ private List _Data = new List(); private List _SceneTable = new List(); private SceneMean _ScMean = new SceneMean(); - private double[] LF = new double[BLOCKS]; - private double[] HF = new double[BLOCKS]; + private double[] LF = new double[BLOCKS + 1]; + private double[] HF = new double[BLOCKS + 1]; private LogFileInfo _LogFileInfo = new LogFileInfo(); private FormCompareLogs _FormCompareLogs = new FormCompareLogs(); private bool _NewLog = true; @@ -59,6 +59,11 @@ private void Form1_Load(object sender, EventArgs e) { var args = Environment.GetCommandLineArgs(); if (args.Length > 1) OpenLog(args[1]); + var asm = System.Reflection.Assembly.GetExecutingAssembly(); + this.Text += $" ver {asm.GetName().Version.Major}.{asm.GetName().Version.Minor}"; +#if DEBUG + this.Text += " [DEBUG]"; +#endif } /// @@ -184,8 +189,25 @@ $"{_ScMean.Pupil.L:0.00} ms"})); } - // HRV算出(1/4ブロック単位) + // HRV算出 listView2.Items.Clear(); + const int WINDOW_LEN = 512; // ウインドウサイズ + const int WINDOW_NUM = 4; // ウインドウ分割数 + const double LFmin = 0.04; + const double LFmax = 0.15; + const double HFmax = 0.4; + LF[BLOCKS] = 0D; + HF[BLOCKS] = 0D; + + // テーパーウインドウ重み生成 + var taperWeight = new double[WINDOW_LEN]; + var taperSize = WINDOW_LEN / 10; + for (var i = 0; i < WINDOW_LEN; i++) { + taperWeight[i] = i < taperSize ? 0.5 * (1.0 - Math.Cos(Math.PI * (double)i / taperSize)) : + i > WINDOW_LEN - taperSize ? 0.5 * (1.0 + Math.Cos(Math.PI * (double)(i - WINDOW_LEN + taperSize) / taperSize)) : 1.0; + } + + // 1/4ブロック単位の処理 for (var block = 0; block < BLOCKS; block++) { LF[block] = 0D; HF[block] = 0D; @@ -233,15 +255,13 @@ var linear = LinearSpline.Interpolate(rrcTime, rrcVal); // 線形補間 //var cspline = CubicSpline.InterpolateNatural(rrcTime, rrcVal); // 3次スプライン補間 var rriVal = new List(); - const int WINDOW_LEN = 512; // ウインドウサイズ - const int WINDOW_NUM = 4; // ウインドウ分割数 int SAMPLES = (WINDOW_LEN / 2) * (WINDOW_NUM + 1); const double fc = 0.04; // 低域遮断周波数 double T = rrcTime.Max() - rrcTime[0]; double F = 0.443 / fc; int n = (int)Math.Floor(F * SAMPLES / (T * (1 - F / T))) + 1; // 移動平均サイズ var interval = T / (SAMPLES + n); - // Debug.WriteLine($"dt={interval}, n={n}, fc={0.443 / (n * interval)}"); + //Debug.WriteLine($"dt={interval}, n={n}, fc={0.443 / (n * interval)}"); for (var t = rrcTime[0]; t < rrcTime.Max(); t += interval) { rriVal.Add(linear.Interpolate(t)); } @@ -261,13 +281,7 @@ //Debug.WriteLine($"{i * interval}\t{rrtr[i]}"); } // ウインドウ処理 - var taperWeight = new double[WINDOW_LEN]; - var taperSize = WINDOW_LEN / 10; - for (var i = 0; i < WINDOW_LEN; i++) { - taperWeight[i] = i < taperSize ? 0.5 * (1.0 - Math.Cos(Math.PI * (double)i / taperSize)) : - i > WINDOW_LEN- taperSize ? 0.5 * (1.0 + Math.Cos(Math.PI * (double)(i- WINDOW_LEN + taperSize) / taperSize)) : 1.0; - } - var fft = new Complex[WINDOW_NUM][]; + var fft = new Complex[WINDOW_NUM][]; // フーリエ変換出力 for (var w = 0; w < WINDOW_NUM; w++) { var rrw = rrtr.GetRange(w * WINDOW_LEN / 2, WINDOW_LEN); fft[w] = new Complex[WINDOW_LEN]; @@ -277,9 +291,6 @@ Fourier.Forward(fft[w], FourierOptions.Default); } var df = 1.0 / (WINDOW_LEN * interval); // フーリエ解析の周波数分解能 - const double LFmin = 0.04; - const double LFmax = 0.15; - const double HFmax = 0.4; for (var i = 0; i < WINDOW_LEN / 2; i++) { var fftm = 0D; for (var w = 0; w < WINDOW_NUM; w++) { @@ -293,7 +304,14 @@ } listView2.Items.Add(new ListViewItem(new string[] { $"{block*10+1}-{block*10+10}", $"{LF[block]:0.0}", $"{HF[block]:0.0}", $"{LF[block]/HF[block]:0.00}" })); + LF[BLOCKS] += LF[block]; + HF[BLOCKS] += HF[block]; } + // 全体のHRV算出 + LF[BLOCKS] /= BLOCKS; + HF[BLOCKS] /= BLOCKS; + listView2.Items.Add(new ListViewItem(new string[] { + "全体", $"{LF[BLOCKS]:0.0}", $"{HF[BLOCKS]:0.0}", $"{LF[BLOCKS]/HF[BLOCKS]:0.00}" })); } /// @@ -405,6 +423,7 @@ for (var b =0; b