Parameter Smoother
Libraries:
DSP System Toolbox /
Signal Operations
Description
The Parameter Smoother block gradually updates the input filter parameters until the parameters reach the desired values. The block uses a first-order IIR filter to smooth the parameter. For more information, see Parameter Smoothing.
Examples
Vary Smoothing Time of Gain in Audio Signal
Vary the smoothing time in the Parameter Smoother block and note the smoothing behavior of the parameter in the time scope. The parameter in this example amplifies the audio signal and you can listen to the changes in the audio using the Audio Device Writer block.
Open the parameter_smoothing_time.slx
model. The input audio signal has two channels and has a sample rate of 44.1 kHz. The signal is amplified by an amplifying parameter. You can set the value of this parameter between 0 and 25 using a slider. When you change the parameter value, the Parameter Smoother block smooths the parameter based on the Smoothing time constant (seconds) you specify in the block dialog box. In the model, the first Parameter Smoother block uses a smoothing time constant of 2 seconds, while the second Parameter Smoother block uses a smoothing time constant of 0 seconds.
Run the model and change the parameter value around half way through the simulation by setting it to a value between 5 and 20. The smoothed parameter gradually changes without causing any abrupt changes in the quality of the audio signal. However, the parameter with a smoothing time constant of 0 seconds changes abruptly.
Smooth Tunable Center Frequency of IIR Notch Filter Using Smoothing Factor
Vary the center frequency of the IIR notch filter. Smooth the center frequency value using the Parameter Smoother block. Note the smoothing behavior of the parameter in the Time Scope when you vary the smoothing factor.
Open the notchFilter_smoothingFactor.slx
model. The input is a noisy sinusoidal signal with a frequency of 2 kHz, sample rate of 44.1 kHz, and contains 1024 samples per frame. Pass this signal through a Notch-Peak Filter block. The block outputs the Notch
filter output and accepts the filter center frequency through the input port Fc. The Sample rate mode parameter of the block is set to Use normalized frequency (0 to 1)
. This setting enables the block to accept frequency specifications in normalized units.
Vary the center frequency of the notch between 0.1 and 0.8 using the slider. Smooth the variation of the center frequency using the Parameter Smoother block. When the smoothing factor is 0, no smoothing occurs and the parameter changes abruptly. As the smoothing factor approaches 1, smoothing increases and the parameter changes gradually.
Run the model. The center frequency is 0.1. The frequency tone of the sinusoidal signal falls in the notch of the filter attenuating the signal.
When you change the center frequency to 0.8, with a sample rate of 44.1 kHz, the center of the notch moves to 17.64 kHz and the tone is unaffected.
Vary the smoothing factor between 0.1 and 0.9 and notice the time it takes for the center frequency to change to the new value in each of these cases.
When alpha is 0.1, the parameter takes less than 0.1 seconds to change to its new value.
When alpha is 0.9, the parameter takes around 1 second to change to its new value. This is because a higher smoothing factor changes the parameter more gradually.
Ports
Input
P — Input parameter to smooth
scalar | vector | matrix
Specify the input parameters to smooth as a scalar, vector, or a matrix. If the value of Number of parameters is greater than 1, then the block labels the input ports as P1, P2, and so on.
This port is unnamed until you select the Specify smoothing factor from input port or Specify smoothing time from input port parameters or you set Number of parameters to a value greater than 1.
Data Types: single
| double
alpha — Smoothing factor
scalar in the range [0, 1)
Specify the smoothing factor α as a scalar in the range [0, 1). When α = 0, the block does not smooth the parameters. As α approaches 1, smoothing and therefore the number of redesigns increase. For more information on the effect of α on smoothing, see Parameter Smoothing.
Dependencies
To enable this port:
Set the Smoothing mode parameter to
Smoothing factor
.Select the Specify smoothing factor from input port parameter.
Data Types: single
| double
tau — Smoothing time
nonnegative scalar
Specify the smoothing time τ in seconds as a nonnegative
scalar. This value indicates the time it takes for the parameter to change to
exp
(−T/τ)×current value +
(1−exp
(−T/τ))×target
value, where T is the value you specify in the Sample
time (−1 for inherited) parameter. For more information on the effect of
τ on smoothing, see Parameter Smoothing.
Dependencies
To enable this port:
Set the Smoothing mode parameter to
Smoothing time
.Select the Specify smoothing time from input port parameter.
Data Types: single
| double
Output
Output — Smoothed parameter
scalar | vector | matrix
Smoothed value of the parameter, returned as a scalar, vector, or a matrix. This is the instantaneous value of the parameter and it changes until the parameter reaches the target value that you specify at the input port P.
Data Types: single
| double
Parameters
To edit block parameters interactively, use the Property Inspector. From the Simulink® Toolstrip, on the Simulation tab, in the Prepare gallery, select Property Inspector.
Number of parameters — Number of input parameters
1
(default) | positive integer
Specify the number of parameters to smooth as a positive integer. The value of this parameter determines the number of inputs ports on the block.
Smoothing mode — Mode to use for smoothing
Smoothing factor
(default) | Smoothing time
Specify the mode to use for smoothing as one of these:
Smoothing factor
–– Specify the smoothing factor in the block dialog box or through the alpha port.Smoothing time
–– Specify the smoothing time in the block dialog box or through the tau port.
For more information on these two modes, see Parameter Smoothing.
Specify smoothing factor from input port — Option to specify smoothing factor from input port
off
(default) |
on
Select this parameter to specify the smoothing factor from the input port alpha. When you clear this parameter, you can specify the smoothing factor in the block dialog box using the Smoothing factor (between 0 and 1) parameter.
Dependencies
To enable this parameter, set the Smoothing mode parameter to
Smoothing factor
.
Smoothing factor (between 0 and 1) — Smoothing factor
0.6
(default) | scalar in the range [0, 1)
Specify the smoothing factor α as a scalar in the range [0, 1). When α = 0, the block does not smooth the parameters. As α approaches 1, smoothing and therefore the number of redesigns increase. For more information on the effect of α on smoothing, see Parameter Smoothing.
Tunable: Yes
Dependencies
To enable this parameter:
Set the Smoothing mode parameter to
Smoothing factor
.Clear the Specify smoothing factor from input port parameter.
Data Types: single
| double
Specify smoothing time from input port — Option to specify smoothing time from input port
off
(default) |
on
Select this parameter to specify the smoothing time from the input port tau. When you clear this parameter, you can specify the smoothing time in the block dialog box using the Smoothing time constant (seconds) parameter.
Dependencies
To enable this parameter, set the Smoothing mode parameter to
Smoothing time
.
Smoothing time constant (seconds) — Smoothing time in seconds
10
(default) | nonnegative scalar
Specify the smoothing time τ in seconds as a nonnegative scalar.
This value indicates the time it takes for the parameter to change to
exp
(−T/τ)×current value +
(1−exp
(−T/τ))×target value,
where T is the value you specify in the Sample time (−1 for
inherited) parameter. For more information on the effect of
τ on smoothing, see Parameter Smoothing.
Tunable: Yes
Dependencies
To enable this parameter:
Set the Smoothing mode parameter to
Smoothing time
.Clear the Specify smoothing time from input port parameter.
Data Types: single
| double
Sample time (−1 for inherited) — Sample time of input parameters
-1
(default) | positive scalar
Specify the sample time of the input parameters T as
-1
(for inherited) or a positive scalar in seconds. This value
determines the frequency with which the block updates the instantaneous values of the
input parameters until the target value is reached.
Dependencies
To enable this parameter, set the Smoothing mode parameter to
Smoothing time
.
Data Types: single
| double
Simulate using — Type of simulation to run
Interpreted execution
(default) | Code generation
Specify the type of simulation to run. You can set this parameter to:
Interpreted execution
–– Simulate model using the MATLAB® interpreter. This option shortens startup time.Code generation
–– Simulate model using generated C code. The first time you run a simulation, Simulink generates C code for the block. The C code is reused for subsequent simulations as long as the model does not change. This option requires additional startup time but provides faster subsequent simulations.
Block Characteristics
Data Types |
|
Direct Feedthrough |
|
Multidimensional Signals |
|
Variable-Size Signals |
|
Zero-Crossing Detection |
|
More About
Parameter Smoothing
Parameter smoothing gradually changes the values of parameters until the desired value is reached.
The algorithm uses a first-order IIR filter to smooth the parameter.
where:
g[n] is the instantaneous value of the parameter.
t[n] is the target value of the parameter.
α is the smoothing factor. When α = 0, the algorithm does not smooth the parameters. As α approaches 1, smoothing and therefore the number of redesigns increase.
Effect of α on Parameter Smoothing
Assume that the initial current value of the parameter g[0] is 0 and the target value t[n] is 1.
Here is the progression of the smoothed parameter using these values.
g[1] = 1−α
g[2] = 1−α2
g[3] = 1−α3
g[n] = 1−αn
Smoothing can also be expressed in terms of time by expressing α as exp
(−nT/τ), where T is the sample time of the parameter (in seconds) and τ is the smoothing time (in seconds).
Effect of τ on Parameter Smoothing
Assume that the initial current value of the parameter g[0] is 0 and the target value t[n] is 1. Also, assume that T divides τ perfectly.
Here is the progression of the smoothed parameter using these values.
In one time constant τ seconds, g[1] =
1−exp
(−1) = 0.6321, the parameter reaches 63.21% of the target
value.
In two time constants, g[2] = 1−exp
(−2) = 0.8647,
the parameter reaches 86.47 % of the target value.
In three time constants, g[3] = 1−exp
(−3) =
0.9502, the parameter reaches approximately 95% of the target value.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
Version History
Introduced in R2024a
Comando de MATLAB
Ha hecho clic en un enlace que corresponde a este comando de MATLAB:
Ejecute el comando introduciéndolo en la ventana de comandos de MATLAB. Los navegadores web no admiten comandos de MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)