private void Filter_Click(object sender, EventArgs e) { foreach (var series in chart1.Series) { series.Points.Clear(); } chart1.Visible = true; int chanCount = comboBox_chanCount.SelectedIndex + 1; for (int i = 0; i < chanCount; i++) { for (int j = 0; j < Convert.ToInt32(LowFrequency.Text) * time / 1000; j++) { value[i][j] = 0.0; ivalue[i][j] = 0.0; } for (int j = Convert.ToInt32(HighFrequency.Text) * time / 1000; j < num; j++) { value[i][j] = 0.0; ivalue[i][j] = 0.0; } } for (int i = 0; i < chanCount; i++) { double[] values = (double[])value[i].ToArray(typeof(double)); double[] ivalues = (double[])ivalue[i].ToArray(typeof(double)); TWFFT.IFFT(values, ivalues); for (int j = 0; j < num; j++) { chart1.Series[i].Enabled = true; if (values[j] != 0) { chart1.Series[i].Points.AddY(values[j]); } } } }
private void FFT_Click(object sender, EventArgs e) { int chanCount = comboBox_chanCount.SelectedIndex + 1; for (int i = 0; i < chanCount; ++i) { double[] values = (double[])xreal[i].ToArray(typeof(double)); double[] ivalues = new double[values.Length]; num = values.Length; for (int j = 0; j < values.Length; j++) { ivalues[j] = 0; } TWFFT.FFT(values, ivalues); //TWFFT.IFFT(values, ivalues); for (int j = 0; j < values.Length; j++) { value[i].Add(values[j]); ivalue[i].Add(ivalues[j]); } } string result = fname.Insert(fname.LastIndexOf('.'), " FFT"); using (FileStream fs = File.Open(result, FileMode.OpenOrCreate)) { StreamWriter w = new StreamWriter(fs); w.BaseStream.Seek(0, SeekOrigin.End); w.Write("\r\nFFT:\r\n"); for (int i = 0; i < chanCount; i++) { w.BaseStream.Seek(0, SeekOrigin.End); w.Write("channel " + i.ToString() + "\r\n"); for (int j = 0; j < num; j++) { //写文件 w.Write(value[i][j].ToString() + " "); w.Write(ivalue[i][j].ToString() + " "); w.Write("\r\n"); } } w.Flush(); w.Close(); } chart1.ChartAreas[0].AxisY.Maximum = trackBar2.Value; // chart1.ChartAreas[0].AxisX.Maximum = trackBar1.Value; double[] Power = { 0, 0, 0, 0, 0, 0, 0, 0 }; double[] Freq = { 0, 0, 0, 0, 0, 0, 0, 0 }; for (int i = 0; i < chanCount; i++) { double power = 0; int frequency = 0; double[] values = (double[])value[i].ToArray(typeof(double)); double[] ivalues = (double[])ivalue[i].ToArray(typeof(double)); for (int j = 0; j < num; j++) { if (power < values[j] * values[j] + ivalues[j] * ivalues[j]) { power = (values[j] * values[j] + ivalues[j] * ivalues[j]); frequency = j; } } Power[i] = power; Freq[i] = frequency * 1000 / time; } ; //control list view ,one grid indicates a channel which specials with color and value. ListView2.Clear(); ListView2.FullRowSelect = false; ListView2.Width = 480; ListView2.Height = 21; ListView2.View = View.Details;// Set the view to show details. ListView2.HeaderStyle = ColumnHeaderStyle.None; ListView2.GridLines = true; // there are 8 columns for every item. for (int k = 0; k < 8; k++) { ListView2.Columns.Add("", 60); } // modify the grid's height with image Indirectly. ImageList imgList2 = new ImageList(); imgList2.ImageSize = new Size(1, 21); //width and height. ListView2.SmallImageList = imgList2; //use imgList to modify the height of listView grids. // create two ListViewItem objects,so there are 16 grids for listView. m_firstItem2 = new ListViewItem(); m_firstItem2.SubItems.Clear(); m_firstItem2.UseItemStyleForSubItems = false; m_firstItem2.Font = new Font("SimSun", 10); m_firstItem2.SubItems[0].Text = String.Format("{0:0}", Power[0]); m_firstItem2.SubItems[0].BackColor = m_simpleGraph.Pens[0].Color; for (int k = 1; k < 8; k++) { if (k < chanCountSet) { m_firstItem2.SubItems.Add((String.Format("{0:0}", Power[k])), Color.Black, Color.Honeydew, new Font("SimSun", 10)); m_firstItem2.SubItems[k].BackColor = m_simpleGraph.Pens[k].Color; } else { m_firstItem2.SubItems.Add(""); m_firstItem2.SubItems[k].BackColor = Color.White; } } ListViewItem[] list2 = new ListViewItem[] { m_firstItem2 }; ListView2.Items.AddRange(list2); ListView3.Clear(); ListView3.FullRowSelect = false; ListView3.Width = 480; ListView3.Height = 21; ListView3.View = View.Details;// Set the view to show details. ListView3.HeaderStyle = ColumnHeaderStyle.None; ListView3.GridLines = true; // there are 8 columns for every item. for (int k = 0; k < 8; k++) { ListView3.Columns.Add("", 60); } // modify the grid's height with image Indirectly. ImageList imgList3 = new ImageList(); imgList3.ImageSize = new Size(1, 21); //width and height. ListView3.SmallImageList = imgList3; //use imgList to modify the height of listView grids. // create two ListViewItem objects,so there are 16 grids for listView. m_firstItem3 = new ListViewItem(); m_firstItem3.SubItems.Clear(); m_firstItem3.UseItemStyleForSubItems = false; m_firstItem3.Font = new Font("SimSun", 10); m_firstItem3.SubItems[0].Text = String.Format("{0:0}", Freq[0]); m_firstItem3.SubItems[0].BackColor = m_simpleGraph.Pens[0].Color; for (int k = 1; k < 8; k++) { if (k < chanCountSet) { m_firstItem3.SubItems.Add((String.Format("{0:0}", Freq[k])), Color.Black, Color.Honeydew, new Font("SimSun", 10)); m_firstItem3.SubItems[k].BackColor = m_simpleGraph.Pens[k].Color; } else { m_firstItem3.SubItems.Add(""); m_firstItem3.SubItems[k].BackColor = Color.White; } } ListViewItem[] list3 = new ListViewItem[] { m_firstItem3 }; ListView3.Items.AddRange(list3); FFT.Enabled = false; }