how to vectorize this for loop
Show older comments
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 Comment
Answers (1)
Jan
on 9 Aug 2017
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);
Categories
Find more on Descriptive Statistics in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!