private double peakCompare; ///自相关函数第一副峰与主峰幅度平方之比 #endregion #region 构造函数 /// <summary> ///参数计算 /// </summary> /// <param name="name">BPSK或BOC信号的类型</param> /// <param name="psdSequence">BPSK或BOC信号的频率谱密度采样点集合</param> /// <param name="autoCorrelationSequence">BPSK或BOC信号的自相关函数的点集合</param> /// <returns></returns> public Param(string name, List <Point> psdSequence, List <Point> autoCorrelationSequence) { //从文件中读取初始化参数 FileStream fileStream = new FileStream(@"../../bandWidth.txt", FileMode.Open, FileAccess.Read); //打开参数存储文件并写入文件流 StreamReader streamReader = new StreamReader(fileStream); //创建文件流写入类 string[] str = streamReader.ReadLine().Split(','); //从文件中读取字符串,并以','为间隔提取出参数 boundWidth = Convert.ToInt32(str[0]); //如下四行为将参数存储到本类的私有字段中 foreBW = Convert.ToInt32(str[1]); stepLength = boundWidth / Convert.ToInt32(str[2]); acCount = Convert.ToInt32(str[3]); val = (boundWidth - foreBW) / (2 * stepLength); //关闭文件流 streamReader.Close(); fileStream.Close(); BPSK_Sequence_Generate bpsk = new BPSK_Sequence_Generate(1.023); ///实例化1.023MHzBPSK BOC_Sequence_Generate boc = new BOC_Sequence_Generate(10, 5); ///实例化BOC(10,5) frequenceDelta = GetFrequenceDelta(psdSequence); ///求得频谱主瓣距频带中心的频偏 lambda = LambdaGet(psdSequence); ///求得带限功率λ nintyPercentBW = GetNintypercentBW(psdSequence); ///求得90%功率的带宽 waste = GetWaste(psdSequence); ///求得带外的损失 betaSq = RMS(psdSequence); ///求得带限信号的均方根带宽 betaRect = Bandwidth(psdSequence); ///求得等效矩形带宽 klsWithSelf = KLS(psdSequence, psdSequence); ///求得与自身的频谱隔离系数 klsWithBpsk = KLS(psdSequence, bpsk.GetPsdSequenceReal); ///求得与 1.023M H zBPSK 的频谱隔离系数 klsWithBoc = KLS(psdSequence, boc.GetPsdSequenceReal); ///求得与BOC (10,5)的频谱隔离系数 delay = GetDelay(autoCorrelationSequence); ///求得自相关函数主峰与第一副峰间的时延、自相关函数第一副峰与主峰幅度平方之比 this.name = name; ///得到选择的波形类型 }
public Param(string name, List <Point> signalPoints) { BPSK_Sequence_Generate bpsk = new BPSK_Sequence_Generate(1.023, 2); BOC_Sequence_Generate boc = new BOC_Sequence_Generate(10, 5); frequenceDelta = GetFrequenceDelta(signalPoints); lambda = LambdaGet(signalPoints); betaSq = RMS(signalPoints); betaRect = Bandwidth(signalPoints); klsWithSelf = KLS(signalPoints, signalPoints); klsWithBpsk = KLS(signalPoints, bpsk.GetPsdSequenceReal); klsWithBoc = KLS(signalPoints, boc.GetPsdSequenceReal); this.name = name; }
/// <summary> /// 添加按钮的事件处理程序 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddButton_Click(object sender, RoutedEventArgs e) { try { string name; if (context.FrequenceBpsk != 0) { name = String.Format(context.FrequenceBpsk + "MHzBPSK"); if (context.nameList.Contains(name)) { MessageBox.Show("已添加过该BPSK参数", "提示"); } else { BPSK_Sequence_Generate bpskSequenceGenerate = new BPSK_Sequence_Generate(Convert.ToDouble(context.FrequenceBpsk));//利用TextBox中输入的参数获取一个序列 paramList.Add(new Param(name, bpskSequenceGenerate.GetPsdSequenceReal, null)); context.nameList.Add(name); } } if ((context.Alpha != 0) && (context.Beta != 0)) { name = String.Format("BOC(" + context.Alpha + "," + context.Beta + ")"); if (context.nameList.Contains(name)) { MessageBox.Show("已添加过该BOC参数", "提示"); } else { BOC_Sequence_Generate bocSequenceGenerate = new BOC_Sequence_Generate(Convert.ToInt32(context.Alpha), Convert.ToInt32(context.Beta)); //利用TextBox中输入的参数获取一个序列 paramList.Add(new Param(name, bocSequenceGenerate.GetPsdSequenceReal, bocSequenceGenerate.GetAutocorrelationSequence)); //添加到listView显示 context.nameList.Add(name); //在已添加列表中做出标记以免重复添加 } } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { context.FrequenceBpsk = 0; context.Alpha = 0; context.Beta = 0; } }
private void AddButton_Click(object sender, RoutedEventArgs e) { string name; if (context.FrequenceBpsk != 0) { name = String.Format(context.FrequenceBpsk + "MHzBPSK"); if (context.nameList.Contains(name)) { MessageBox.Show("已添加过该BPSK参数", "提示"); } else { BPSK_Sequence_Generate bpskSequenceGenerate = new BPSK_Sequence_Generate(Convert.ToDouble(context.FrequenceBpsk), 2);//利用TextBox中输入的参数获取一个序列 paramList.Add(new Param(name, bpskSequenceGenerate.GetPsdSequenceReal)); context.nameList.Add(name); } } if ((context.Alpha != 0) && (context.Beta != 0)) { name = String.Format("BOC(" + context.Alpha + "," + context.Beta + ")"); if (context.nameList.Contains(name)) { MessageBox.Show("已添加过该BOC参数", "提示"); } else { BOC_Sequence_Generate bocSequenceGenerate = new BOC_Sequence_Generate(Convert.ToInt32(context.Alpha), Convert.ToInt32(context.Beta));//利用TextBox中输入的参数获取一个序列 paramList.Add(new Param(name, bocSequenceGenerate.GetPsdSequenceReal)); context.nameList.Add(name); } } context.FrequenceBpsk = 0; context.Alpha = 0; context.Beta = 0; }
private void PaintButton_Click(object sender, RoutedEventArgs e) { BPSK_Sequence_Generate bpskSequenceGenerate = new BPSK_Sequence_Generate(Convert.ToDouble(context.FrequenceBpsk), 2); //利用TextBox中输入的参数获取一个序列 BOC_Sequence_Generate bocSequenceGenerate = new BOC_Sequence_Generate(Convert.ToInt32(context.Alpha), Convert.ToInt32(context.Beta)); //利用TextBox中输入的参数获取一个序列 NewThread newThread = new NewThread(); if (context.WhichMode) { if (context.TimeDomain) { context.points = new List <Point>(); newThread.whichFigure = "bpskTimeDomain"; } else if (context.Psd) { context.points = bpskSequenceGenerate.GetPsdSequenceRealDb;//把计算得到的点序列存到context类中 newThread.whichFigure = "bpskPsd"; } else if (context.Autocorrelation) { context.points = bpskSequenceGenerate.GetAutocorrelationSequence; newThread.whichFigure = "bpskAutocorrelation"; } if ((context.points != null) && (context.points.Count != 0)) { newThread.points = context.points; Thread thread = new Thread(new ThreadStart(newThread.StartThread)); thread.SetApartmentState(ApartmentState.STA); thread.Start(); } else { MessageBox.Show("请先输入频率", "错误"); } } else { if (context.TimeDomain) { context.points = new List <Point>(); newThread.whichFigure = "bocTimeDomain"; } else if (context.Psd) { context.points = bocSequenceGenerate.GetPsdSequenceRealDb;//把计算得到的点序列存到context类中 newThread.whichFigure = "bocPsd"; } else if (context.Autocorrelation) { context.points = bocSequenceGenerate.GetAutocorrelationSequence; newThread.whichFigure = "bocAutocorrelation"; } if ((context.points != null) && (context.points.Count != 0)) { newThread.points = context.points; Thread thread = new Thread(new ThreadStart(newThread.StartThread)); thread.SetApartmentState(ApartmentState.STA); thread.Start(); } else { MessageBox.Show("请先输入频率", "错误"); } } }
/// <summary> /// tab_1中的添加按钮事件处理程序 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Add_Button_Click(object sender, RoutedEventArgs e) { string name = null; try { if (context.WhichMode) //如果要添加的是bpsk参数 { if (context.dictionaryBpskBoc.Count == 0) //当第一次向字典中添加数据时 { BPSK_Sequence_Generate bpsk_Sequence_Generate = new BPSK_Sequence_Generate(Convert.ToDouble(context.FrequenceBpsk)); //创建bpsk实例 if (context.TimeDomain) //如果选择的是画时域波形 { flagTab1 = 0; //设定标志位 name = context.FrequenceBpsk + "MHz" + "BPSK" + "时域波形"; //设定曲线名称 context.dictionaryBpskBoc.Add(name, bpsk_Sequence_Generate.GetBpskSequence); //将曲线名称和曲线保存,以下均相同 } else if (context.Psd) { flagTab1 = 1; name = context.FrequenceBpsk + "MHz" + "BPSK" + "谱密度"; context.dictionaryBpskBoc.Add(name, bpsk_Sequence_Generate.GetPsdSequenceRealDb); } else if (context.Autocorrelation) { flagTab1 = 2; name = context.FrequenceBpsk + "MHz" + "BPSK" + "自相关"; context.dictionaryBpskBoc.Add(name, bpsk_Sequence_Generate.GetAutocorrelationSequence); } listBox_Tab1.Items.Add(name); } else if (context.dictionaryBpskBoc.Count < 5)//当添加小于五项时正常添加。检测标志位和选择的图形类别以判断是否在添加同一类型的图像 { BPSK_Sequence_Generate bpsk_Sequence_Generate = new BPSK_Sequence_Generate(Convert.ToDouble(context.FrequenceBpsk)); if (context.TimeDomain && (flagTab1 == 0)) { throw new Exception("观察时域波形时只可添加一个"); } else if (context.Psd && (flagTab1 == 1)) { name = context.FrequenceBpsk + "MHz" + "BPSK" + "谱密度"; context.dictionaryBpskBoc.Add(name, bpsk_Sequence_Generate.GetPsdSequenceRealDb); listBox_Tab1.Items.Add(name); } else if (context.Autocorrelation && (flagTab1 == 2)) { name = context.FrequenceBpsk + "MHz" + "BPSK" + "自相关"; context.dictionaryBpskBoc.Add(name, bpsk_Sequence_Generate.GetAutocorrelationSequence); listBox_Tab1.Items.Add(name); } else//当添加不同类型波形时抛出异常 { throw new FormatException("请选择和第一次相同类别的波形!"); } } else//当添加超过五项时抛出异常 { throw new IndexOutOfRangeException("最多添加五项!"); } } else { if (context.dictionaryBpskBoc.Count == 0)//完全同上 { BOC_Sequence_Generate boc_Sequence_Generate = new BOC_Sequence_Generate(Convert.ToInt32(context.Alpha), Convert.ToInt32(context.Beta)); if (context.TimeDomain) { flagTab1 = 0; name = "BOC" + "(" + context.Alpha + "," + context.Beta + ")" + "时域波形"; context.dictionaryBpskBoc.Add(name, boc_Sequence_Generate.GetBocSequence); //添加序列 } else if (context.Psd) { flagTab1 = 1; name = "BOC" + "(" + context.Alpha + "," + context.Beta + ")" + "谱密度"; context.dictionaryBpskBoc.Add(name, boc_Sequence_Generate.GetPsdSequenceRealDb); } else if (context.Autocorrelation) { flagTab1 = 2; name = "BOC" + "(" + context.Alpha + "," + context.Beta + ")" + "自相关"; context.dictionaryBpskBoc.Add(name, boc_Sequence_Generate.GetAutocorrelationSequence); } listBox_Tab1.Items.Add(name); } else if (context.dictionaryBpskBoc.Count < 5) { BOC_Sequence_Generate boc_Sequence_Generate = new BOC_Sequence_Generate(Convert.ToInt32(context.Alpha), Convert.ToInt32(context.Beta)); if (context.TimeDomain && (flagTab1 == 0)) { throw new Exception("观察时域波形时只可添加一个"); } else if (context.Psd && (flagTab1 == 1)) { name = "BOC" + "(" + context.Alpha + "," + context.Beta + ")" + "谱密度"; context.dictionaryBpskBoc.Add(name, boc_Sequence_Generate.GetPsdSequenceRealDb); listBox_Tab1.Items.Add(name); } else if (context.Autocorrelation && (flagTab1 == 2)) { name = "BOC" + "(" + context.Alpha + "," + context.Beta + ")" + "自相关"; context.dictionaryBpskBoc.Add(name, boc_Sequence_Generate.GetAutocorrelationSequence); listBox_Tab1.Items.Add(name); } else { throw new FormatException("请选择和第一次相同类别的波形!"); } } else { throw new IndexOutOfRangeException("最多添加五项!"); } } } catch (IOException ex)//处理IO错误 { MessageBox.Show(ex.Message); } catch (ArgumentException)//处理参数错误 { MessageBox.Show("已添加该项", "提示"); } catch (FormatException ex)//处理格式错误 { MessageBox.Show(ex.Message, "提示"); } catch (IndexOutOfRangeException ex)//处理超出数组索引错误 { MessageBox.Show(ex.Message, "提示"); } catch (Exception ex)//处理其他一般错误 { MessageBox.Show(ex.Message, "提示"); } finally//无论是否发生错误均重置输入的参数 { //重置输入的参数 context.FrequenceBpsk = 0; context.Alpha = 0; context.Beta = 0; } }
/// <summary> /// tab_2的添加按钮的事件处理程序 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Add2_Button_Click(object sender, RoutedEventArgs e) { string name = null; try { if (context.SLine) { int delta; switch (comboBox_SLine.SelectedIndex)//根据不同的s曲线选择不同的Δ参数 { case 0: delta = 20; break; case 1: delta = 30; break; case 2: delta = 40; break; case 3: delta = 50; break; case 4: delta = 60; break; default: delta = 20; break; } if (context.WhichMode_2)//同tab_1的添加按钮逻辑 { if (context.dictionaryError.Count == 0) { BPSK_Sequence_Generate bpsk_Sequence_Generate = new BPSK_Sequence_Generate(Convert.ToDouble(context.FrequenceBpsk)); Error error = new Error(); flagTab2 = 0; name = context.FrequenceBpsk + "MHz" + "BPSK" + delta + "ns"; context.dictionaryError.Add(name, error.Varone(bpsk_Sequence_Generate.GetAutocorrelationSequence, delta)); listBox_Tab2.Items.Add(name); } else if (context.dictionaryError.Count < 5) { BPSK_Sequence_Generate bpsk_Sequence_Generate = new BPSK_Sequence_Generate(Convert.ToDouble(context.FrequenceBpsk)); Error error = new Error(); if (flagTab2 == 0) { name = context.FrequenceBpsk + "MHz" + "BPSK" + delta + "ns"; context.dictionaryError.Add(name, error.Varone(bpsk_Sequence_Generate.GetAutocorrelationSequence, delta)); listBox_Tab2.Items.Add(name); } else { throw new FormatException("请选择和第一次相同类别的波形!"); } } else { throw new IndexOutOfRangeException("最多添加五项!"); } } else { if (context.dictionaryError.Count == 0) { BOC_Sequence_Generate boc_Sequence_Generate = new BOC_Sequence_Generate(Convert.ToInt32(context.Alpha), Convert.ToInt32(context.Beta)); Error error = new Error(); flagTab2 = 0; name = "BOC" + "(" + context.Alpha + "," + context.Beta + ")" + delta + "ns"; context.dictionaryError.Add(name, error.Varone(boc_Sequence_Generate.GetAutocorrelationSequence, delta)); listBox_Tab2.Items.Add(name); } else if (context.dictionaryError.Count < 5) { BOC_Sequence_Generate boc_Sequence_Generate = new BOC_Sequence_Generate(Convert.ToInt32(context.Alpha), Convert.ToInt32(context.Beta)); Error error = new Error(); if (flagTab2 == 0) { name = "BOC" + "(" + context.Alpha + "," + context.Beta + ")" + delta + "ns"; context.dictionaryError.Add(name, error.Varone(boc_Sequence_Generate.GetAutocorrelationSequence, delta)); listBox_Tab2.Items.Add(name); } else { throw new FormatException("请选择和第一次相同类别的波形!"); } } else { throw new IndexOutOfRangeException("最多添加五项!"); } } } else if (context.Delay) { if (context.WhichMode_2) { if (context.dictionaryError.Count == 0) { BPSK_Sequence_Generate bpsk_Sequence_Generate = new BPSK_Sequence_Generate(Convert.ToDouble(context.FrequenceBpsk)); Error error = new Error(); flagTab2 = 1; name = context.FrequenceBpsk + "MHz" + "BPSK" + "码跟踪误差"; context.dictionaryError.Add(name, error.SigmaDeltaSequenceGenerate(bpsk_Sequence_Generate.GetPsdSequenceReal)); listBox_Tab2.Items.Add(name); } else if (context.dictionaryError.Count < 5) { BPSK_Sequence_Generate bpsk_Sequence_Generate = new BPSK_Sequence_Generate(Convert.ToDouble(context.FrequenceBpsk)); Error error = new Error(); if (flagTab2 == 1) { name = context.FrequenceBpsk + "MHz" + "BPSK" + "码跟踪误差"; context.dictionaryError.Add(name, error.SigmaDeltaSequenceGenerate(bpsk_Sequence_Generate.GetPsdSequenceReal)); listBox_Tab2.Items.Add(name); } else { throw new FormatException("请选择和第一次相同类别的波形!"); } } else { throw new IndexOutOfRangeException("最多添加五项!"); } } else { if (context.dictionaryError.Count == 0) { BOC_Sequence_Generate boc_Sequence_Generate = new BOC_Sequence_Generate(Convert.ToInt32(context.Alpha), Convert.ToInt32(context.Beta)); Error error = new Error(); flagTab2 = 1; name = "BOC" + "(" + context.Alpha + "," + context.Beta + ")" + "码跟踪误差"; context.dictionaryError.Add(name, error.SigmaDeltaSequenceGenerate(boc_Sequence_Generate.GetPsdSequenceReal)); listBox_Tab2.Items.Add(name); } else if (context.dictionaryError.Count < 5) { BOC_Sequence_Generate boc_Sequence_Generate = new BOC_Sequence_Generate(Convert.ToInt32(context.Alpha), Convert.ToInt32(context.Beta)); Error error = new Error(); if (flagTab2 == 1) { name = "BOC" + "(" + context.Alpha + "," + context.Beta + ")" + "码跟踪误差"; context.dictionaryError.Add(name, error.SigmaDeltaSequenceGenerate(boc_Sequence_Generate.GetPsdSequenceReal)); listBox_Tab2.Items.Add(name); } else { throw new FormatException("请选择和第一次相同类别的波形!"); } } else { throw new IndexOutOfRangeException("最多添加五项!"); } } } else if (context.CN) { BPSK_Sequence_Generate bpsk_Sequence_Generate; BOC_Sequence_Generate boc_Sequence_Generate; Error error = new Error(); List <Point> tempPoints = new List <Point>(); switch (comboBox_DB.SelectedIndex) { case 0: bpsk_Sequence_Generate = new BPSK_Sequence_Generate(1.023); name = "1.023MHz" + "PSK-R"; tempPoints = error.SigmaCNDbSequenceGenerate(bpsk_Sequence_Generate.GetPsdSequenceReal, "BPSK"); break; case 1: bpsk_Sequence_Generate = new BPSK_Sequence_Generate(10.23); name = "10.23MHz" + "PSK-R"; tempPoints = error.SigmaCNDbSequenceGenerate(bpsk_Sequence_Generate.GetPsdSequenceReal, "BPSK"); break; case 2: boc_Sequence_Generate = new BOC_Sequence_Generate(5, 2); name = "BOC" + "(5,2)"; tempPoints = error.SigmaCNDbSequenceGenerate(boc_Sequence_Generate.GetPsdSequenceReal, "BOC(5,2)"); break; case 3: boc_Sequence_Generate = new BOC_Sequence_Generate(8, 4); name = "BOC" + "(8,4)"; tempPoints = error.SigmaCNDbSequenceGenerate(boc_Sequence_Generate.GetPsdSequenceReal, "BOC(8,4)"); break; case 4: boc_Sequence_Generate = new BOC_Sequence_Generate(10, 5); name = "BOC" + "(10,5)"; tempPoints = error.SigmaCNDbSequenceGenerate(boc_Sequence_Generate.GetPsdSequenceReal, "BOC(10,5)"); break; } if (context.dictionaryError.Count == 0) { flagTab2 = 2; context.dictionaryError.Add(name, tempPoints); listBox_Tab2.Items.Add(name); } else if (context.dictionaryError.Count < 5) { if (flagTab2 == 2) { context.dictionaryError.Add(name, tempPoints); listBox_Tab2.Items.Add(name); } else { throw new FormatException("请选择和第一次相同类别的波形!"); } } else { throw new IndexOutOfRangeException("最多添加五项!"); } } else if (context.MultiPath) { BPSK_Sequence_Generate bpsk_Sequence_Generate; BOC_Sequence_Generate boc_Sequence_Generate; Error error = new Error(); List <Point> tempPoints_1 = new List <Point>(); List <Point> tempPoints_2 = new List <Point>(); switch (comboBox_MultiPath.SelectedIndex) { case 0: bpsk_Sequence_Generate = new BPSK_Sequence_Generate(1.023); name = "1.023MHz" + "PSK-R"; if (error.MultiPathSequenceGenerate(bpsk_Sequence_Generate.GetPsdSequenceReal, out tempPoints_1, out tempPoints_2, "BPSK")) { break; } else { throw new Exception("Error"); } case 1: bpsk_Sequence_Generate = new BPSK_Sequence_Generate(10.23); name = "10.23MHz" + "PSK-R"; if (error.MultiPathSequenceGenerate(bpsk_Sequence_Generate.GetPsdSequenceReal, out tempPoints_1, out tempPoints_2, "BPSK")) { break; } else { throw new Exception("Error"); } case 2: boc_Sequence_Generate = new BOC_Sequence_Generate(5, 2); name = "BOC" + "(5,2)"; if (error.MultiPathSequenceGenerate(boc_Sequence_Generate.GetPsdSequenceReal, out tempPoints_1, out tempPoints_2, "BPSK")) { break; } else { throw new Exception("Error"); } case 3: boc_Sequence_Generate = new BOC_Sequence_Generate(8, 4); name = "BOC" + "(8,4)"; if (error.MultiPathSequenceGenerate(boc_Sequence_Generate.GetPsdSequenceReal, out tempPoints_1, out tempPoints_2, "BPSK")) { break; } else { throw new Exception("Error"); } case 4: boc_Sequence_Generate = new BOC_Sequence_Generate(10, 5); name = "BOC" + "(10,5)"; if (error.MultiPathSequenceGenerate(boc_Sequence_Generate.GetPsdSequenceReal, out tempPoints_1, out tempPoints_2, "BPSK")) { break; } else { throw new Exception("Error"); } } if (context.dictionaryError.Count == 0) { flagTab2 = 3; context.dictionaryError.Add(name + "Even", tempPoints_1); context.dictionaryError.Add(name + "Odd", tempPoints_2); listBox_Tab2.Items.Add(name); } else if (context.dictionaryError.Count < 10) { if (flagTab2 == 3) { context.dictionaryError.Add(name + "Even", tempPoints_1); context.dictionaryError.Add(name + "Odd", tempPoints_2); listBox_Tab2.Items.Add(name); } else { throw new FormatException("请选择和第一次相同类别的波形!"); } } else { throw new IndexOutOfRangeException("最多添加五项!"); } } } catch (ArgumentException) { MessageBox.Show("已添加该项", "提示"); } catch (FormatException ex) { MessageBox.Show(ex.Message, "提示"); } catch (IndexOutOfRangeException ex) { MessageBox.Show(ex.Message, "提示"); } catch (Exception ex) { MessageBox.Show(ex.Message, "提示"); } }