声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 14078|回复: 21

[综合讨论] 关于高斯白噪声

[复制链接]
发表于 2007-7-11 09:56 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
关于matlab中的白噪声的产生,已经知道可以用WGN命令。

我的问题是:现在做的一个东西,需要对白噪声信号进行两次求导,即求其二阶导数值,然后加入至微分方程求解计算。

如果求导使用diff的话,是进行差分运算,求两次导数的话,序列的长度会减少,请问除了用simulink可以解决之外,直接用=编程方法能不能解决这个问题啊?
回复
分享到:

使用道具 举报

发表于 2007-7-11 10:07 | 显示全部楼层
v为对象数据

s1=(diff(v(1:end-1))+diff(v(2:end)))/2;  %中心差分法
s1=[diff(v(1:2));s1;diff(v(end-1:end))]; %少的两个点用前向和后向差分法补齐
s1=s1/dt; %近似为导数


转自Vibmaster老师http://forum.vibunion.com/forum/thread-47721-2-1.html  20楼的回复

评分

1

查看全部评分

 楼主| 发表于 2007-7-11 11:58 | 显示全部楼层
哦,原来可以这样子的哦,太感谢了,我试试看!
 楼主| 发表于 2007-7-11 20:58 | 显示全部楼层

问另外一个问题

再问另外一个问题,不知道大家有没有遇到过。

产生高斯白噪声序列可以用WGN命令,如WGN(1000,1,1)即可生成一个1000*1维的强度为1的高斯白噪声

还有一个办法就是用simulink中的Band-Limited white noise,将白噪声数据输出至工作空间即可。

我的问题就是——这两种方法产生的白噪声,怎么不一样呢?

(1)WGN生成的白噪声数据如何和时间相关联?
(2)在Band-Limited white noise模块中有几个参数,如图,分别取采样时间:0.1、0.05、0.02、0.01,结果分别如下。

采样时间我看了一下帮助,也没有一个确切的说明,所以这里请大家一起帮忙分析一下,为什么这两种方法产生的白噪声会差别这么大。谢谢

Band-Limited white noise模块

Band-Limited white noise模块

取采样时间为0.1的结果

取采样时间为0.1的结果
 楼主| 发表于 2007-7-11 20:59 | 显示全部楼层
下面的两个图分别是采样时间为0.02和0.01的结果

取采样时间为0.02的结果

取采样时间为0.02的结果

取采样时间为0.01的结果

取采样时间为0.01的结果

评分

1

查看全部评分

发表于 2007-7-12 09:49 | 显示全部楼层

回复 #5 octopussheng 的帖子

我的matlab没找到wgn这个函数,本来想看一下代码的。
发表于 2007-7-12 10:56 | 显示全部楼层



我这里没有matlab,所以只能给个主意:对于 wgn 函数,估计你 edit wgn 一下就可以看到源代码了,结合“关于信噪比”的精华帖来阅读吧。至于simulink问题,我就不懂了
发表于 2007-7-12 10:56 | 显示全部楼层
原帖由 zhlong 于 2007-7-12 09:49 发表
我的matlab没找到wgn这个函数,本来想看一下代码的。


2006a以上的版本应该有
 楼主| 发表于 2007-7-12 13:34 | 显示全部楼层
谢谢热心帮助,下面附上wgn的源码!

function y = wgn(varargin)
%WGN Generate white Gaussian noise.
%   Y = WGN(M,N,P) generates an M-by-N matrix of white Gaussian noise.
%   P specifies the power of the output noise in dBW.
%
%   Y = WGN(M,N,P,IMP) specifies the load impedance in Ohms.
%
%   Y = WGN(M,N,P,IMP,STATE) resets the state of RANDN to STATE.
%
%   Additional flags that can follow the numeric arguments are:
%
%   Y = WGN(..., POWERTYPE) specifies the units of P.  POWERTYPE can
%   be 'dBW', 'dBm' or 'linear'.  Linear power is in Watts.
%
%   Y = WGN(..., OUTPUTTYPE); Specifies the output type.  OUTPUTTYPE can
%   be 'real' or 'complex'.  If the output type is complex, then P
%   is divided equally between the real and imaginary components.
%
%   Example: To generate a 1024-by-1 vector of complex noise with power
%            of 5 dBm across a 50 Ohm load, use:
%            Y = WGN(1024, 1, 5, 50, 'dBm', 'complex');
%
%   Example: To generate a 256-by-5 matrix of real noise with power
%            of 10 dBW across a 1 Ohm load, use:
%            Y = WGN(256, 5, 10, 'real');
%
%   Example: To generate a 1-by-10 vector of complex noise with power
%            of 3 Watts across a 75 Ohm load, use:
%            Y = WGN(1, 10, 3, 75, 'linear', 'complex');
%
%   See also RANDN, AWGN.
%   Copyright 1996-2003 The MathWorks, Inc.
%   $Revision: 1.11.4.3 $  $Date: 2004/04/12 23:01:28 $
% --- Initial checks
error(nargchk(3,7,nargin));
% --- Value set indicators (used for the strings)
pModeSet    = 0;
cplxModeSet = 0;
% --- Set default values
p        = [];
row      = [];
col      = [];
pMode    = 'dbw';
imp      = 1;
cplxMode = 'real';
seed     = [];
% --- Placeholders for the numeric and string index values
numArg = [];
strArg = [];
% --- Identify string and numeric arguments
%     An empty in position 4 (Impedance) or 5 (Seed) are considered numeric
for n=1:nargin
   if(isempty(varargin{n}))
      switch n
      case 4
         if(ischar(varargin{n}))
            error('The default impedance should be marked by [].');
         end;
         varargin{n} = imp; % Impedance has a default value
      case 5
         if(ischar(varargin{n}))
            error('The default seed should be marked by [].');
         end;
         varargin{n} = [];  % Seed has no default
      otherwise
         varargin{n} = '';
      end;
   end;
   % --- Assign the string and numeric vectors
   if(ischar(varargin{n}))
      strArg(size(strArg,2)+1) = n;
   elseif(isnumeric(varargin{n}))
      numArg(size(numArg,2)+1) = n;
   else
      error('Only string and numeric arguments are allowed.');
   end;
end;
% --- Build the numeric argument set
switch(length(numArg))
   case 3
      % --- row is first (element 1), col (element 2), p (element 3)
      if(all(numArg == [1 2 3]))
         row    = varargin{numArg(1)};
         col    = varargin{numArg(2)};
         p      = varargin{numArg(3)};
      else
         error('Illegal syntax.')
      end;
   case 4
      % --- row is first (element 1), col (element 2), p (element 3), imp (element 4)
      %
      if(all(numArg(1:3) == [1 2 3]))
         row    = varargin{numArg(1)};
         col    = varargin{numArg(2)};
         p      = varargin{numArg(3)};
         imp    = varargin{numArg(4)};
      else
         error('Illegal syntax.')
      end;
   case 5
      % --- row is first (element 1), col (element 2), p (element 3), imp (element 4), seed (element 5)
      if(all(numArg(1:3) == [1 2 3]))
         row    = varargin{numArg(1)};
         col    = varargin{numArg(2)};
         p      = varargin{numArg(3)};
         imp    = varargin{numArg(4)};
         seed   = varargin{numArg(5)};
      else
         error('Illegal syntax.');
      end;
   otherwise
      error('Illegal syntax.');
end;
% --- Build the string argument set
for n=1:length(strArg)
   switch lower(varargin{strArg(n)})
   case {'dbw' 'dbm' 'linear'}
      if(~pModeSet)
         pModeSet = 1;
         pMode = lower(varargin{strArg(n)});
      else
         error('The Power mode must only be set once.');
      end;
   case {'db'}
      error('Incorrect power mode passed in.  Please use ''dBW'', ''dBm'', or ''linear.''');
   case {'real' 'complex'}
      if(~cplxModeSet)
         cplxModeSet = 1;
         cplxMode = lower(varargin{strArg(n)});
      else
         error('The complexity mode must only be set once.');
      end;
   otherwise
      error('Unknown option passed in.');
   end;
end;
% --- Arguments and defaults have all been set, either to their defaults or by the values passed in
%     so, perform range and type checks
% --- p
if(isempty(p))
   error('The power value must be a real scalar.');
end;
if(any([~isreal(p) (length(p)>1) (length(p)==0)]))
   error('The power value must be a real scalar.');
end;
if(strcmp(pMode,'linear'))
   if(p<0)
      error('In linear mode, the required noise power must be >= 0.');
   end;
end;
% --- Dimensions
if(any([isempty(row) isempty(col) ~isscalar(row) ~isscalar(col)]))
   error('The required dimensions must be real, integer scalars > 1.');
end;
if(any([(row<=0) (col<=0) ~isreal(row) ~isreal(col) ((row-floor(row))~=0) ((col-floor(col))~=0)]))
   error('The required dimensions must be real, integer scalars > 1.');
end;
% --- Impedance
if(any([~isreal(imp) (length(imp)>1) (length(imp)==0) any(imp<=0)]))
   error('The Impedance value must be a real scalar > 0.');
end;
% --- Seed
if(~isempty(seed))
   if(any([~isreal(seed) (length(seed)>1) (length(seed)==0) any((seed-floor(seed))~=0)]))
      error('The State must be a real, integer scalar.');
   end;
end;
% --- All parameters are valid, so no extra checking is required
switch lower(pMode)
   case 'linear'
      noisePower = p;
   case 'dbw'
      noisePower = 10^(p/10);
   case 'dbm'
      noisePower = 10^((p-30)/10);
end;
% --- Generate the noise
if(~isempty(seed))
   randn('state',seed);
end;
if(strcmp(cplxMode,'complex'))
   z = randn(2*row,col);
   y = (sqrt(imp*noisePower/2))*(z(1:row,:)+j*z(row+1:end,:));
else
   y = (sqrt(imp*noisePower))*randn(row,col);
end;
 楼主| 发表于 2007-7-17 21:11 | 显示全部楼层
难道这个问题会成为解决不了的问题???
发表于 2007-7-18 10:29 | 显示全部楼层

回复 #10 octopussheng 的帖子

问题并不难解决,是你没有仔细看wgn的help文档。在文档里提到:
y = wgn(m,n,p,imp,state) is the same as the previous syntax, except that wgn first resets the state of the normal random number generator randn to the integer state.

y = wgn(...,powertype) is the same as the previous syntaxes, except that the string powertype specifies the units of p. Choices for powertype are 'dBW', 'dBm', and 'linear'.
这就是需要注意的2点:
(1)第一条可以推断wgn产生白噪声其实是利用randn函数,而randn函数有个初始状态的问题。你贴的源代码也证实了这点
(2)wgn产生的噪声有3种不同的功率类型'dBW', 'dBm', and 'linear'.
白噪声模块并没有提到噪声功率的类型,因此为了比较就把wgn的各种功率类型的曲线都画出来
白噪声模块的设置:power 0.1  sapmle time 0.1 seed 0 仿真时间10秒
wgn噪声产生的设置:
randn('state',0)%设置seed为0
y=wgn(101,1,0.1,'dBW');
y1=wgn(101,1,0.1,'dBm');
y2=wgn(101,1,0.1,'linear');
由图可见白噪声模块产生的噪声和y=wgn(101,1,0.1,'dBW');产生的噪声是一致的

[ 本帖最后由 花如月 于 2007-7-18 10:34 编辑 ]
temp.JPG

评分

1

查看全部评分

 楼主| 发表于 2007-7-18 19:32 | 显示全部楼层
哦,原来是这个样子的,wgn中噪声类型设置项“powertype”的设置是关键啊!

这个seed对噪声数据的影响也是很大!自己多试试,呵呵,感谢花如月的指点哦!
发表于 2007-7-18 19:50 | 显示全部楼层

回复 #12 octopussheng 的帖子

呵呵,客气了。共同进步!
 楼主| 发表于 2007-7-20 12:11 | 显示全部楼层
还是要强烈建议分析一下这个seed选项,究竟seed该怎样设置才会得到理论上的Gauss白噪声!

我的电脑这两天一直在算一个分岔程序,唉,分不开手啊!
发表于 2007-7-20 12:41 | 显示全部楼层

回复 #14 octopussheng 的帖子

相同的seed也无法产生完全相同的白噪声,噪声本来就是随机的。seed相同时保证的是具有相同的数字特征

评分

1

查看全部评分

您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-9-21 00:34 , Processed in 0.063953 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表