[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Average Magnitude Differential Function - implementation
From: |
John W. Eaton |
Subject: |
Average Magnitude Differential Function - implementation |
Date: |
Wed, 5 May 2010 15:48:08 -0400 |
On 5-May-2010, jacek grabowski wrote:
| s=wavread('/home/jaca/ka.wav');
| w=s(2000:4000);
| N=length(w);
| for k=1:N
| suma=0;
| for n=1:N-k
| suma=suma+abs(w(k)-w(k+n)); % 2 001 000 times for N=2001
| endfor
| amdf(k)=suma;
| endfor
|
| I wolud like to run it from PHP system('octave3.0 -qf amdf.m') but max
| execution time is only 30 s.
| When i run amdf.m direct on shell:
|
| address@hidden:~$ octave3.0 -fq amdf.m
| Elapsed time is 58.2993 seconds.
|
| It's any way to optimize this code?
Octave is an array language, so operations on arrays are generally
faster than explicit looping. Your inner loop is fairly easy to
vectorize:
amdf = zeros (1, N);
for k = 1:N
amdf(k) = sum (abs (w(k) - w(k+1:N)));
endfor
Maybe someone else will have an idea for how to vectorize the
remaining loop.
jwe