0
  • 聊天消息
  • 系統(tǒng)消息
  • 評(píng)論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會(huì)員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識(shí)你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

如何用MATLAB生成AWGN噪聲

FPGA技術(shù)江湖 ? 來源:FPGA算法工程師 ? 作者:FPGA算法工程師 ? 2022-07-03 15:10 ? 次閱讀

huanying

MATLAB中的help文檔,是一個(gè)神奇的存在,檢索你想找的關(guān)鍵詞,會(huì)自動(dòng)檢索出與關(guān)鍵詞相關(guān)的內(nèi)容。例如:檢索一下“awgn”,我們可以得到如下圖所示的界面。

830b2f06-f396-11ec-ba43-dac502259ad0.png

可以非常方便地查閱函數(shù)的語法定義,信號(hào)定義,以及給出example。

83351730-f396-11ec-ba43-dac502259ad0.png

835a3754-f396-11ec-ba43-dac502259ad0.png

大部分非核心函數(shù),可以打開看到源碼,例如awgn的源碼:

function y = awgn(varargin)%AWGN Add white Gaussian noise to a signal.%   Y = AWGN(X,SNR) adds white Gaussian noise to X.  The SNR is in dB.%   The power of X is assumed to be 0 dBW.  If X is complex, then %   AWGN adds complex noise.%%   Y = AWGN(X,SNR,SIGPOWER) when SIGPOWER is numeric, it represents %   the signal power in dBW. When SIGPOWER is 'measured', AWGN measures%   the signal power before adding noise.%%   Y = AWGN(X,SNR,SIGPOWER,S) uses S to generate random noise samples with%   the RANDN function. S can be a random number stream specified by%   RandStream. S can also be an integer, which seeds a random number%   stream inside the AWGN function. If you want to generate repeatable%   noise samples, then either reset the random stream input before calling%   AWGN or use the same seed input.%%   Y = AWGN(..., POWERTYPE) specifies the units of SNR and SIGPOWER.%   POWERTYPE can be 'db' or 'linear'.  If POWERTYPE is 'db', then SNR%   is measured in dB and SIGPOWER is measured in dBW.  If POWERTYPE is%   'linear', then SNR is measured as a ratio and SIGPOWER is measured%   in Watts.%%   Example 1: %        % To specify the power of X to be 0 dBW and add noise to produce%        % an SNR of 10dB, use:%        X = sqrt(2)*sin(0:pi/8:6*pi);%        Y = awgn(X,10,0);%%   Example 2: %        % To specify the power of X to be 3 Watts and add noise to%        % produce a linear SNR of 4, use:%        X = sqrt(2)*sin(0:pi/8:6*pi);%        Y = awgn(X,4,3,'linear');%%   Example 3: %        % To cause AWGN to measure the power of X and add noise to%        % produce a linear SNR of 4, use:%        X = sqrt(2)*sin(0:pi/8:6*pi);%        Y = awgn(X,4,'measured','linear');%%   Example 4: %        % To specify the power of X to be 0 dBW, add noise to produce%        % an SNR of 10dB, and utilize a local random stream, use:%        S = RandStream('mt19937ar','Seed',5489);%        X = sqrt(2)*sin(0:pi/8:6*pi);%        Y = awgn(X,10,0,S);%%   Example 5: %        % To specify the power of X to be 0 dBW, add noise to produce%        % an SNR of 10dB, and produce reproducible results, use:%        reset(RandStream.getGlobalStream)%        X = sqrt(2)*sin(0:pi/8:6*pi);%        Y = awgn(X,10,0);%%%   See also comm.AWGNChannel, WGN, RANDN, RandStream/RANDN, and BSC.
%   Copyright 1996-2018 The MathWorks, Inc.
%#codegen
narginchk(2,5);
% Validate signal inputsig = varargin{1};validateattributes(sig, {'numeric'}, ...    {'nonempty'}, 'awgn', 'signal input');
% Validate SNR inputreqSNR = varargin{2};validateattributes(reqSNR, {'numeric'}, ...    {'real','scalar','nonempty'}, 'awgn', 'SNR input');
% Validate signal powerif nargin >= 3    if strcmpi(varargin{3}, 'measured')       sigPower = sum(abs(sig(:)).^2)/numel(sig); % linear    else        validateattributes(varargin{3}, {'numeric'}, ...            {'real','scalar','nonempty'}, 'awgn', 'signal power input');        sigPower = varargin{3}; % linear or dB    endelse    sigPower = 1; % linear, defaultend
% Validate state or power typeif nargin >= 4        coder.internal.errorIf(comm.internal.utilities.isCharOrStringScalar(varargin{4}) && ...        all(~strcmpi(varargin{4}, {'db','linear'})), ...        'commInvalidPowerType');
    isStream = ~isempty(varargin{4}) && ~comm.internal.utilities.isCharOrStringScalar(varargin{4});
    if isStream && ~isa(varargin{4}, 'RandStream') % Random stream seed        validateattributes(varargin{4}, {'double'}, ...            {'real','scalar','nonnegative','integer','<',2^32}, ...            'awgn', 'seed input');    endelse % Default    isStream = false;end
% Validate power typeif nargin == 5    coder.internal.errorIf(comm.internal.utilities.isCharOrStringScalar(varargin{4}), ... % Type has been specified as the 4th input        'commInputAfterPowerType');     coder.internal.errorIf(all(~strcmpi(varargin{5}, {'db','linear'})), ...        'commInvalidPowerType'); end
isLinearScale = ((nargin == 4) && ~isStream && strcmpi(varargin{4}, 'linear')) || ...    ((nargin == 5) && strcmpi(varargin{5}, 'linear'));
% Cross-validationcoder.internal.errorIf(isLinearScale && (sigPower < 0), ...    'commInvalidSigPowerForLinearMode');
coder.internal.errorIf(isLinearScale && (reqSNR < 0), ...    'commInvalidSNRForLinearMode');
if ~isLinearScale  % Convert signal power and SNR to linear scale    if (nargin >= 3) && ~comm.internal.utilities.isCharOrStringScalar(varargin{3}) % User-specified signal power        sigPower = 10^(sigPower/10);    end    reqSNR = 10^(reqSNR/10);end
noisePower = sigPower/reqSNR;
if isStream    if isa(varargin{4}, 'RandStream')        stream = varargin{4};    elseif isempty(coder.target)        stream = RandStream('shr3cong', 'Seed', varargin{4});    else                stream = coder.internal.RandStream('shr3cong', 'Seed', varargin{4});    end
    if ~isreal(sig)        noise = sqrt(noisePower/2)* (randn(stream, size(sig)) + ...                                  1i*randn(stream, size(sig)));    else        noise = sqrt(noisePower)* randn(stream, size(sig));    endelse    if ~isreal(sig)        noise = sqrt(noisePower/2)* (randn(size(sig)) + 1i*randn(size(sig)));    else        noise = sqrt(noisePower)* randn(size(sig));    endend    
y = sig + noise; 
% [EOF]

但是,如果不用MATLAB內(nèi)置的awgn函數(shù),如何用MATLAB生成AWGN噪聲?

可以自己寫一個(gè),可以找找別人寫的,站在別人的肩膀上,可以看得更遠(yuǎn)。(如果是學(xué)習(xí),建議理解awgn背后的原理和定義,然后自己寫;如果只是為了應(yīng)用,提高效率,直接用,浮躁的沉不下來的心,已經(jīng)蔓延~)

下面這份文檔,借花獻(xiàn)佛,在不用內(nèi)置的函數(shù)下,用MATLAB生成AWGN噪聲,可以參考一下。

836d4024-f396-11ec-ba43-dac502259ad0.png

839de4b8-f396-11ec-ba43-dac502259ad0.png

83c57a5a-f396-11ec-ba43-dac502259ad0.png

83dbdf98-f396-11ec-ba43-dac502259ad0.png

84399d54-f396-11ec-ba43-dac502259ad0.png

文檔來源于https://www.gaussianwaves.com,國(guó)外的網(wǎng)站,總是這么專業(yè)!

高斯波形,信號(hào)處理,通信系統(tǒng),簡(jiǎn)潔明了。

845173c0-f396-11ec-ba43-dac502259ad0.png

846c5e24-f396-11ec-ba43-dac502259ad0.png

8496bca0-f396-11ec-ba43-dac502259ad0.png

84a6228a-f396-11ec-ba43-dac502259ad0.png

MATLAB 源碼:

%author - Mathuranathan Viswanathan (gaussianwaves.com%This code is part of the books: Wireless communication systems using Matlab & Digital modulations using Matlab.
function [r,n,N0] = add_awgn_noise(s,SNRdB,L)%Function to add AWGN to the given signal%[r,n,N0]= add_awgn_noise(s,SNRdB) adds AWGN noise vector to signal%'s' to generate a %resulting signal vector 'r' of specified SNR%in dB. It also returns the noise vector 'n' that is added to the%signal 's' and the spectral density N0 of noise added%%[r,n,N0]= add_awgn_noise(s,SNRdB,L) adds AWGN noise vector to%signal 's' to generate a resulting signal vector 'r' of specified%SNR in dB. The parameter 'L' specifies the oversampling ratio used%in the system (for waveform simulation). It also returns the noise%vector 'n' that is added to the signal 's' and the spectral%density N0 of noise added s_temp=s; if iscolumn(s), s=s.'; end; %to return the result in same dim as 's' gamma = 10?(SNRdB/10); %SNR to linear scale  if nargin==2, L=1; end %if third argument is not given, set it to 1  if isvector(s),  P=L*sum(abs(s).?2)/length(s);%Actual power in the vector else %for multi-dimensional signals like MFSK  P=L*sum(sum(abs(s).?2))/length(s); %if s is a matrix [MxN] end  N0=P/gamma; %Find the noise spectral density if(isreal(s)),  n = sqrt(N0/2)*randn(size(s));%computed noise else  n = sqrt(N0/2)*(randn(size(s))+1i*randn(size(s)));%computed noise end  r = s + n; %received signal  if iscolumn(s_temp), r=r.'; end;%return r in original format as send

原文標(biāo)題:基礎(chǔ):如何用MATLAB生成AWGN噪聲?(附源代碼)

文章出處:【微信公眾號(hào):FPGA技術(shù)江湖】歡迎添加關(guān)注!文章轉(zhuǎn)載請(qǐng)注明出處。

審核編輯:彭靜

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場(chǎng)。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請(qǐng)聯(lián)系本站處理。 舉報(bào)投訴
  • matlab
    +關(guān)注

    關(guān)注

    180

    文章

    2952

    瀏覽量

    229854
  • 函數(shù)
    +關(guān)注

    關(guān)注

    3

    文章

    4256

    瀏覽量

    62223
  • AWGN
    +關(guān)注

    關(guān)注

    0

    文章

    7

    瀏覽量

    6722

原文標(biāo)題:基礎(chǔ):如何用MATLAB生成AWGN噪聲?(附源代碼)

文章出處:【微信號(hào):HXSLH1010101010,微信公眾號(hào):FPGA技術(shù)江湖】歡迎添加關(guān)注!文章轉(zhuǎn)載請(qǐng)注明出處。

收藏 人收藏

    評(píng)論

    相關(guān)推薦

    何用matlab仿真CCD的噪聲

    現(xiàn)在已經(jīng)用光學(xué)設(shè)計(jì)軟件仿真出了圖像,怎么在matlab中給它加CCD的仿真噪聲!謝謝啦
    發(fā)表于 11-29 16:52

    何用matlab寫出sollin算法

    何用matlab寫出sollin算法?求大神帶我學(xué)習(xí),價(jià)格好商量。
    發(fā)表于 04-17 20:30

    Matlab中的snr

    matlab中產(chǎn)生高斯白噪聲可以直接應(yīng)用兩個(gè)函數(shù),一個(gè)是WGN,另一個(gè)是AWGN。WGN用于產(chǎn)生高斯白噪聲,AWGN則用于在某一信號(hào)中加
    發(fā)表于 05-27 10:10

    何用matlab生成正弦波數(shù)據(jù)?

    何用matlab生成正弦波數(shù)據(jù)?
    發(fā)表于 11-22 07:15

    AWGN信道仿真數(shù)據(jù)量研究

    研究了蒙特卡羅仿真原理和仿真結(jié)果置信度;結(jié)合AWGN(加性白高斯噪聲)信道特點(diǎn),甄選出3 個(gè)合適的參量,即誤碼個(gè)數(shù)、置信概率和仿真結(jié)果最大相對(duì)誤差;提出了AWGN 信道下仿真數(shù)據(jù)
    發(fā)表于 09-08 15:25 ?21次下載

    MathWorks推出基于MATLAB生成HDL代碼的產(chǎn)品

    MathWorks 近日宣布推出 HDL Coder,該產(chǎn)品 支持MATLAB 自動(dòng)生成 HDL 代碼,允許工程師利用廣泛應(yīng)用的 MATLAB 語言實(shí)現(xiàn) FPGA 和 ASIC 設(shè)計(jì)。
    發(fā)表于 03-07 09:27 ?2134次閱讀
    MathWorks推出基于<b class='flag-5'>MATLAB</b><b class='flag-5'>生成</b>HDL代碼的產(chǎn)品

    MATLAB如何生成EXE文件介紹

    MATLAB如何生成EXE文件介紹,感興趣的小伙伴們可以看看。
    發(fā)表于 07-25 10:45 ?0次下載

    詳解如何用AD生成Gerber文件

    詳解如何用AD生成Gerber文件
    發(fā)表于 11-23 11:07 ?0次下載

    一文了解加性高斯白噪聲AWGN)資料下載

    電子發(fā)燒友網(wǎng)為你提供一文了解加性高斯白噪聲AWGN)資料下載的電子資料下載,更有其他相關(guān)的電路圖、源代碼、課件教程、中文資料、英文資料、參考設(shè)計(jì)、用戶指南、解決方案等資料,希望可以幫助到廣大的電子工程師們。
    發(fā)表于 04-03 08:55 ?91次下載
    一文了解加性高斯白<b class='flag-5'>噪聲</b>(<b class='flag-5'>AWGN</b>)資料下載

    何用matlab生成一個(gè)可編程FIR濾波器的硬件HDL代碼?

    01 概述 本文通過matlab自帶的工具箱生成一個(gè)可編程FIR濾波器的硬件HDL代碼,可生成VHDL或者Verilog HDL兩種類型的代碼。 02 具體操作步驟 新建一個(gè)matlab
    的頭像 發(fā)表于 05-03 09:37 ?3442次閱讀
    如<b class='flag-5'>何用</b><b class='flag-5'>matlab</b><b class='flag-5'>生成</b>一個(gè)可編程FIR濾波器的硬件HDL代碼?

    何用MATLAB實(shí)現(xiàn)靜態(tài)仿真電子版下載

    何用MATLAB實(shí)現(xiàn)靜態(tài)仿真電子版下載
    發(fā)表于 05-27 10:40 ?0次下載

    何用MATLAB進(jìn)行電路仿真

    本文演示如何用MATLAB進(jìn)行電路仿真,測(cè)量RLC電路的電壓。我用的是R2014a,不同版本軟件界面稍有差別。
    的頭像 發(fā)表于 08-09 17:14 ?1.3w次閱讀

    【C語言應(yīng)用】如何用C代碼生成一維碼?

    【C語言應(yīng)用】如何用C代碼生成一維碼?
    的頭像 發(fā)表于 08-25 12:42 ?2351次閱讀
    【C語言應(yīng)用】如<b class='flag-5'>何用</b>C代碼<b class='flag-5'>生成</b>一維碼?

    NC3400系列同軸AWGN噪聲源介紹

    Noisecom的NC3400系列同軸AWGN噪聲源需用高ENR和抗高入射點(diǎn)RF使用功率(例如ATE、輻射計(jì)和雷達(dá)系統(tǒng))的最佳選擇??紤]到NC3400系列噪聲源的校正精度和平面度比較低,VSWR也
    發(fā)表于 02-08 09:07 ?471次閱讀

    何用MATLAB進(jìn)行電路仿真?

    本文演示如何用MATLAB進(jìn)行電路仿真,測(cè)量RLC電路的電壓。我用的是R2014a,不同版本軟件界面稍有差別。
    的頭像 發(fā)表于 05-26 09:47 ?4373次閱讀
    如<b class='flag-5'>何用</b><b class='flag-5'>MATLAB</b>進(jìn)行電路仿真?