필터 지우기
필터 지우기

how to vectorize these for loop?

조회 수: 2 (최근 30일)
serena dsouza
serena dsouza 2017년 8월 9일
편집: Jan 2017년 8월 9일
clc;
clear all;
close all;
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);
M=zeros(f_s,no_f);
for j=1:no_f;%i=1:frame size;
for i=1:f_s;%j=1:no of frames;
M(i,j)=s(((j-1)*overlap)+i);
end;
end;
  댓글 수: 1
José-Luis
José-Luis 2017년 8월 9일
Please edit your code to make it easy to read.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2017년 8월 9일
편집: Walter Roberson 2017년 8월 9일
First improvement:
for j=1:no_f %i=1:frame size; j=1:no of frames;
M(1:f_s, j)=s(((j-1)*overlap)+(1:f_s));
end
Second improvement:
M = s( bsxfun(@plus, (1:f_s).', ((1:no_f)-1)*overlap ) );
Third improvement: replace much of your code with a call to buffer()
  댓글 수: 2
serena dsouza
serena dsouza 2017년 8월 9일
thank you
Jan
Jan 2017년 8월 9일
편집: Jan 2017년 8월 9일
@serena dsouza: Further improvement: Omit the brute celaring header clc; clear all; close all;, which is cargo cult only and wastes a lot of time, when all functions must be imported from the slow hard disk afterwards. See Stephen's comment .

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Measurements and Spatial Audio에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by