February 4th, 2010, 02:24 PM
finding certain data points
The 'find' function is slow, how can I make this faster?
So I have two time bases: n1/44100 and m/48000, where n1 and n2 are integers. n ends at 176400, m ends at 192000.
n2 = n1+1 (for indexing, so its the next one or n2 = n1(i+1), i is the index)
here the timesteps are tx1, tx2, and ty1.
tx1 is the timestep for n1/44100
tx2 is the incremental next timestep for tx1 (one turn of the clock for tx1)
ty1 is the timestep for m/48000
I need to find n1 and n2 so that: n1 <= m < n2,
1) n1 <= m
2) n2 > m
for every m
Presently, I am using the Matlab find function ( find(tx1 <= m(i),1,'last'); ) that finds the last occurance of the timestep that is equal to or less than m, or the closest to m without going over. Then, for the second half, I use find(tx1>ty1,1,'first'); to get the first value of tx2 (basically tx1) that is greater than m. So, using these two functions I have found the surrounding timesteps so that I can interpolate.
My problem lies with the 'find' function. It is VERY slow. It took ~20 minutes to convert a 4-second long .WAV file this way. Using the profiler, it stated that it took 10 minutes on each of the find function uses.
Does anyone know a more efficient way to do this?
I can post my code here if you want, but I'm not a CS major or a good coder, and its ugly as sin (I'm an EE).
Click Here to Expand Forum to Full Width