# BandLimitedWhiteNoise

block BandLimitedWhiteNoise "Noise generator to produce band-limited white noise with normal distribution" import distribution = Modelica.Math.Distributions.Normal.quantile; extends Modelica.Blocks.Interfaces.PartialNoise; parameter Real noisePower = 1 "Power of white noise signal" annotation (Dialog(enable = enableNoise)); protected parameter Real mu = 0; parameter Real sigma = sqrt(noisePower / samplePeriod); initial equation r = distribution(r_raw, mu, sigma); equation when generateNoise and sample(startTime, samplePeriod) then r = distribution(r_raw, mu, sigma); end when; annotation ( Dialog(enable = enableNoise), Icon(graphics = { Text( extent = { {-70, 96}, {92, 60}}, lineColor = {175, 175, 175}, textString = "%noisePower"), Text( extent = { {-96, 11}, {96, -11}}, lineColor = {175, 175, 175}, origin = {-87, 0}, rotation = 90, textString = "white noise")}), Documentation(info = "<html>\n<p>\nA summary of the common properties of the noise blocks is provided in the documentation of package\n<a href=\"modelica://Modelica.Blocks.Noise\">Blocks.Noise</a>.\nThis BandLimitedWhiteNoise block generates reproducible, random noise at its output according to a\nband-limited white noise distribution. This is performed by using a normal distribution with mu=0 and\nsigma = sqrt(noisePower/samplePeriod).\n</p>\n\n<p>\nIn order for this block to produce meaningful results, you should set the following\nparameters:\n</p>\n\n<ul>\n<li> The <strong>samplePeriod</strong> of the block should be much faster (say by a factor of 100)\n than the fastest dynamics of the system fed by the block's outputs.</li>\n<li> The <strong>noisePower</strong> of the signal should be set to the expected power per frequency\n of the white noise. Since many system models assume a noise power of 1,\n this preset may be a reasonable first choice (= default).</li>\n</ul>\n\n<h4>About sampling frequencies</h4>\n\n<p>\nIdeal white noise contains all frequencies, including infinitely high ones.\nHowever, these usually cannot be observed in physical systems, since all physical systems in\none way or the other contain low-pass filters. It is thus sufficient to generate a\nlimited range of frequency content in the noise signal, as long as it exceeds the frequencies of\nthe subsequent dynamics by a sufficiently high factor (of e.g. 100).\n</p>\n\n<h4>About noise power</h4>\n\n<p>\nIdeal white noise has a flat, i.e. constant, power spectral density for all frequencies.\nIt has thus infinitely high power, because the total power of a signal can be obtained by\nintegrating the power spectral density over all frequencies. The following three ways to\nthink of the power of a signal may be helpful:\n</p>\n\n<ul>\n<li> The energy of a signal is the integral of its squared absolute value over time.\n The signal's power is this integral divided by the time span of the integral.</li>\n<li> The total power of a signal can also be obtained by integrating its (two-sided)\n power spectral density over all frequencies.</li>\n<li> The total power of a signal is finally also equal to its variance.</li>\n</ul>\n\n<p>\nIn order to set the correct level of the band-limited white noise power spectral density,\nthe variance of its normal distribution can thus be influenced directly.\nRecalling that the samplePeriod of the noise signal generates frequency content in the\nrange ±0.5/samplePeriod, the variance must be increased to generate sufficient\ntotal signal power. The total power must match the product of the noisePower and its\nfrequency bandwidth 1/samplePeriod: <code>signal power = signal variance = noisePower / samplePeriod</code>.\n</p>\n\n<p>\nExample <a href=\"modelica://Modelica.Blocks.Examples.NoiseExamples.DrydenContinuousTurbulence\">NoiseExamples.DrydenContinuousTurbulence</a>\ndemonstrates how to utilize this block to model wind gust.\n</p>\n</html>")); end BandLimitedWhiteNoise;