2012-11-09 221 views
1

下面是代碼:MATLAB - 矩陣尺寸必須同意(儘管它們是 「同意」!)

fs = 22050; 
x = rand(fs,1); 
x = x - mean(x); % get rid of DC offeset 

% set comb-filter coefficients 
f = 220; % fundamental 
L = round(fs/f); % delay length 
coef = 0.99; % IIR coefficient 

% build delay vector and filter 
b = [1 zeros(1,L-1) coef]; 
y = filter(1, b, x); 

% create amplitude envelope for output 
decay = 8; 
expEnv = exp ((0:(length(y)-1))/length(y)); 
expEnv = (1./expEnv).^ decay; 
fprintf('%d\n',length(expEnv)); 
fprintf('%d\n', length(y)); 

% envelope output signal 
z = y .* expEnv; 
sound(z , fs); % play sound 

它拒絕執行Z = Y * expEnv線。 printf行顯示y和expEnv都具有相同的長度(22050)

回答

4

是...... length命令的危險。

雖然他們有相同數量的元素,他們具有相同的形狀:

>> size(y) 
ans = 
     22050   1 
>> size(expEnv) 
ans = 
      1  22050 

這將解決這個問題:

z = y .* expEnv.'; 
+0

是的,轉!這樣的搖滾錯誤:) –

+1

「搖滾錯誤」。大聲笑 – learnvst