2012-02-15 98 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);