Can QBasic (MS Quick Basic) do Log operations? - Page 1
Forum section: electronics / beginners

author: CaptDon
author_rank: Super Contributor
timestamp: March 04, 2025, 07:03:59 pm
content: I should know how to write this and I am dinking around with it. I want to add pairs of numbers expressed as dBm. For instance -5.19 + -1.55 = ?I want to write a loop such asEnter A in dBmEnter B in dBmAnswer =Hit Enter to do more.The math needs to accept numbers both above and below 0 dBm.I am not sure how to do Log in Qbasic or if it even can.I do have a licensed copy of MatLab, perhaps that is the way to go?Thanks for any insight!!!

author: BrianHG
author_rank: Super Contributor
timestamp: March 04, 2025, 07:22:43 pm
content: See here for 'freebasic' compiler commands. They are usually compatible with QBasic:https://www.freebasic.net/wiki/KeyPgLog

author: langwadt
author_rank: Super Contributor
timestamp: March 04, 2025, 07:23:56 pm
content: are you trying to make a joke?

author: CaptDon
author_rank: Super Contributor
timestamp: March 04, 2025, 07:48:36 pm
content: No joke on my part. I have been supplied a hand written list of audio output levels from an active electronic crossover. The list looks like this,Hz Lo Mid Result39 -0.14 -16.2542.9 -0.34 -13.1447.16 -0.67 -10.1651.9 -1.23 -7.4257.0 -2.07 -5.0362.77 -3.40 -3.0069 -5.19 -1.5576 -7.52 -0.5583.55 -10.23 0.0In this example the crossover is set at 50Hz. The ideal design target is 0dBm plus or minus perhaps 1/2 to 1 dB. I have a full list and could convert to .csv or even .xls to perform the math. Or with a simple QBasic program I can finish his hand written list. What is going on of interest here is comparing two electronic crossovers, one of which seems to have a depression in output level from the total system occurring around the crossover points. We are trying to see it as represented by the combination of Lo + Mid expressed as dBm. The numbers I gave are from the relatively 'smooth' crossover. The numbers from the other unit don't look good. We are trying to see 'how bad is bad?'Thanks all!!! Hope this explains it in more detail.

author: magic
author_rank: Super Contributor
timestamp: March 04, 2025, 07:53:24 pm
content: Doesn't F1 open built-in help?A quick search says: log(x) and exp(x). Not sure if there are decimal versions, but you can do the math manually.

author: CaptDon
author_rank: Super Contributor
timestamp: March 04, 2025, 07:59:07 pm
content: It also occurred to me, since both physical crossovers are sitting on his bench I could build a resistor combiner (outputs are XLR with low impedance output stages) and sweep the unit which would also show any additional bumps or dips caused by unequal phase shift through the electronic filters. Hmmm??? Food for thought??

author: langwadt
author_rank: Super Contributor
timestamp: March 04, 2025, 07:59:47 pm
content: Quote from: magic on March 04, 2025, 07:53:24 pmadding dBs with dBs where it the log/exp needed?

author: themadhippy
author_rank: Super Contributor
timestamp: March 04, 2025, 08:37:50 pm
content: Quoteor feed it into something like arta and let that do the donkey work

author: BeBuLamar
author_rank: Super Contributor
timestamp: March 04, 2025, 08:49:58 pm
content: If you're talking about QuickBasic 4.5 for DOS it does. Only Ln but that is enoughLOG function■ ActionReturns the natural logarithm of a numeric expression■ SyntaxLOG(n)■ RemarksThe numeric expression, n, must be greater than zero. The naturallogarithm is the logarithm to the base e. The constant e is approximatelyequal to 2.718282.The LOG function calculates the natural logarithm with single-precisionaccuracy, unless the argument n is a double-precision value. In this caseLOG is calculated with double-precision accuracy.You may calculate base-10 logarithms by dividing the natural logarithm ofthe number by the logarithm of 10. The following FUNCTION calculatesbase-10 logarithms:FUNCTION Log10(X) STATICLog10=LOG(X)/LOG(10.#)END FUNCTION■ ExampleThe following example first prints the value of e and then prints thenatural logarithms of e taken to the first, second, and third powers:PRINT EXP(1),FOR I = 1 TO 3PRINT LOG(EXP(1)^I),NEXT■ Output2.718282 1 2 3

author: BeBuLamar
author_rank: Super Contributor
timestamp: March 04, 2025, 11:16:32 pm
content: Quote from: CaptDon on March 04, 2025, 07:03:59 pm-5.19 + -1.55 = ?So what the answer should be?

author: CaptDon
author_rank: Super Contributor
timestamp: March 05, 2025, 12:28:09 am
content: -3.0dBm + -3.0dBm = 0.0dBm The power adds, similarly +3.0dBm + +3.0dBm = +6.0dBm. So the example -5.19 + -1.55 would probably be an estimated -1.0 or in that ballpark, again the power adds and pushes the sum toward 0dBm or 1 milliwatt at a standardized reference impedance which doesn't have to be 600 ohms or even 50 ohms, it only matters that all data was taken at the same impedance. I'll be up nights now crunching numbers!!!! This is crazy. The crossover with the numbers which appear on paper to make more sense gave the largest deviation when measured using a resistor combiner to combine the balanced outputs of the Lo and Mid sections. It gave a variation that rose 2.8dBm above the reference slightly above the crossover setpoint. The crossover that had a bigger spread at each individual test frequency produced an impressive response through the resistor combiner rising a maximum of only 0.6dBm from reference right at the crossover point!!! Although the numbers showed a higher spread I guess it all makes sense. For instance the unit with the close set of numbers -5.19dBm and -1.55dBm showed a bigger combined deviation from reference than the other unit which showed -12.3dBm and -3.0dBm at the same test frequency. The crossover with the greatest resistor combined deviation was 18dB per octave, The 'better' unit was 24dB per octave and about 1.6X higher purchase price.

author: BeBuLamar
author_rank: Super Contributor
timestamp: March 05, 2025, 01:09:20 am
content: So why do you need the log function?

author: CaptDon
author_rank: Super Contributor
timestamp: March 05, 2025, 02:19:18 am
content: Because you must first convert both dBm numbers to a real power in milliwatts which I think uses antilog, then you can add the milliwatts together in a normal linear fashion, then you convert the milliwatts back to dBm using the log function. You can not simply add dBm to dBm in linear fashion because the numbers are logarithmic. dB or dBm is a more realistic way to relate to SPL Sound Pressure Level.

author: BeBuLamar
author_rank: Super Contributor
timestamp: March 05, 2025, 02:44:37 am
content: So when you talked about Quick Basic you mean the Quick Basic that runs under DOS? If not which version sof Quick Basic do you talked about?

author: BeBuLamar
author_rank: Super Contributor
timestamp: March 05, 2025, 03:04:01 am
content: I think this is itI converted the 2 dBm values to voltage, added them then covert back to dBm.I think you want to add the power and not voltage I can do it too. I just used Excel.

author: BeBuLamar
author_rank: Super Contributor
timestamp: March 05, 2025, 02:02:17 pm
content: I do a new one and the dBm is converted to mW. Add them then convert back to dBm

author: CaptDon
author_rank: Super Contributor
timestamp: March 05, 2025, 02:04:51 pm
content: The online text I found said "Add the two powers together", however your numbers look very close to what I got when I did the sweep with the resistor combiner. Probably within .1dB so I guess the formula works with voltage or power? The final outcome of the system went like this, my friend took out the 18dB/octave crossover and installed a 24dB/octave crossover which included multiband limiters for safety when D.J.'s go nuts on his house system. I suggested the make and model since I had also installed one in my system about two years ago and was very pleased. He said his system didn't seem as punchy with the new crossover (all other processing settings remaining un-touched) I thought the new crossover perhaps had a sag at the crossover point. Turns out his old crossover had a 2.8dB rise in the 63 to 69Hz area. I know that sounds almost undetectable but trained ears listening to familiar music can easily detect that amount of change. A slight diddle on the 31 band EQ should give him what he is used to but we didn't want to start changing things until we understood what change had occurred. Thanks to everyone who offered assistance!!!

author: CaptDon
author_rank: Super Contributor
timestamp: March 05, 2025, 02:15:59 pm
content: Interesting, the spread of the numbers appears much smaller and the -10.23 added to 0.0 should have produced a negative number as opposed to the positive .39 Your first set of numbers using voltage seemed to be in very close alignment with what my dBm meter produced using a resistor combiner to incorporate the Lo+Hi into a single measurable signal which should represent the overall system performance (plus or minus the actual deviation in individual speaker response curves). All of the numbers were taken with a Tektronix DM502 3.5 digit meter set to measure dBm as opposed to dBV with an internal jumper. My assumption was measuring in dBm would more accurately represent the 'system power output' which would be closely related to sound pressure level. I thought measuring in dBV would not be an accurate approach?

author: BeBuLamar
author_rank: Super Contributor
timestamp: March 05, 2025, 02:20:33 pm
content: If you add anything to 0dB would make it greater than 0dB. You don't take anything away from it.

author: themadhippy
author_rank: Super Contributor
timestamp: March 05, 2025, 03:11:08 pm
content: Quoteundetectable? Thats bucket loads.

author: CaptDon
author_rank: Super Contributor
timestamp: March 05, 2025, 06:50:15 pm
content: Bebu, you are correct, don't know how I missed that!

author: BeBuLamar
author_rank: Super Contributor
timestamp: March 05, 2025, 07:17:30 pm
content: But Don I am curious about Qbasic? do you really want to use Qbasic? Do you have it? How do you run it?

author: Zero999
author_rank: Super Contributor
timestamp: March 05, 2025, 08:41:36 pm
content: Why use such an antiquated piece of software such as QBasic or Quick Basic?And which is it? Quick Basic is a compiler and QBasic is just an interpreter which was shipped with MS-DOS and Windows 95/98.https://en.wikipedia.org/w/index.php?title=QBasic&useskin=vectorhttps://en.wikipedia.org/wiki/QuickBASIC?useskin=vector

author: BrianHG
author_rank: Super Contributor
timestamp: March 05, 2025, 10:04:31 pm
content: I would have done it in MS-Excel or LibreOffice spreadsheets.

author: CaptDon
author_rank: Super Contributor
timestamp: March 06, 2025, 01:59:10 am
content: It was the QBasic which shipped with W95 DOS6.0 or possibly newer. I wrote tons of NEMA0182(3) diagnostic software for testing chartplotters and other devices needing particular data strings so I was familiar with the client. I do own a registered legal copy of MatLab so I ended up playing with the numbers in that client. I am still baffled by the fact that when Bebu did the number crunching having converted to voltage mid-step his numbers closely matched my metered results. All of the formulas say convert to power and add and when Bebu did that the numbers were not anywhere close to my real time measurements. My measurements were taken using the dBm mode as opposed to the dBV mode.

author: BeBuLamar
author_rank: Super Contributor
timestamp: March 06, 2025, 02:23:51 am
content: How do you measure the total in dBm. I know you can measure the low and mid dBm separately but how did you measure the combined dBm with a meter?

author: Zero999
author_rank: Super Contributor
timestamp: March 06, 2025, 08:16:50 am
content: Quote from: CaptDon on March 06, 2025, 01:59:10 amTry QB64. It can run most QBasic code unmodified.https://qb64.com/

author: CaptDon
author_rank: Super Contributor
timestamp: March 06, 2025, 04:11:57 pm
content: LO IN Balanced 0----/\/\/\/\/\----0--------/\/\/\/\/\------0 HI IN BalancedR1 \ R3/\R5R2 / R4\0 ---/\/\/\/\/\---0--------/\/\/\/\/\-------0Low output impedance drive circuits.Combined output taken from the ends of R5 and fedto a differential amplifier Tektronix AM502 who's singleended output went to a Tektronix DM502 who's internaldBV/dBm jumper was set to dBm. All resistors 270 ohm.

author: BeBuLamar
author_rank: Super Contributor
timestamp: March 06, 2025, 05:17:11 pm
content: Quote from: CaptDon on March 06, 2025, 04:11:57 pmI see you want to measure the combined power of the Low and Mid output in R5. However what you measured is a voltage and thus I think we should use dBm instead of power.

author: mdijkens
author_rank: Regular Contributor
timestamp: March 06, 2025, 05:27:47 pm
content: Quote from: Zero999 on March 06, 2025, 08:16:50 amqb64.com is not very active anymoreswitch tohttps://qb64phoenix.com/which continued where qb64 stopped

author: mwb1100
author_rank: Frequent Contributor
timestamp: March 06, 2025, 06:02:16 pm
content: Quote from: mdijkens on March 06, 2025, 05:27:47 pmLink to the QB64 Phoenix github:https://github.com/QB64-Phoenix-Edition/QB64peIt was kind of buried in the forum.

author: CaptDon
author_rank: Super Contributor
timestamp: March 06, 2025, 10:34:34 pm
content: I like your emoji with action but you do realize when the switch closes it shorts out the battery???

author: mdijkens
author_rank: Regular Contributor
timestamp: March 07, 2025, 11:58:46 am
content: Yes of course, Best way to shut down a lamp

author: u666sa
author_rank: Frequent Contributor
timestamp: March 07, 2025, 04:01:09 pm
content: Ask chatgpt,In QBASIC, logarithmic operations can be performed using the `LOG` function, which computes the natural logarithm (base e) of a number. If you need to compute logarithms with a different base, you can use the change of base formula:\[\log_b(x) = \frac{\log_e(x)}{\log_e(b)}\]Where:- \( \log_b(x) \) is the logarithm of \( x \) to base \( b \),- \( \log_e(x) \) is the natural logarithm (base e) of \( x \),- \( \log_e(b) \) is the natural logarithm of \( b \).Here's an example of how you can perform logarithmic operations in QBASIC:### Example: Natural Logarithm (Base e)```qbasicCLSDIM num AS SINGLEnum = 10PRINT "Natural Logarithm of "; num; " is "; LOG(num)END```### Example: Logarithm with a Different Base (e.g., Base 10)```qbasicCLSDIM num AS SINGLE, base AS SINGLEnum = 100base = 10PRINT "Logarithm of "; num; " to base "; base; " is "; LOG(num) / LOG(base)END```In this example:- The first program calculates the natural logarithm of `10`.- The second program calculates the logarithm of `100` to base `10` using the change of base formula.Let me know if you need more details or help with QBASIC!

author: u666sa
author_rank: Frequent Contributor
timestamp: March 07, 2025, 04:01:40 pm
content: But that language is 3 decades as dead. Use C++

author: BeBuLamar
author_rank: Super Contributor
timestamp: March 07, 2025, 04:29:45 pm
content: Quote from: u666sa on March 07, 2025, 04:01:40 pmFor the calculations the OP wanted I would use a spreadsheet like Excel. But I just run Quick Basic a minute ago. I don't know if it's dead.

author: mdijkens
author_rank: Regular Contributor
timestamp: March 07, 2025, 05:50:37 pm
content: Quote from: u666sa on March 07, 2025, 04:01:40 pmqb64phoenix is alive and kicking.I've never stopped using Basic for my professional customers applications

author: u666sa
author_rank: Frequent Contributor
timestamp: March 07, 2025, 09:24:12 pm
content: Quote from: mdijkens on March 07, 2025, 05:50:37 pmSomething like Delphi or C++Builder is what you need. Target Linux, Windows and MacOS, plus Android and iPhone, if you using FireMonkey. Rapid Application Development (RAD) IDE allows you to drag and drop your UI within minutes. Very powerful stuff.

author: Zero999
author_rank: Super Contributor
timestamp: March 08, 2025, 07:05:14 pm
content: Quote from: u666sa on March 07, 2025, 09:24:12 pmQuickBasic and QBasic might be antiquated and no longer supported, but there's nothing wrong with BASIC. It's what many people here first learned to code, as it was commonly supplied on most home computers from the late 70s to early 90s.Modern versions of BASIC are fairly comprehensive, can be compiled and run at a decent speed.