1

这是代码:

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

1 回答 1

4

是的……length命令的危险。

尽管它们具有相同数量的元素,但它们形状不同:

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

这将解决:

z = y .* expEnv.';
于 2012-11-09T18:32:33.820 回答