Test and measurement
Octave Bands <smart-octave-bands>
OctaveBands displays the level in each octave or third-octave band as a bar, with the frequency-weighted overall level and a limit curve the bands are checked against: the display of a sound level meter and of a vibration survey.
<smart-octave-bands> · 19 properties, 7 methods, 2 events · source/modules/smart.octavebands.js
Usage in Blazor
The Razor component is <OctaveBands> in Smart.Blazor.Industrial: every property is a parameter in PascalCase, every event an EventCallback<Event> named On<Event> whose ev["Detail"] is the typed detail class, and the methods are called on the @ref. String choices are enums. In a Blazor Web App (.NET 8 and later) the page needs an interactive render mode, for example @rendermode InteractiveServer; a statically rendered component stays empty.
@using Smart.Blazor.Industrial
@* .NET 8 and later: an interactive render mode, on the page or for the whole app *@
@rendermode InteractiveServer
<OctaveBands @ref="octaveBands" Resolution="octave"
OnLevelsChange="OnLevelsChange" />
@code {
OctaveBands octaveBands;
void OnLevelsChange(Event ev)
{
OctaveBandsLevelsChangeEventDetail detail = ev["Detail"];
}
// Task<bool> Push(object block)
void Call() => octaveBands.Push(new { });
}
Properties
| Parameter | Type, default | Description |
|---|---|---|
Resolution | OctaveBandsResolution | Sets or retrieves the band width: whole octaves or third octaves. |
SampleRate | int | Sets or retrieves the sample rate of pushed blocks, in samples per second. A band is shown only when all of it lies below half the sample rate. A value that is not a positive number analyses nothing: push() returns false, the header says so, and one console warning names the value; assigned levels are still shown. |
Size | int | Sets or retrieves the FFT size a pushed block is analysed with. 0 uses the block's own length. Held to 16,777,216 at most. |
FrequencyMin | double | Sets or retrieves the centre frequency of the lowest band shown. Set above frequencyMax, the two are swapped, with one console warning, rather than leaving the chart empty. |
FrequencyMax | double | Sets or retrieves the centre frequency of the highest band shown. Bands whose upper edge lies above half the sample rate are not shown whatever this says: at a sample rate of 8 kHz the 4 kHz third-octave band, which runs to 4.49 kHz, would be summed from the bins that exist and read low. |
Weighting | OctaveBandsWeighting | Sets or retrieves the frequency weighting applied to each band and to the overall level: Z (none), A or C, per IEC 61672. |
Reference | double | Sets or retrieves what reads as 0 dB: 1 for dB re one unit of the signal, 0.00002 for dB SPL of a signal in pascal. |
Unit | string | Sets or retrieves the signal's unit, so a level reads dBV or, with the 20 µPa reference, dB SPL. |
Averaging | OctaveBandsAveraging | Sets or retrieves the exponential time weighting of the bars: none, fast (125 ms) or slow (1 s), as a meter's. |
PeakHold | bool | Keeps the highest level of each band as a marker. |
Levels | IEnumerable<object> | Sets or retrieves the level of each band in dB, in the order of bands(). Assigned by an application with its own filter bank, or computed by push. |
Limit | IEnumerable<object> | Sets or retrieves the limit the bands are checked against: a level per band in dB, or [{ frequency, level }] points interpolated across the bands on the log axis. A band above its limit is drawn in the exceeded colour and counted in the header. A null or non-numeric per-band value is no limit for that band; a point that is not an object with a frequency and a level is skipped. Either is said once in a console warning. |
LevelMin | double | Sets or retrieves the bottom of the level axis in dB. Null follows the data. With levelMax set below it, the two are swapped; set equal, the axis follows the data. Either is said once in a console warning. |
LevelMax | double | Sets or retrieves the top of the level axis in dB. Null follows the data. Fixes the axis together with levelMin. |
ShowOverall | bool | Shows the overall level in the header. |
ShowGrid | bool | Shows the grid lines at the level ticks. |
Paused | bool | Drops pushed blocks while set. |
Label | string | Sets or retrieves the title shown in the header and used in the accessible name. |
PrecisionDigits | int | Sets or retrieves the number of decimals in levels, held to 0 to 20. |
Methods
| Method | Description |
|---|---|
Task<bool> Push(object block) | Analyses a block of samples into band levels and shows them, with averaging and peak hold applied. Samples that are not numbers are analysed as zeros, and never passed off as clean: the header shows how many, levelsChange carries the count, and the console says so once per run of such blocks. Returns false, and analyses nothing, when the analyser is paused, when Smart.DSP is not loaded, when the block is not an array of at least two samples or has no number in it, or when the sample rate is not a positive number.block any The samples, as an array or a typed array. |
Task<IEnumerable<object>> Bands() | Returns the bands shown: [{ centre, low, high, label, index }], centres on the IEC 61260 base-10 series, between frequencyMin and frequencyMax, and only bands whose upper edge lies below half the sample rate. |
Task<int> Overall() | Returns the overall level: the levels of the bands summed on energy, in dB, or NaN with no levels. |
void Clear() | Clears the levels and the peaks. |
void ResetPeaks() | Drops the held peaks. |
Task<string> Describe() | Returns a sentence describing what the analyser shows, as used in its accessible name: the bands, the overall level, the highest band and the number above the limit (exceededSummaryOne for one). |
void Invalidate() | Redraws the plot on the next animation frame, so that many changes between two frames cost one draw. |
Events
Every event is an EventCallback<Event>; Event is a dictionary and ev["Detail"] converts to the detail class named under the event.
| Event | Description and detail |
|---|---|
OnLevelsChange | This event is triggered after a pushed block has been analysed.Levels IEnumerable<double> The level of each band, in dB.Overall double The overall level, in dB.InvalidSamples string How many samples of the block were not numbers and were analysed as zeros; 0 for a clean block. |
OnBandClick | This event is triggered when a band is clicked.Index int The band.Centre double Its centre frequency.Label string Its nominal frequency.Level double Its level.Peak double Its held peak. |
Types
enum OctaveBandsResolution
OctaveBandsResolution.Octave OctaveBandsResolution.Third
enum OctaveBandsWeighting
OctaveBandsWeighting.Z OctaveBandsWeighting.A OctaveBandsWeighting.C
enum OctaveBandsAveraging
OctaveBandsAveraging.None OctaveBandsAveraging.Fast OctaveBandsAveraging.Slow
CSS variables
The component declares 4 CSS variables; the CSS page shows how to set them.
--smart-octave-height --smart-octave-plot-background --smart-octave-grid-color --smart-octave-axis-color