📜  如何使用 MATLAB 将高斯白噪声添加到信号中?

📅  最后修改于: 2022-05-13 01:54:21.733000             🧑  作者: Mango

如何使用 MATLAB 将高斯白噪声添加到信号中?

在本文中,我们将讨论使用 MATLAB 向正弦、余弦和方波等信号添加“高斯白噪声”。可以使用 MATLAB/GNU-Octave 内置函数awgn()将高斯白噪声添加到信号中。这里,“AWGN”代表“加性高斯白噪声”。

AWGN是一种非常基本的噪声模型,常用于通信系统、信号处理和信息论中,用于模拟自然界中发生的随机过程的影响。

根据传递给它的参数的数量和类型,我们通常对 awgn()函数有不同的语法。但在这里,我们将只研究它的两种最常用于通信系统和信号处理的语法。

句法:

注意:信号功率可以作为“测量”或一些标量值来设置input_signal的信号电平,根据snr的值确定合适的噪声电平。

分步实施

让我们借助一个示例来理解实现,我们将在正弦波中添加高斯白噪声。

步骤 1:定义所需的参数

Matlab
% sampling frequency
fs = 1000;
 
% time sampling with step
% size = 0.001 (1/fs)
t = 0:1/fs:1;
 
% frequency of input signal
f = 20;
 
% SNR to be maintained
snr = 10;


Matlab
% input message signal (sine wave)
% generates a sine wave of frequency f
st = sin(2 * pi * f * t);
 
% plot the input signal (sine wave)
% 'b' gives blue colour plot
plot(t, st, 'b', 'Linewidth', 2);
xlabel('Time');
ylabel('Amplitude');
title('Input Message Signal');
grid on;


Matlab
% signal with white Gaussian noise
% adds White Gaussian Noise to the signal
st_nn = awgn(st, snr, 'measured');
 
% plot the noisy signal
% 'r' gives red colour plot
plot(t, st_nn, 'r', 'Linewidth', 2);
xlabel('Time');
ylabel('Amplitude');
title('Signal After Addition of Noise');
grid on;


Matlab
% sampling frequency
fs = 1000;
 
% time sampling with step size
% 0.001 (1/fs)
t = 0:1/fs:1;
 
% frequency of input signal
f = 10;
 
% SNR to be maintained 
snr = 5;
 
% Input Message Signal
% generates a square wave of
% frequency f
st = square(2 * pi * f * t);
subplot(2,1,1);
 
% 'b' gives blue colour plot
plot(t,st,'b','Linewidth',2);
xlabel('Time'); ylabel('Amplitude');
title('Input Message Signal');
grid on; 
 
% signal with white Gaussian
% noise adds White Gaussian
% Noise to the signal
st_nn = awgn(st,snr,'measured');
 
% gives a blue colour plot of
% square wave
subplot(2,1,2); plot(t, st, 'b', 'Linewidth', 2);
 
% puts the next graph on the
% same plot
hold on;
 
% gives a red colour plot of the
% AWGN noise
plot(t, st_nn, 'r');
xlabel('Time');
ylabel('Amplitude');
title('Signal After Addition of Noise');
grid on;
hold off;





步骤 2:定义输入信号并绘图

MATLAB

% input message signal (sine wave)
% generates a sine wave of frequency f
st = sin(2 * pi * f * t);
 
% plot the input signal (sine wave)
% 'b' gives blue colour plot
plot(t, st, 'b', 'Linewidth', 2);
xlabel('Time');
ylabel('Amplitude');
title('Input Message Signal');
grid on;

输出:

输入信号(正弦波)

第 3 步:将高斯白噪声添加到信号和绘图中

MATLAB

% signal with white Gaussian noise
% adds White Gaussian Noise to the signal
st_nn = awgn(st, snr, 'measured');
 
% plot the noisy signal
% 'r' gives red colour plot
plot(t, st_nn, 'r', 'Linewidth', 2);
xlabel('Time');
ylabel('Amplitude');
title('Signal After Addition of Noise');
grid on;

输出:

噪声信号(具有高斯白噪声)

让我们看另一个例子,将高斯白噪声添加到方波中。我们必须按照与上面相同的三个步骤将高斯白噪声添加到方波中。但是这次我们将在同一图中同时绘制输入信号和噪声信号,以仔细分析变化。

MATLAB

% sampling frequency
fs = 1000;
 
% time sampling with step size
% 0.001 (1/fs)
t = 0:1/fs:1;
 
% frequency of input signal
f = 10;
 
% SNR to be maintained 
snr = 5;
 
% Input Message Signal
% generates a square wave of
% frequency f
st = square(2 * pi * f * t);
subplot(2,1,1);
 
% 'b' gives blue colour plot
plot(t,st,'b','Linewidth',2);
xlabel('Time'); ylabel('Amplitude');
title('Input Message Signal');
grid on; 
 
% signal with white Gaussian
% noise adds White Gaussian
% Noise to the signal
st_nn = awgn(st,snr,'measured');
 
% gives a blue colour plot of
% square wave
subplot(2,1,2); plot(t, st, 'b', 'Linewidth', 2);
 
% puts the next graph on the
% same plot
hold on;
 
% gives a red colour plot of the
% AWGN noise
plot(t, st_nn, 'r');
xlabel('Time');
ylabel('Amplitude');
title('Signal After Addition of Noise');
grid on;
hold off;

输出:

输出图