help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Zero Crossing Rate - optimize implementation


From: Akira Nishimura
Subject: Re: Zero Crossing Rate - optimize implementation
Date: Sat, 08 May 2010 11:03:34 +0900 (JST)

Nice solution !! 
You can get rid of the for loop !

> zcr = diff(sign(s))~=0;

zcr_rate = sum(reshape(zcr(1:framesize*(FN-1)), framesize, FN-1), 1);
 
> Then you can loop over this to do your summations of frames.  Something
> like:
> index = 1;
> frame_start = 1:framesize:N;
> zcr_rate = zeros(1, length(frame_start));
> for starttime = frame_start,
>    endtime = min(starttime+framesize-1, N);
>    zcr_rate(index) = sum(zcr(starttime:endtime));
>    index = index + 1;
> end

> > s=wavread('sample.wav');
> > N=length(s)
> > framesize=2000;
> > frame_lim=[1:framesize:N-1];
> > FN=length(frame_lim);
> > zcr=zeros(1,FN-1);
> > tic()
> > for i=1:FN-1
> >    for k=frame_lim(1,i):frame_lim(1,i+1)
> >        if sign(s(k)) != sign (s(k+1))
> >         zcr(i)=zcr(i)+1;
> >        endif
> >    endfor
> > endfor
> > toc()
> >
> > N =  236352
> > Elapsed time is 41.39265 seconds.
> >
> > This is my first week with Octave, so forgive me any stupid question ... :)
> > Thank you very much.
> >
> > --
> > Jacek Grabowski

Akira Nishimura, Associate Professor
Department of Media and Cultural Studies
Tokyo University of Information Sciences


reply via email to

[Prev in Thread] Current Thread [Next in Thread]