Signal Scaling

Functions for mapping values between ranges and automatic gain control.

pyminidsp.scale(value, oldmin, oldmax, newmin, newmax)[source]

Map a single value from one range to another.

Map a single value from one range to another.

Example: scale(5.0, 0.0, 10.0, 0.0, 100.0) returns 50.0.

pyminidsp.scale_vec(a, oldmin, oldmax, newmin, newmax)[source]

Map every element of a vector from one range to another.

Map every element of a vector from one range to another.

pyminidsp.fit_within_range(a, newmin, newmax)[source]

Fit values within [newmin, newmax].

Fit values within [newmin, newmax]. If all values already fit, they are copied unchanged. Otherwise the entire vector is rescaled.

pyminidsp.adjust_dblevel(signal, dblevel)[source]

Automatic Gain Control: scale signal to target dB level, clip to [-1, 1].

Automatic Gain Control: scale a signal so its power matches the requested dB level, then clip to [-1, 1].