how to vectorize this for loop
显示 更早的评论
tic; [s,fs]=audioread('sample.wav'); fdatool
l=length(s); figure('name','speechsignal');
subplot(3,3,1); plot (s); title('speech signal'); xlabel('samples---->'); ylabel('amplitudes---->');
t=(0:1:l-1)/fs; subplot(3,3,2); plot(t,s); title('Speech signal on time axis'); xlabel('time(s) ---->'); ylabel('Amplitude ---->');
f_d=0.1; f_s=floor(l*f_d); overlap=f_s/2; no_f=floor((l/f_s)*2-1); n=zeros(f_s,no_f); n = s( bsxfun(@plus, (1:f_s).', ((1:no_f)-1)*overlap ) );
subplot(3,3,3);
plot(n);
title('Framing');
xlabel('frames');
ylabel('amplitude');
time=toc
% %windowing
w=hamming(f_s);
for i=1:no_f;
xw(:,i)=w.*n(:,i);
end
1 个评论
回答(1 个)
Jan
2017-8-9
I assume you can replace the loop
for i=1:no_f;
xw(:,i)=w.*n(:,i);
end
by:
xw = w .* n; % >= R2016b
For older Matlab versions:
xw = bsxfun(@times, w, n);
类别
在 帮助中心 和 File Exchange 中查找有关 Descriptive Statistics 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!