1clear;
2pack;
3%
4% Enter the path to YOUR executable and remember to define the perprocessor
5% variable PRINT_MIPS te get the instructions printed to the screen.
6%
7command = '!iLBCtest.exe 30 speechAndBGnoise.pcm out1.bit out1.pcm tlm10_30ms.dat';
8cout=' > st.txt';   %saves to matlab variable 'st'
9eval(strcat(command,cout));
10if(length(cout)>3)
11    load st.txt
12else
13    disp('No cout file to load')
14end
15
16% initialize vector to zero
17index = find(st(1:end,1)==-1);
18indexnonzero = find(st(1:end,1)>0);
19frames = length(index)-indexnonzero(1)+1;
20start = indexnonzero(1) - 1;
21functionOrder=max(st(:,2));
22new=zeros(frames,functionOrder);
23
24for i = 1:frames,
25    for j = index(start-1+i)+1:(index(start+i)-1),
26        new(i,st(j,2)) = new(i,st(j,2)) + st(j,1);
27    end
28end
29
30result=zeros(functionOrder,3);
31for i=1:functionOrder
32    nonzeroelements = find(new(1:end,i)>0);
33    result(i,1)=i;
34    
35    % Compute each function's mean complexity
36    % result(i,2)=(sum(new(nonzeroelements,i))/(length(nonzeroelements)*0.03))/1000000;
37    
38    % Compute each function's maximum complexity in encoding
39    % and decoding respectively and then add it together:
40    % result(i,3)=(max(new(1:end,i))/0.03)/1000000;
41    result(i,3)=(max(new(1:size(new,1)/2,i))/0.03)/1000000 + (max(new(size(new,1)/2+1:end,i))/0.03)/1000000;
42end
43
44result
45
46% Compute maximum complexity for a single frame (enc/dec separately and together)
47maxEncComplexityInAFrame = (max(sum(new(1:size(new,1)/2,:),2))/0.03)/1000000
48maxDecComplexityInAFrame = (max(sum(new(size(new,1)/2+1:end,:),2))/0.03)/1000000
49totalComplexity = maxEncComplexityInAFrame + maxDecComplexityInAFrame