Reply by Richard Owlett November 2, 20072007-11-02
maxplanck wrote:
> In Scilab, I'm using cat in a for loop to concatenate column matrices > produced by > the for loop. The problem is that since i'm working with audio data, > the matrices are long, and cat takes longer every time the for loop > runs because it's handling more data each time the for loop runs. > > Are there any alternative functions that i could use instead of cat, > which will be faster? Perhaps a function that stores a matrix in a > buffer, and when adding elements to that matrix it doesn't have to > process the data that's already in the matrix (i.e. already in the > buffer)? > > Thanks, any help would be much appreciated. > > Here's my code so far, which takes way too long to run when H1.txt > contains around a second or more of audio data @ 44100 samples/second. > > stacksize(99999999); > signal=fscanfMat('/H1.txt');
Insert the line envelope=zeros(signal); This initializes the array "envelope" to its final size. Scilab does not _require_ declaring/dimensioning an array before use which allows us to be a little sloppy. But it requires Scilab to keep moving the array to a larger chunk of memory. On each each iteration, it has to move more more and mmoorree and mmmooorrreee data. Got bit by that one when built a 2 dimensional array row by row. I don't think "cat" is the problem.
> slope_signal=diff(signal); > tt = find( (slope_signal(1:$-1).*slope_signal(2:$))<= 0 ); > envelope=abs(signal(tt)); > > for i=1:(length(envelope)-1), > > if i == 1 then > linenvelope = linspace(envelope(i), envelope(i+1), > tt(i+1)-tt(i))'; > else > linenvelope = cat(1,linenvelope,(linspace(envelope(i), > envelope(i > +1), tt(i+1)-tt(i))')); > end > > end
Reply by maxplanck November 2, 20072007-11-02
In Scilab, I'm using cat in a for loop to concatenate column matrices
produced by
the for loop.  The problem is that since i'm working with audio data,
the matrices are long, and cat takes longer every time the for loop
runs because it's handling more data each time the for loop runs.

Are there any alternative functions that i could use instead of cat,
which will be faster?  Perhaps a function that stores a matrix in a
buffer, and when adding elements to that matrix it doesn't have to
process the data that's already in the matrix (i.e. already in the
buffer)?

Thanks, any help would be much appreciated.

Here's my code so far, which takes way too long to run when H1.txt
contains around a second or more of audio data @ 44100 samples/second.

stacksize(99999999);
signal=fscanfMat('/H1.txt');
slope_signal=diff(signal);
tt = find( (slope_signal(1:$-1).*slope_signal(2:$))<= 0 );
envelope=abs(signal(tt));

for i=1:(length(envelope)-1),

        if i == 1 then
                linenvelope = linspace(envelope(i), envelope(i+1),
tt(i+1)-tt(i))';
        else
                linenvelope = cat(1,linenvelope,(linspace(envelope(i),
envelope(i
+1), tt(i+1)-tt(i))'));
        end

end