Emodel.pm
上传用户:wzkunzhan
上传日期:2022-04-23
资源大小:2618k
文件大小:6k
- # File: Emodel.pm
- #
- # Modified OpenPhone based Voice Evaluation Tool (MOBVET) Version 0.1
- # --------------------------------------------------------------------
- # Voice Over IP Laboratory (http://www.voip.nce.ufrj.br)
- # Federal University of Rio de Janeiro
- # Copyright (c) 2002-2004 UFRJ (Federal University of Rio de Janeiro).
- # The contents of this file are subject to the Mozilla Public License
- # Version 1.0 (the "License"); you may not use this file except in
- # compliance with the License. You may obtain a copy of the License at
- # http://www.mozilla.org/MPL/
- package VoIP::Emodel;
- #Inicializa as variaveis com os valores default
- set_default();
- #****************************
- # Sub set_default
- #****************************
- #Default Parameter Values, according to Tab.3/G.107 (lines 29-60)
- sub set_default
- {
- $SLR = 8;
- $RLR = 2;
- $STMRs = 15;
- $Ds = 3;
- $STMR = 15;
- $Dr = 3;
- $LSTR = 18;
- $TELR = 65;
- $T = 0;
- $WEPL = 110;
- $Tr = 0;
- $Ta = 0;
- $Ie = 0;
- $Bpl = 1;
- $Ppl = 0;
- $A = 0;
- $Nc = -70;
- $Ps = 35;
- $Pr = 35;
- $qdu = 1;
- $Nfor = -64;
- $OLR = $SLR + $RLR;
- $Id = 0;
- $Ieef = 0;
-
- }
- #****************************
- # Sub r
- #****************************
- #Compute R
- sub r
- {
- $Nr1 = 0;
- $Nr2 = 0;
- $Pro = 0;
- $Pr1 = 0;
- $Nfo = 0;
- $No = 0;
- $Nt = 0;
- $Ro = 0;
- $Xolr = 0;
- $Iolr = 0;
- $STMRo = 0;
- $Ist = 0;
- $Q = 0;
- $G = 0;
- $Iq = 0;
- $TERV = 0;
- $Re = 0;
- $Ro = 0;
- $Xdt = 0;
- $Idte = 0;
- $Rle = 0;
- $Idd = 0;
- $X = 0;
- $R = 0;
- $Isyn = 0;
- # Noise Summation, formulas (3) to (7)
- $Nr1 = $Ps - $SLR - $Ds - 100;
- $Nr1 = $Nr1 + 0.004 * ($Ps - $SLR - $Ds - 14) ** 2;
- $LSTR = $STMR + $Dr;
- $Pro = $Pr + 10 * log(1 + 10 ** ((10 - $LSTR) / 10)) / log(10);
- $Pr1 = $Pro + 0.008 * ($Pro - 35)**2;
- $Nr2 = $Pr1 - 121 + $RLR;
- $Nfo = $Nfor + $RLR;
- $No = 10 * log(10**($Nr1 / 10) + 10 ** ($Nr2 / 10) + 10 ** ($Nc / 10) + 10 ** ($Nfo / 10)) / log(10);
- $Nt = $No - $RLR;
-
- # Ro, formula (2)
- $Ro = 15 - 1.5 * ($SLR + $No);
- # Iolr, formulas (9) and (10)
- $Xolr = $SLR + $RLR + 0.2 * (64 + $Nt);
- $Iolr = 20 * ((1 + ($Xolr / 8) ** 8) ** (1 / 8) - $Xolr / 8);
- # Ist, formulas (11) and (12)
- $STMRo = - 10 * log(10 ** (- $STMR / 10) + 10 ** (- $TELR / 10) * exp( - $T / 4)) / log(10);
- $Ist = 10 * (1 + (($STMRo - 12) / 5) ** 6) ** (1 / 6) - 10;
- $Ist = $Ist - 46 * (1 + ($STMRo / 23) ** 10) ** (1 / 10) + 46;
- # Iq, formulas (13) to (17)
- if ($qdu < 1) { $qdu = 1 }
- $Q = 37 - 15 * log($qdu) / log(10);
- $G = 1.07 + 0.258 * $Q + 0.0602 * $Q ** 2;
- $Iq = 15 * log(1 + 10 ** (($Ro - 100) / 15) * 10 ** (46 / 8.4 - $G / 9) + 10 ** (46 / 30 - $G / 40)) / log(10);
-
- # Is, formula (8)
- $Isyn = $Iolr + $Ist + $Iq;
- # TERV, formula (22)
- $TERV = $TELR + 6 * exp(- 0.3 * $T ** 2) - 40 * log((1 + $T / 10) / (1 + $T / 150)) / log(10);
- # Modifications to satisfy formula (23)
- if ($STMR < 9) { $TERV = $TERV + 0.5 * $Ist }
- # Idte, formulas (19) to (21)
- $Re = 80 + 2.5 * ($TERV - 14);
- $Roe = -1.5 * ($No - $RLR);
- $Xdt = ($Roe - $Re) / 2;
- $Idte = $Xdt + sqrt($Xdt ** 2 + 100);
- $Idte = ($Idte - 1) * (1 - exp(- $T));
- # Modifications to satisfy formula (24)
- if ($STMR > 15) { $Idte = sqrt($Idte ** 2 + $Ist ** 2) }
- # Idle, formulas (25) and (26)
- $Rle = 10.5 * ($WEPL + 7) * ($Tr + 1) ** (-1 / 4);
- $Xdl = ($Ro - $Rle) / 2;
- $Idle = $Xdl + sqrt($Xdl ** 2 + 169);
- #Idd, formulas (27) and (28)
- if ($Ta < 100) { $Idd = 0 }
- if ($Ta == 100) { $Idd = 0 }
- if ($Ta > 100)
- {
- $X = (log($Ta / 100)) / log(2);
- $Idd = 25 * ((1 + $X ** 6) ** (1 / 6) - 3 * (1 + ($X / 3) ** 6) ** (1 / 6) + 2);
- }
- # Id
- $Id = $Idte + $Idle + $Idd;
- # Inclusion of packet-loss: Ieef, formula (29)
- $Ieef = $Ie + (95 - $Ie) * ($Ppl / ($Ppl + $Bpl));
- # R, formula (1)
-
- $R = $Ro - $Isyn - $Id - $Ieef + $A;
-
- #Truncando o Valor de R
- $R = int($R * 10 + 0.5) / 10;
- if ($R < 0) {
- $R = 0;
- }
- return $R;
- }
- #****************************
- # Sub gob
- #****************************
- # Compute GOB, formula (B.2)
- sub gob
- {
-
- $R = pop(@_);
- $Z = 0;
- $GOB = 0;
- $Z = ($R - 60) / 16;
- f($Z);
- $GOB = 100 * $F;
- $GOB = int($GOB * 10 + 0.5) / 10;
- return $GOB;
- }
- #****************************
- # Sub pow
- #****************************
- # Compute POW, formula (B.3)
- sub pow
- {
- $Z = 0;
- $POW = 0;
- $F = 0;
- $R = pop(@_);
- $Z = ($R - 45) / 16;
- $F = f($Z);
- $POW = 100 * (1 - $F);
- $POW = int($POW * 10 + 0.5) / 10;
- return $POW;
- }
- #****************************
- # Sub mos
- #****************************
- # Compute MOS, formula (B.4)
- sub mos
- {
- $R = pop(@_);
- $MOS = 0;
- $MOS = 1 + $R * 0.035 + $R * ($R - 60) * (100 - $R) * 7 * 10 ** (-6);
- $MOS = int($MOS * 100 + 0.5) / 100;
- if ($R < 0) { $MOS = 1 }
- if ($MOS < 1) { $MOS = 1 }
- if ($R > 100) { $MOS = 4.5 }
- return $MOS;
- }
- #****************************
- # Sub f
- #****************************
- # Norm Distr F(Z), formula (B.1)
- sub f
- {
-
- $Z = pop(@_);
- $S = 0;
- $N = 0;
- $H = $Z;
- $F = 0;
- do
- {
- $S = $S + $H;
- $H = $H * (-1) * ($Z) ** 2 * (2 * $N + 1) / (($N + 1) * 2 * (2 * $N + 3));
- $N = $N + 1;
- }while ( abs($H) > 10** (-6) );
-
- $S = $S / (sqrt(2 * 3.14159265));
- $F = 0.5 + $S;
- return int($F * 10 ** 5 + 0.5) / 10 ** 5;
-
- }
- sub setSLR { $SLR = pop(@_); $OLR = $SLR + $RLR }
- sub setRLR { $RLR = pop(@_); $OLR = $SLR + $RLR }
- sub setDs { $Ds = pop(@_); }
- sub setSTMR { $STMR = pop(@_); $LSTR = $STMR + $Dr }
- sub setDr { $Dr = pop(@_); $LSTR = $STMR + $Dr }
- sub setTELR { $TELR = pop(@_); }
- sub setT { $T = pop(@_); }
- sub setWEPL { $WEPL = pop(@_); }
- sub setTr { $Tr = pop(@_); }
- sub setTa { $Ta = pop(@_); }
- sub setIe { $Ie = pop(@_); }
- sub setBpl { $Bpl = pop(@_); }
- sub setPpl { $Ppl = 100 * pop(@_); }
- sub setA { $A = pop(@_); }
- sub setNc { $Nc = pop(@_); }
- sub setPs { $Ps = pop(@_); }
- sub setPr { $Pr = pop(@_); }
- sub setqdu { $qdu = pop(@_); }
- sub setNfor { $Nfor = pop(@_); }
- sub getSLR { return $SLR }
- sub getRLR { return $RLR }
- sub getDs { return $Ds }
- sub getSTMR { return $STMR }
- sub getDr { return $Dr }
- sub getTELR { return $TELR }
- sub getT { return $T }
- sub getWEPL { return $WEPL}
- sub getTr { return $Tr}
- sub getTa { return $Ta}
- sub getIe {
- if ($Ie < 100) {
- return $Ie;
- }
- else {
- return 100;
- }
- }
- sub getBpl { return $Bpl }
- sub getPpl { return $Ppl}
- sub getA { return $A }
- sub getNc { return $Nc }
- sub getPs { return $Ps }
- sub getPr { return $Pr }
- sub getqdu { return $qdu }
- sub getNfor { return $Nfor }
- sub getId { return $Id }
- sub getIeef { return $Ieef }
- 1;