Log function

How do i write a code to convert watt to dBm and vice versa?
1o log(w) + 30 = dBm

Thanks!

One way...

$ cat calc
#! /usr/bin/ksh
bc -l |&
print -p scale=6
while read watt?"enter watt -->  "; do
        print -p "l($watt)/l(10)*10+30"
        read -p dbm
        echo "watt = $watt     dbm = $dbm"
done
echo
exit 0
$ ./calc
enter watt -->  .835
watt = .835     dbm = 29.216870
enter watt -->  1.002
watt = 1.002     dbm = 30.008670
enter watt -->

Unfortunately, it does not work. I am basically looking for the log formula in UNIX. I have already tried a few such as:double log(double x), log(x) etc., but none seems to work.
Hope that helps.
Thanks for replying.

The "log(x)" function is available in (n)awk

Yes it does. It works perfectly. I tested it and I show the test results in my post. The first example .835 watts does indeed equal 29.216870 dbm. You can verify that on this page. That page uses milliwatts so look for 835 and see what value they calculated. If you still think my script is not correct, please provide an example of something it did wrong.

I am not saying your script is wrong. I just cannot get it to work. everytime I try to run it, i keep getting error messages saying i.e. watt not found. Maybe I am doing something wrong. Remember i am new to unix. i do not know my way around yet to make things work. Below is what I wrote:

[COLOR=Navy]echo "x is a positive integer"
echo "Enter x"
read x
expr double log(log(x))
assuming you enter 5 when asked to enter the value of x, the value in dB should be displayed on the screen.

My expr formula is not working. I am looking for a simple formula that works. Thanks for the help!

Put my script in a file called calc in your current directory. Do a "chmod u+x calc" to make the file executable. Then do "./calc" to run it.

Thanks! It is working fine

What is the format (formula) for the awk function. I am not familiar with it.

It works. Now I need to understand the script itself. Would you mind explaining to me the meaning of each line.

Thanks for the help!

you can use awk too..it has a log function

watt=0.9
awk -v wat=$watt 'BEGIN { print 10*log(wat) + 30 }'

How can I modify the script below to convert from dBM to watt instead of watt to dBm?

#! /usr/bin/ksh
bc -l |&
print -p scale=6
echo "This is a program designed to convert watt to dbm"
while read watt?"enter watt: "; do
print -p "l($watt)/l(10)*10+30"
read -p dbm
echo "watt = $watt dbm = $dbm"
done
echo
exit 0

what would the 'backwards' conversion formula? (I'm lazy doing the math myself)

mW = 10dBm/10

mW = 10dBm/10
mW = dBm(10/10)
mW = dBm

In other words, multiplying a number by 10 and then dividing the result by 10 results in the original number. :wink:

So, using an alternate formula...

$ cat calc2
#! /usr/bin/ksh
bc -l |&
print -p scale=6


while read dbm?"enter dBm -->  "; do
        print -p  "e(($dbm-30)*l(10)/10)"
        read -p watt
        echo "dBm = $dbm     watt = $watt"
done
echo
exit 0
$ ./calc2
enter dBm -->  29.216870
dBm = 29.216870     watt = .835001
enter dBm -->  30.008670
dBm = 30.008670     watt = 1.001997
enter dBm -->

nawk 'BEGIN { w = 0.1; print 10*log(w) + 30 }'

I have a function check_ok in my abc.sh. which return me 1 or 0 . I want to call this fuction through other shell script. this shell also send two parameter to calling function.
Can you please tell me how. I am very new in unix.

#!/bin/bash

date_equal()
{

sqlplus -silent rep/qpalwo@cbi <<END
set pagesize 0 feedback off verify off heading off echo off serverout on size 100000
DECLARE
date1 DATE:=NULL;
date2 DATE:=NULL;
BEGIN
DBMS_OUTPUT.enable(100000);
select hdsg.HLD_DI_SRC_GRP_DATE into date_1 from di_hold.HOLD_DI_SRC_GRP hdsg where hdsg.HLD_DI_SRC_GRP_NAME = $1;

select hdsg.HLD_DI_SRC_GRP_DATE into date_2 from di_hold.HOLD_DI_SRC_GRP hdsg where hdsg.HLD_DI_SRC_GRP_NAME = $2;

select trunc(sysdate) into current_date from dual;
IF current_date = date_1 and current_date = date_2
THEN
DBMS_OUTPUT.put_line('1');
ELSE
DBMS_OUTPUT.put_line('0');
END IF;
END;
/
exit;
END

First thing is please open a new thread for your new request.

You can invoke the "abc.sh" from your other shell script like:
abc.sh arg1 arg2

In you abc.sh, make your function use these arguments as $1,$2 ... and return 1 or 0.