faster "log10" command
이전 댓글 표시
Hi all, Is anyone know how to use the "log10" more wisely? currently, I convert from dB to decimal using log10 but it seems to slow down the execution process. Any help would be appreciated!
Ta
[EDITED, 09-12-2011 08:13 UTC, Jan Simon] Code copied from Answer section:
Sorry guys for the late reply, and thanks for the comment. Anyway, my code look like this:
for trial = 1:1000
for a = 1:N
for b=1:N
interfere(b,a) = dBtodec(Pr) * power(dstsr(b,a), -(dBtodec(gamma))))) * ...
Li(b) * Ri(b);
end
%
sinrSUr(a) = dBtodec(Pr) * power(ds(a), -(dBtodec(gamma))))) * ...
LSUr(a) * RSUr(a)) / (dBtodec(No) + sum(interfere(:,a)));
snr(a) = (dBtodec(Pr)*(power(ds(a), (-(dBtodec(gamma))))) * ...
LSUr(a) * RSUr(a)) / (dBtodec(No));
end
end
where dBtodec is a function which is:
function [decimal] = dBtodec(x)
%converting dB to decimal
decimal = 10*log10(x);
end
hope that make sense
댓글 수: 6
Jan
2011년 12월 8일
If you post the relevant part of the code, we could look for other problems.
Jan
2011년 12월 9일
Parenthesis can help to make the code easier to read, e.g. when mixing logical expressions. But "-dBtodec(gamma)" is nicer than "(-(dBtodec(gamma)))".
Jan
2011년 12월 9일
Fangjun has commented the code:
Daniel and Jan are right. You probably don't have pre-allocation. Put the following prior to your for-loops.
interfere=zeros(N);
sinrSUr=zeros(N,1);
snr=zeros(N,1);
Parenthesis imbalance in:
interfere(b,a) = dBtodec(Pr)*power(dstsr(b,a),-(dBtodec(gamma)))))*Li(b)*Ri(b) is not valid.
log() is for Natural logarithm. You need to use log10().
OMG! Your dBtodec() calculation is also wrong!
Jan
2011년 12월 9일
There is no log10 in the posted code?!
Please fix the problems Fangjun has shown. Replace the posted code by the cleaned version by editing the original question.
Ricky
2011년 12월 11일
Jan
2011년 12월 12일
@Rak: You can simply edit your question to fix this.
채택된 답변
추가 답변 (4개)
Daniel Shub
2011년 12월 8일
I am guessing you are not preallocating ...
Does you code look something like:
x = randn(1e7,1);
for ii = 1:length(x)
y(ii) = log10(x(ii));
end
You could replace it with
y = log10(x);
댓글 수: 4
Jan
2011년 12월 8일
I agree and this is exactly the point, why I asked Rak for posting the code.
Daniel Shub
2011년 12월 8일
I think my favorite answers are when we have to guess what the question is: sometimes we get it right and sometimes we miss. Asking for more information not only can improve our accuracy it also gives a hint as to how much the OP cares. That said sometimes I like to ask for more info and sometimes I like to guess.
Jan
2011년 12월 8일
Then I guess, that we will get a speedup of >55% if we apply our experiences on Rak's code. But even then this will *not* be an advantage: Currently Rak has waited 16 hours for the answer! It will be hard to recover this delay even with the fastest code...
Jan
2011년 12월 9일
Damn English. Sometimes I'm too confused. While "I guess" is nonsense here, I meant "I bet". And if I had written this, I'd won. What a pitty.
Daniel Shub
2011년 12월 9일
You may want to look at
doc db2mag
doc mag2db
doc pow2db
doc db2pow
they are not going to speed up your code, but they do the transformations in the correct direction and use the correct log base and scale factors ...
댓글 수: 1
Jan
2011년 12월 9일
See: http://en.wikipedia.org/wiki/Anti-pattern , Do not re-invent the square wheel. +1
Sean de Wolski
2011년 12월 8일
On my system:
A = magic(10000); %Don't do this!
tic,log10(A);toc
Elapsed time is 1.388229 seconds.
1.39 seconds to calculate the log10 of 10000^2 elements seems pretty good, so you probably have something else slowing you down. How much memory are you using?
b = whos;
sum(b(:).bytes)
If you're using more memory than you have RAM available that's quite possibly your issue.
Ricky
2011년 12월 11일
0 개 추천
댓글 수: 2
Ricky
2011년 12월 12일
Daniel Shub
2011년 12월 12일
the best way to thank people is to accept the best answer and vote for the other answers that helped you. This lets future people with similar questions and problems learn what you learned.
카테고리
도움말 센터 및 File Exchange에서 Exponents and Logarithms에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!