2012-02-15 82 views
0

我的任务是绘制完全随机的信号。MATLAB:剧情随机信号

这是我迄今取得的进展:

sig_length = 200; % this task is part of a three plot figure so ignore the subplot part 
subplot(2,2,1) 
hold on 
sig = rand(1,sig_length); 
plot(1:sig_length,sig) 
axis tight 
title('Signal') 

我的问题是,我想y轴的间隔为-5〜5。我怎样才能做到这一点?先谢谢你。

+0

你想要跑dom信号在-5和5之间变化,还是你希望实际轴显示-5到5? – Phonon 2012-02-15 16:13:07

+0

那么我设法通过编写 轴([0 200 -5 5]) 设置轴显示-5到5,但信号仍然从0变为1. 所以是的,我希望信号达到值显示在轴上:/ – 2012-02-15 16:15:10

+0

你的意思是完全随机的?你想实现什么样的分配?制服?正常? – 2012-02-15 16:43:11

回答

2
  1. 为了设置轴,使用axis([xmin xmax ymin ymax])更多的文档可以发现

  2. 为了创建一个信号,表明为中心0℃,用在开放的间隔均匀分布-5至5,必须先通过10(RAND上开区间(0,1)产生的值,并且需要的值上的范围(-5,5)),并通过5移动它,作为观察的因子缩放兰特如下:

    shiftedCenteredSig =(10 * rand(1,sig_length)) - 5%缩放并移位至-5至5

该图案/配方可在文献中的实施例可以看出:http://www.mathworks.com/help/techdoc/ref/rand.html

实施例实施例1产生上 从均匀分布的值区间[a,b]上:

r = a +(ba)。* rand(100,1);

最后的代码可以看到下面:

sig_length = 200; % this task is part of a three plot figure so ignore the subplot part 
subplot(2,2,1) 
hold on 
%sig = rand(1,sig_length); %note this is a uniform distribution on interval 0,1 
sig = (10*rand(1,sig_length)) - 5 %scaled and shifted to be from -5 to 5 
plot(1:sig_length,sig) 
axis([1,sig_length,-5,5]) 
title('Signal') 
+0

谢谢!这帮了很多! – 2012-02-15 17:34:05

3

如果你想你的信号去从-5到5,

sig = -5 + 10*rand(1,sig_length); 

在一般情况下,随机信号去在ab之间,使用

a + (b-a)*rand(1,length);