LESSON 36 OF 52 · CHAPTER 04

Root Mean Square

Stable rms on signals and visible vector windows

ORIGINAL SOURCE

12-root-mean-square.srp

// RMS measures signal magnitude per sample without changing its inputs.
bind balanced = [2.0, -2.0, 2.0, -2.0];
print("balanced", rms(balanced));

// The values at either edge are excluded from the selected window.
bind samples = [99.0, 3.0, 4.0, 0.0, 0.0, 99.0];
bind selected = window(samples, 1, 4);
print("window", rms(selected));

// Scaling avoids directly squaring a huge finite value.
print("finite", rms([1e308, -1e308]) == 1e308);
print("zero", rms([0.0, -0.0]));
EXPECTED OUTPUT

stdout

Verified
balanced 2.0
window 2.5
finite true
zero 0.0

UNDERSTAND THE CODE

Explanation & practice

What this example teaches

Stable rms on signals and visible vector windows

Expected behavior

balanced 2.0, window 2.5, finite true, zero 0.0

Practice: Read the source before looking at the output. Predict the values and their order, then use the pinned compiler to execute this lesson and compare the exact fixture. Identify which operation produces the result.

मूल-माध्य-वर्ग (RMS)

rms(values) संख्यात्मक वेक्टर के वर्गों का औसत लेकर उसका वर्गमूल निकालता है। [2.0, -2.0, 2.0, -2.0] का RMS 2.0 है। window से [3.0, 4.0, 0.0, 0.0] चुनने पर RMS 2.5 आता है। बहुत बड़े सीमित फ्लोट मानों पर गणना स्थिर रखी जाती है; खाली वेक्टर पर रनटाइम त्रुटि आती है। इस पाठ के लिए Scarp v0.0.6-alpha.1 चाहिए।

आउटपुट: balanced 2.0, window 2.5, finite true और zero 0.0।

अभ्यास: चार मानों के वर्ग जोड़कर चार से भाग दें, फिर वर्गमूल निकालें। यह norm से कैसे अलग है?

Explanations are sourced from the project's English chapter guide and हिन्दी अध्याय. The Scarp program and output are unchanged.

TRY IT LOCALLY

Verify, then execute

Use the pinned compiler from the course root. Keep any imported _support files next to the source.

scarp verify examples/04-collections/12-root-mean-square.srp scarp exec examples/04-collections/12-root-mean-square.srp

The website does not run code. Read the CLI guide ↗

CHAPTER 04 · LAST LESSON

Ready for your next step? · आगे क्या सीखें?

This is the final example in this chapter. Try its verified coding lab before moving on. Your lesson progress changes only when you mark a lesson complete.

Pinned compiler: Scarp v0.0.6-alpha.3 · ceff07d9014f. No simulated output.