问小白 wenxiaobai
资讯
历史
科技
环境与自然
成长
游戏
财经
文学与艺术
美食
健康
家居
文化
情感
汽车
三农
军事
旅行
运动
教育
生活
星座命理

MATLAB 如何给信号添加白噪声

创作时间:
作者:
@小白创作中心

MATLAB 如何给信号添加白噪声

引用
1
来源
1.
https://deepinout.com/matlab/matlab-top-articles/1694772140_tr_how-to-add-white-gaussian-noise-to-signal-using-matlab.html

白高斯噪声是一种在所有频率上具有平坦功率谱密度(PSD)的噪声信号。在信号处理中,它常被用于分析和模拟实际系统中可能发生的随机干扰。本文将详细介绍如何使用MATLAB给信号添加白高斯噪声,并通过多个示例展示'awgn'函数的不同用法。

什么是白高斯噪声

白高斯噪声是一种在指定频率范围内所有频率上具有相等能量的噪声信号。因此,白高斯噪声在所有频率上都有平坦的功率谱密度(PSD)。

对于白高斯噪声,术语"白"表明噪声信号具有与光学中的白光相同的特性,即包含所有可见颜色,并且比例相等。而"高斯噪声"表示噪声信号的幅度遵循高斯分布,其中高斯分布具有钟形曲线。

白高斯噪声在信号处理中用于分析和模拟可能发生在实际系统中的真实随机干扰。

给信号添加白高斯噪声

在MATLAB中,有一个内置函数'awgn'用于给信号添加白高斯噪声。下面解释了按步骤给信号添加白高斯噪声的过程:

  1. 第一步:根据输入信号的持续时间指定一个时间向量。该向量将用于生成输入信号,并作为图形的x轴。
  2. 第二步:使用时间向量生成所需波形和参数的输入信号。
  3. 第三步:计算信号功率。
  4. 第四步:设置信噪比(SNR)。
  5. 第五步:使用'awgn'函数将白高斯噪声添加到信号中。
  6. 第六步:绘制结果信号。

现在,让我们通过实例帮助理解这些步骤。

按照指定的信噪比将白噪声添加到信号中

为了根据指定的信噪比(Signal-to-Noise Ratio)向信号中增加白噪声,使用'awgn'函数的以下语法:

Y = awgn(X, snr);

在这里,X是输入信号,snr是信噪比,Y是带噪声的信号。

示例

% MATLAB program to add white gaussian noise to signal based on SNR
% Create a sample sinusoidal signal
t = 0:0.005:2;  % Time vector
X = sin(2*pi*5*t);  % Input signal 
% Set SNR in dB
snr = 15;
% Add white gaussian noise to signal
Y = awgn(X, snr);
% Plot the original signal and the signal with noise
subplot(2, 1, 2);
plot(t, X, t, Y);
legend('Original Signal', 'Noisy Signal');
title('Input Signal with Noise');

将指定的信号功率和信噪比添加到信号中的白噪声

使用'awgn'函数的以下语法可将白噪声添加到具有指定信噪比和信号功率的信号中:

Y = awgn(X, snr, signalpower);

示例

% MATLAB program to add white gaussian noise to signal with specified SNR and signal power
% Generate a sample input signal
t = 0:0.005:2;  % Time vector
X = sin(2*pi*5*t);  % Input signal 
% Compute the signal power
signal_power = sum(X.^2) / length(X);
% Set an SNR
snr = 15;
% Add white gaussian noise to signal
Y = awgn(X, snr, signal_power);
% Plot the original signal and the signal with noise
subplot(2, 1, 2);
plot(t, X, t, Y);
legend('Input Signal', 'Noisy Signal');
title('Input Signal with Noise');

给信号加入具有指定随机数生成器对象的白高斯噪声

使用 'awgn' 函数的以下语法,可以给信号加入具有指定随机数生成器对象的白高斯噪声,用于生成正态分布的随机噪声:

Y = awgn(X, snr, signal_power, rand_object);

示例

% MATLAB program to add white gaussian noise to signal with specified random object
% Generate a sample input signal
t = 0:0.005:2;  % Time vector
X = sin(2*pi*5*t);  % Input signal 
% Compute the signal power
signal_power = sum(X.^2) / length(X);
% Set an SNR in dB
snr = 15;
% Create a random number generator object
rand_obj = RandStream('mt19937ar', 'Seed', 50);
% Add white gaussian noise to signal using the random object
Y = awgn(X, snr, signal_power, rand_obj);
% Plot the original signal and the signal with noise
subplot(2, 1, 2);
plot(t, X, t, Y);
legend('Input Signal', 'Noisy Signal');
title('Input Signal with Noise');

给信号添加具有指定随机种子的白噪声

在MATLAB中,我们可以使用'awgn'函数的以下语法,为了可重复性而给信号添加具有指定随机种子的白高斯噪声:

Y = awgn(X, snr, signal_power, seed);

示例

% MATLAB program to add white gaussian noise to signal with specified random seed
% Generate a sample input signal
t = 0:0.005:2;  % Time vector
X = sin(2*pi*5*t);  % Input signal 
% Compute the signal power
signal_power = sum(X.^2) / length(X);
% Set the SNR in dB
snr = 15;
% Set a random seed for reproducibility
seed = 120;
% Add white gaussian noise to signal using the random seed
Y = awgn(X, snr, signal_power, seed);
% Plot the original signal and the signal with noise
subplot(2, 1, 2);
plot(t, X, t, Y);
legend('Input Signal', 'Noisy Signal');
title('Input Signal with Noise');

向指定功率类型的信号添加白高斯噪声

使用'awgn'函数的以下语法可以向指定功率类型的信号中添加白高斯噪声:

Y = awgn(X, snr, signal_power, power_type);

在这里,参数'power_type'的值可以是'measured','actual'或'db'。默认值为'measured'。

示例

% MATLAB program to add white gaussian noise to signal with specified power type
% Generate a sample input signal
t = 0:0.005:2;  % Time vector
X = sin(2*pi*5*t);  % Input signal 
% Compute the signal power
signal_power = sum(X.^2) / length(X);
% Set the SNR in dB
snr = 15;
% Set the power type
power_type = 'measured';
% Add white gaussian noise to signal using the random seed
Y = awgn(X, snr, signal_power, power_type);
% Plot the original signal and the signal with noise
subplot(2, 1, 2);
plot(t, X, t, Y);
legend('Input Signal', 'Noisy Signal');
title('Input Signal with Noise');

总结

这就是关于使用MATLAB向信号添加白高斯噪声的全部内容。在MATLAB中,使用内置函数'awgn'将白高斯噪声添加到信号中。在本教程中,通过示例程序解释了'awgn'函数的所有可能的语法格式。

© 2023 北京元石科技有限公司 ◎ 京公网安备 11010802042949号