如何在MATLAB中為訊號新增高斯白噪聲?
在所有頻率上具有平坦功率譜密度 (PSD) 的噪聲訊號稱為高斯白噪聲或白噪聲。在本教程中,我將解釋如何使用MATLAB為訊號新增高斯白噪聲。但在此之前,讓我們簡要概述一下高斯白噪聲。
什麼是高斯白噪聲?
在指定頻率範圍內所有頻率具有相同能量的噪聲訊號稱為高斯白噪聲。因此,高斯白噪聲在所有頻率上具有平坦的功率譜密度 (PSD)。
在高斯白噪聲的情況下,“白”表示噪聲訊號具有與光學中的白光相同的特性,即包含所有可見光顏色,且比例相同。“高斯”表示噪聲訊號的幅度遵循高斯分佈。其中,高斯分佈具有鐘形曲線。
高斯白噪聲用於訊號處理中,以分析和模擬實際系統中可能發生的現實世界隨機干擾。
現在,讓我們討論如何使用MATLAB為訊號新增高斯白噪聲。
為訊號新增高斯白噪聲
在MATLAB中,有一個內建函式“awgn”,用於為訊號新增高斯白噪聲。此處解釋了為訊號新增高斯白噪聲的分步過程
步驟(1) – 根據輸入訊號的持續時間指定一個時間向量。此向量將用於生成輸入訊號,也用作圖中的x軸。
步驟(2) – 使用時間向量並生成所需波形和引數的輸入訊號。
步驟(3) – 計算訊號功率。
步驟(4) – 設定信噪比 (SNR)。
步驟(5) – 使用“awgn”函式為訊號新增高斯白噪聲。
步驟(6) – 繪製生成的訊號。
現在,讓我們透過示例來實際理解這些步驟。
如前所述,我們有一個內建的MATLAB函式“awgn”來為訊號新增高斯白噪聲。但是,此函式可以根據噪聲級別、訊號功率等引數具有各種語法格式。
“awgn”函式常用的語法格式如下所示
Y = awgn(X, snr)
Y = awgn(X, snr, signalpower)
Y = awgn(X, snr, signalpower, randobject)
Y = awgn(X, snr, signalpower, seed)
Y = awgn(___, powertype)
讓我們詳細討論每種語法以及示例程式。
基於指定的SNR新增高斯白噪聲到訊號
要基於指定的SNR(信噪比)為訊號新增高斯白噪聲,請使用“awgn”函式的以下語法
Y = awgn(X, snr);
此處,X是輸入訊號,snr是信噪比,Y是噪聲訊號。
示例
此處,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');
輸出
使用指定的SNR和訊號功率為訊號新增高斯白噪聲
使用“awgn”函式的以下語法為訊號新增具有指定SNR和訊號功率的高斯白噪聲
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程式來了解此語法的程式碼實現
% 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程式中使用此函式。
% 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”函式所有可能的語法格式。