本文主要是介绍C++实现窄带干扰建模和宽带干扰建模,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
窄带干扰建模和宽带干扰建模C++实现
1.窄带干扰
1.1定义
窄带干扰是指干扰所占的带宽远小于信号带宽的干扰,包括单频干扰、多频干扰、窄带高斯噪声等。在实际工程应用中,需要具体问题具体分析。所以研究窄带干扰抑制方法需要考虑到对所有类型干扰的普适性问题。
1.2 实现公式
Asf表示干扰幅度,决定了信干比(Signal to Interference Ratio, SIR);f0表示单频干扰的频率,φ为初始相位。
1.3 代码实现
//全部程序代码在最后
oid narrow_band_data()
{string filename = "C:/Users/16599/Desktop/banddata/narrow_band_Test.data";int s;//采样率double A, f, φ; //Al,fl,gl分别为宽带干扰的第 l l l个载波频率分量的幅度,频率和调频率cout << "请输入幅度A:";cin >> A;cout << "请输入频率f(kHz):";cin >> f;f *= 1000;cout << "请输入初始相位φ(°):";cin >> φ;cout << "请输入采样率s(k):";cin >> s;s *= 1000;short* SY = new short[s];ofs.open(filename, ios::out | ios::binary);double Icm;int count = 0;for (double n = 0; n < s; n++){double PI_2_frequency = 2 * M_PI * f;double phaseInc = PI_2_frequency / s;//计算采样间隔Icm = A * cos(phaseInc * n + φ);SY[count] = (short)Icm;count++;}ofs.write((char*)SY, s * sizeof(short));ofs.close();//将生成数据的参数写入配置文件,此处我只写了采样率write_ini("C:/Users/16599/Desktop/banddata/narrow_band_Test.txt", s); delete[]SY;cout << "窄带生完了" << endl;
}
1.4 时域图
因为生成了1000k个数据,所以此时表现为长方形状,将图片放大,可看到具体的各数据变化。
1.5 频域图
窄带干扰在频域部分表现为有凸出的顶峰。
2.宽带干扰
2.1 定义
宽带干扰指的是带宽与发射信号带宽的比值较大或者其绝对带宽较大的干扰。一般情况下干扰带宽与信号带宽的比大于10%时干扰被称作宽带干扰。
2.2 实现公式
L为调频干扰的数量, A为宽带干扰的幅度,f1为频率,g1为调频率。注意的是ej(x)在实现中可表示为cos(x)。
2.3 代码实现
void broad_band_data()
{string filename = "C:/Users/16599/Desktop/banddata/broad_band_Test.data";int s;//采样率double A, f, g; //Al,fl,gl分别为宽带干扰的第 l l l个载波频率分量的幅度,频率和调频率cout << "请输入幅度A:";cin >> A;cout << "请输入频率f(kHz):";cin >> f;f *= 1000;cout << "请输入调频率g(kHz):";cin >> g;g *= 1000;cout << "请输入采样率s(k):";cin >> s;s *= 1000;short* SY = new short[s];ofs.open(filename, ios::out | ios::binary);double Icm;int count = 0;for (double n = 0; n < s; n++){/*double fre = f + g * (n/s);cout << fre << endl;*/double PI_2_frequency = 2 * M_PI * f;double phaseInc = PI_2_frequency / s;//计算采样间隔Icm = A * cos(phaseInc *n + M_PI * g * pow((n/s), 2));SY[count] = (short)Icm;count++;//cout << n << "->" << Icm << endl;}//怎么改(设计) svn代码给老师 不要界面ofs.write((char*)SY, s*sizeof(short));ofs.close();write_ini("C:/Users/16599/Desktop/banddata/broad_band_Test.txt", s);delete []SY;cout << "宽带生完了"<<endl;
}
2.4 时域图
2.5 频域图
3 所有代码
3.1 .h文件
#pragma once
#include<iostream>
using namespace std;void broad_band_data();
void narrow_band_data();void write_ini(string path, int s);
3.2 .cpp文件
#include <iostream>
#include <fstream>
#include "hello.h"
#include <math.h>
#include <atlstr.h>
#include <string>
#define M_PI 3.14159265358979323846
ofstream ofs;
using namespace std;int main() {int key = 1;while (key){cout << "选择生成文件类型(0、不生 1、宽带 2、窄带) :";cin >> key;switch (key){case 0:return 0;case 1:broad_band_data();break;case 2:narrow_band_data();break;default:cout << "输错了吧你,重输!";}system("pause");system("cls");}system("pause");return 0;
}
void broad_band_data()
{string filename = "C:/Users/16599/Desktop/banddata/broad_band_Test.data";int s;//采样率double A, f, g; //Al,fl,gl分别为宽带干扰的第 l l l个载波频率分量的幅度,频率和调频率cout << "请输入幅度A:";cin >> A;cout << "请输入频率f(kHz):";cin >> f;f *= 1000;cout << "请输入调频率g(kHz):";cin >> g;g *= 1000;cout << "请输入采样率s(k):";cin >> s;s *= 1000;short* SY = new short[s];ofs.open(filename, ios::out | ios::binary);double Icm;int count = 0;for (double n = 0; n < s; n++){/*double fre = f + g * (n/s);cout << fre << endl;*/double PI_2_frequency = 2 * M_PI * f;double phaseInc = PI_2_frequency / s;//计算采样间隔Icm = A * cos(phaseInc *n + M_PI * g * pow((n/s), 2));SY[count] = (short)Icm;count++;//cout << n << "->" << Icm << endl;}ofs.write((char*)SY, s*sizeof(short));ofs.close();write_ini("C:/Users/16599/Desktop/banddata/broad_band_Test.txt", s);delete []SY;cout << "宽带生完了"<<endl;
}
void narrow_band_data()
{string filename = "C:/Users/16599/Desktop/banddata/narrow_band_Test.data";int s;//采样率double A, f, φ; //Al,fl,gl分别为宽带干扰的第 l l l个载波频率分量的幅度,频率和调频率cout << "请输入幅度A:";cin >> A;cout << "请输入频率f(kHz):";cin >> f;f *= 1000;cout << "请输入初始相位φ(°):";cin >> φ;cout << "请输入采样率s(k):";cin >> s;s *= 1000;short* SY = new short[s];ofs.open(filename, ios::out | ios::binary);double Icm;int count = 0;for (double n = 0; n < s; n++){/*double fre = f + g * (n/s);cout << fre << endl;*/double PI_2_frequency = 2 * M_PI * f;double phaseInc = PI_2_frequency / s;//计算采样间隔Icm = A * cos(phaseInc * n + φ);SY[count] = (short)Icm;count++;//cout << n << "->" << Icm << endl;}ofs.write((char*)SY, s * sizeof(short));ofs.close();write_ini("C:/Users/16599/Desktop/banddata/narrow_band_Test.txt", s);delete[]SY;cout << "窄带生完了" << endl;
}
void write_ini(string path, int s)
{ofs.open(path, ios::out | ios::binary);string tempstr = "BoardType = JYPXIe69834\n";string str = tempstr + "SampleRate = " + to_string(s) + "\nRange = 10\nDataType = System.Int16\nChannelCount = 1\nChannel[0]\nElapsedTime = 1800661.2116";const char* c_s = str.c_str();ofs.write(c_s, str.length());ofs.close();
}
后续更新连续波干扰、非高斯非平稳、大气噪声
这篇关于C++实现窄带干扰建模和宽带干扰建模的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!