help-octave
[Top][All Lists]
Advanced

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

Re: Average Magnitude Differential Function - implementation


From: Thomas D. Dean
Subject: Re: Average Magnitude Differential Function - implementation
Date: Wed, 05 May 2010 15:59:13 -0700

On Wed, 2010-05-05 at 17:06 -0500, Jordi GutiƩrrez Hermoso wrote:
>   [a,b] = meshgrid(w,w);
>   amdf = sum(tril(abs(a-b))));
> 
> 
I tried all three, The combination of an outter loop and sum(abs seems
about 3x faster than meshgrid sum/tril.

The mat s read from the file is 1687552 x 2.  Is it technically an error
to return s(n:m,1) when indexed as s(n:m) ??  This IS sloppy code on my
part...

> doit
filename = /home/tomdean/Radio/Wave/CaptureTahuya3_090407_224446.wav
Read file in 0.381936 seconds, sample 16276 Hz, 16 bits.
Size s 1687552, 2
Loop Calculation in 29.308255 seconds.
Inner Loop matricized 0.071585 seconds.   ## new word????
Matrix Calculation in 0.214732 seconds.
octave:18> max(abs(amdf-amdg))
ans =  1.2079e-12
octave:19> max(abs(amdf-amdh))
ans =  1.2079e-12
octave:20> max(abs(amdg-amdh))
ans = 0

===== file doit.m ===============
1;
tic();
filename='/home/tomdean/Radio/Wave/CaptureTahuya3_090407_224446.wav'
[s, fs, bits]=wavread(filename);
read_time=toc();
printf("Read file in %f seconds, sample %d Hz, %d bits.\n",
       read_time, fs, bits);
printf("Size s %d, %d\n",size(s))

tic();
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
loop_time=toc();
printf("Loop Calculation in %f seconds.\n", loop_time);

tic()
amdg = zeros (1, N);
for k = 1:N
  amdg(k) = sum (abs (w(k) - w(k+1:N)));
endfor
inner_loop=toc();
printf("Inner Loop matricized %f seconds.\n",inner_loop);

tic();
  [a,b] = meshgrid(w,w);
  amdh = sum(tril(abs(a-b)));
matrix_calc = toc();
printf("Matrix Calculation in %f seconds.\n",matrix_calc);




reply via email to

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