Stromhau

asked on

Hi, can anybody help me to get this function faster ?

Think the matrix concatenation is the trouble? I also know that a double for i not good.

Takes 8-9 seconds for a 15 seconds sound file.

Think the matrix concatenation is the trouble? I also know that a double for i not good.

Takes 8-9 seconds for a 15 seconds sound file.

```
function p=SDC(signal)
%functions to compute shifted delta cepstral from MFCC,PLP,LPC
%
%Signal is coeff of MFCC
%Author Tommy Strømhaug, 2008
%Hardcoded N, d, P, and k
%d and P considered in frames. N amd k is ints
N=7; % number of c cepstral coefficients in each cepstral vector
d=1; % time advance and delay for the delta computation
P=3; % timeshift netween consecutive blocks
k=7; % number of blocks whose delta coefficients are concatenated to form the SDC vector
[row,col]=size(signal);
sdc=[];
sdc_temp=[];
%Pad data to not get out of bound. circular padding
right=signal(:,col-9:col)
left =signal(:,1:21)
signal=cat(2,signal,left);
signal=cat(2,right,signal);
for t=11:col+10
for i=0:k-1
sdc_temp=signal(:,t+i*P+d)-signal(:,t+i*P-d);
sdc=cat(2,sdc,sdc_temp);
end
end
p=sdc;
```

Last Comment

ASKER

Thank you for your time,

The signal file can easily be genrated , a typically signal file is 13 rows and 5000-10000 coloums. A 13*5000 matrix of doubles is a average signal file.

Tommy,

The signal file can easily be genrated , a typically signal file is 13 rows and 5000-10000 coloums. A 13*5000 matrix of doubles is a average signal file.

Tommy,

I'll try to look more in-depth at the code tomorrow, but remember, you're doing a double "for" loop and these take time. You're performing 65,000 to 130,000 matrix concatenations, maybe more.

I would preliminarily suggest instead of concatenating to vectors that start out small and grow in the loops, try pre-allocating the sdc vector to the desired size like this

sdc = zeros(13, whatever);

before the for loops, where 'whatever' represents the final size of the SDC vector. You should be able to calculate this size beforehand based on the expected values for k, d, etc. Give that a whirl for now. Matlab recommends pre-allocating like this for speed.

Good luck,

Luke

I would preliminarily suggest instead of concatenating to vectors that start out small and grow in the loops, try pre-allocating the sdc vector to the desired size like this

sdc = zeros(13, whatever);

before the for loops, where 'whatever' represents the final size of the SDC vector. You should be able to calculate this size beforehand based on the expected values for k, d, etc. Give that a whirl for now. Matlab recommends pre-allocating like this for speed.

Good luck,

Luke

ASKER

yes, tried vectors and preallocation, but matlab didnt let me preallocate such big numbers.

View this solution by signing up for a free trial.

Members can start a 7-Day free trial and enjoy unlimited access to the platform.

Hi,

This article will help you ,how to write matlab code faster

http://www.mathworks.com/matlabcentral/fileexchange/5685

Thanks, hope this helps

This article will help you ,how to write matlab code faster

http://www.mathworks.com/matlabcentral/fileexchange/5685

Thanks, hope this helps

Programming Languages-Other

A programming language is a formal constructed language designed to communicate instructions to a machine, particularly a computer. Thousands of different programming languages have been created, mainly in the computer field, and many more still are being created every year. The description of a programming language is usually split into the two components of syntax (form) and semantics (meaning). Some languages are defined by a specification document (for example, the C programming language is specified by an ISO Standard), while other languages (such as Perl) have a dominant implementation that is treated as a reference. Some languages have both, with the basic language defined by a standard and extensions taken from the dominant implementation being common.

20K

Questions

--

Followers

--

Top Experts

Get a personalized solution from industry experts

TRUSTED BY

Sometimes loops are necessary even in Matlab... :-)

Since I do not have your signal file I can only look at the code. I would suggest first that you examine your program when you do processing and see exactly what steps are taking time. Once you look at this it may give you some ideas of where to look at speed increases.

To examine your code run Matlab's profiler:

>> profile on %start profiler

>> p=SDC(signal) %run your program

>> profile off %stop profiler

>> profreport %make the profile report. You can see exactly what steps take time and you can click on individual lines to see what inside them takes time

Maybe this can help you fix the problem. If not then I suggest you post some "signal file" to here so that your code can be run.

Good luck.

/Dan