awgn()函数在c++实现
时间: 2023-08-11 21:16:14 浏览: 496
C++QPSK调制解调
awgn()函数是用于添加高斯白噪声的函数,具体实现可以参考以下代码:
```c++
#include <iostream>
#include <cmath>
#include <random>
using namespace std;
double awgn(double signal, double snr) {
double noise = 0;
double power_signal = signal * signal;
double power_noise = power_signal / pow(10, snr / 10);
std::default_random_engine generator;
std::normal_distribution<double> distribution(0, sqrt(power_noise / 2));
noise = distribution(generator);
double noisy_signal = signal + noise;
return noisy_signal;
}
int main() {
double signal = 1.0;
double snr = 10.0;
double noisy_signal = awgn(signal, snr);
cout << "Original Signal: " << signal << endl;
cout << "Noisy Signal: " << noisy_signal << endl;
return 0;
}
```
在该代码中,使用了C++11的随机数生成库random,通过正态分布生成高斯白噪声,并且根据信噪比计算噪声功率,最后将噪声和信号相加得到带噪信号。
阅读全文