summaryrefslogtreecommitdiff
path: root/macros/pow2db.sci
blob: 5be09410a4f497bb37505e1969fda8c8df761060 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//POW2DB   Power to dB conversion
//YDB = POW2DB(Y) convert the data Y into its corresponding dB value YDB
//Example:
//Calculate ratio of 2000W to 2W in decibels
//y1 = pow2db(2000/2)     //Answer in db
//Author : Debdeep Dey
function [ydb]=pow2db(y)
rhs = argn(2)
if(rhs~=1)
error("Wrong number of input arguments.")
end
[r,c]=size(y);
if (find(real(y(:))<0))==[] then
    if abs(y(:))>=0 then
     for i=1:r
            for j=1:c
                if abs(y(i,j))>0 then
                    ydb(i,j)=10*log10(y(i,j));
                else 
                    ydb(i,j)=-%inf;
                end
            end 
        end

    
    end
else
        error("The power value must be non-negative")
end

endfunction