16
$\begingroup$

In some papers, I read that the additive noise is band limited Gaussian white.
How can I simulate this type of noise use Matlab?

$\endgroup$
  • $\begingroup$ In continuous-time systems, the concept of band-limited white noise, whether Gaussian or not, is well-defined and well understood. For discrete-time systems, the issue is more complicated and you need to consider what the band limitation is and how it compares to the Nyquist frequency. $\endgroup$ – Dilip Sarwate Jun 21 '13 at 16:05
  • 2
    $\begingroup$ @DilipSarwate: To me,"band-limited white noise" is an oxymoron! :-) $\endgroup$ – Peter K. Jun 21 '13 at 23:54
  • $\begingroup$ @PeterK. The notion of bandlimited white noise is used primarily in bandpass systems where the characteristics of noise outside the passband are irrelevant while within the passband, the noise is indistinguishable from white noise that has been passed through an ideal bandpass filter that passes precisely the frequency band that is the passband. It is no more an oxymoron than white noise (without any pejorative comments about band-limitations). See also, DRazick's comment (which is spot on) following Jason R's answer (which I disagree with). $\endgroup$ – Dilip Sarwate Jun 22 '13 at 1:59
  • 1
    $\begingroup$ @DilipSarwate: Thanks for the explanation. I get it, but I still think it's a very poor choice of terminology. To me "band-pass filtered white noise" is more accurate, but I suppose it ends up at the same place. $\endgroup$ – Peter K. Jun 22 '13 at 2:39
  • 1
    $\begingroup$ @PeterK. Unfortunately, "band-pass filtered white noise" generally means the process described in JasonR's answer. Start with white noise and filter it through a filter with transfer function $H(f)$ to get a process with PSD proportional to $|H(f)|^2$. Band-limited white noise is the same except that we insist that$H(f)$ must be the transfer function of an ideal bandpass filter. The key point with white noise is that we can't put the signal where the noise a'i'nt which applies to band-limited white noise too as long as we are constrained to have our signals stay in band. $\endgroup$ – Dilip Sarwate Jun 22 '13 at 3:04
18
$\begingroup$

You would generate bandlimited Gaussian noise by first generating white noise, then filtering it to the bandwidth that you desire. As an example:

% design FIR filter to filter noise to half of Nyquist rate
b = fir1(64, 0.5);
% generate Gaussian (normally-distributed) white noise
n = randn(1e4, 1);
% apply to filter to yield bandlimited noise
nb = filter(b,1,n);
$\endgroup$
  • $\begingroup$ I have always wondered this, but if something like this is done, then what is so Gaussian about it anymore? I dont think the PDF is at all at this point... $\endgroup$ – Spacey Jun 20 '13 at 2:04
  • 8
    $\begingroup$ One of the special features of Gaussian random variables is that the sum of two independent Gaussian RVs is also Gaussian distributed. Since the input noise is white, you can look at each sample at the filter output as a sum of many independent Gaussian random variables (where the variance of each RV depends upon the input noise variance and the values of the corresponding filter tap). Therefore, the samples at the filter output are also Gaussian distributed. However, the noise is obviously no longer white, as there is correlation between successive samples at the filter output. $\endgroup$ – Jason R Jun 20 '13 at 4:05
  • $\begingroup$ This property is described in more detail at Wikipedia. Note that the property still holds even if the input noise is colored (see the "Correlated random variables" section). $\endgroup$ – Jason R Jun 20 '13 at 4:06
  • 1
    $\begingroup$ facepalm. Of course. $\endgroup$ – Spacey Jun 20 '13 at 15:20
  • 3
    $\begingroup$ Yet this method won't generate White noise. No need to apply a filter, every discrete sampled noise is band limited to begin with. $\endgroup$ – Royi Jun 21 '13 at 15:02
9
$\begingroup$

Just as a small addition to Jason's answer: usually you need to generate bandlimited noise with a given variance $\sigma^2$. You can add this code to the code given in Jason's answer:

var = 3.0;  % just an example  
scale = sqrt(var)/std(nb);
nb = scale*nb;  % nb has variance 'var'

Note that you have to do the scaling after filtering, because in general the filter changes the noise variance.

$\endgroup$
  • 2
    $\begingroup$ Good point. If you scale the filter coefficients such that $\sum_{n=0}^{N} |h[n]|^2 = 1$, then the filter will not affect the noise variance. $\endgroup$ – Jason R Jun 20 '13 at 14:39
  • $\begingroup$ @Matt Nice addition! $\endgroup$ – Spacey Jun 20 '13 at 15:13
4
$\begingroup$

Every time you generate discrete noise samples (Using MATLAB's randn / rand for instance) you actually generate a band limited noise.

All you need to do is the adjustment of the variance of the discrete samples to the variance of the "Continuous" noise those samples are allegedly taken from.

Given a continuous White Noise (Wide Sense) with variance $ \sigma^{2}_{cn} \delta (t) $ and you want sample it at rate of $ f_{s} $ you should generate discrete noise samples with variance of $ f_{s} \sigma^{2}_{cn} $.

This result is valid assuming before sampling the continuous noise you applied an ideal LPF filter with bandwidth of $ f_{s} / 2 $.

Full description is given here:
How to simulate AWGN in communication systems for specific bandwidth

$\endgroup$
2
$\begingroup$

Why can one not use the approach mentioned in this post?

It starts with the desired frequencies and works backwards to build the signal, instead of filtering. It uses python code, but also links to the original Matlab code.

Are there any drawbacks to doing it that way?

$\endgroup$
  • $\begingroup$ looking at the original matlab code, it works for a block size of n, your fft length. If I want 2n samples, you can double the fft length, which is more than doing 2 ffts. if you do 2 separate blocks, there will be a discontinuous transition from the first to the second block. you could use a window to smooth out the transition, but then you need to do more than 2 blocks to avoid scalloping your time series. Using the filter method, once the filter is in steady state, you can feed it random numbers as long as you want. The processing increase for the filter method scales linearly. $\endgroup$ – Stanley Pawlukiewicz Sep 23 at 18:11
0
$\begingroup$

i realize this question popped up in current view because @Drazick modified his/her 2013 answer.

if you generate a good uniform p.d.f. pseudo-random number $x$ (say using rand() or frand(), if it's a good version) that ranges from 0 to 1 (that is $0 \le x < 1$), then if you do that 12 times, add up all 12 of the supposedly independent and uncorrelated values, and subtract 6.0 from that sum, you will have something that is very close to a unit-variance and zero-mean gaussian random number. if the uniform p.d.f. pseudo-random numbers are "good" (that is they exhibit independence from each other), this sum will be as "white" as you can get a discrete-time signal to be.

"white noise" is, of course a misnomer, even for analog signals. a "power signal" with flat spectrum all the way to infinity also has infinite power. the virtually-gaussian and "white" signal generated as described has a finite power (which is the variance and is 1) and finite bandwidth which, expressed as one-sided, is Nyquist. (so the 'power spectral density" or power per unit frequency is 1/Nyquist.) scale it and offset it however you please.

i s'pose i can edit this later and add some C-like pseudo-code to show this explicitly.

$\endgroup$
-1
$\begingroup$

Producing full spectrum white noise and then filtering it is like you want to paint a wall of your house white, so you decide to paint the whole house white and then paint back all house except the wall. Is idiotic. (But has sense in electronics).

I made a small C program that can generate white noise at any frequency and any bandwidth (let's say at 16kHz central frequency and 2 kHz "wide"). No filtering involved.

What I did is simple: inside the main (infinite) loop I generate a sinusoid at center frequency +/- a random number between -half bandwidth and +halfbandwidth, then I keep that frequency for an arbitrary number of samples (granularity) and this is the result:

White noise 2kHz wide at 16kHz center frequency

White noise 2kHz wide at 16kHz center frequency

Pseudo code:

while (true)
{

    f = center frequency
    r = random number between -half of bandwidth and + half of bandwidth

<secondary loop (for managing "granularity")>

    for x = 0 to 8 (or 16 or 32....)

    {

        [generate sine Nth value at frequency f+r]

        output = generated Nth value
    }


}
$\endgroup$
  • 1
    $\begingroup$ The STFT isn’t flat across the band. You have not shown why there is any advantage to your technique. Btw most paint is stocked as a grayish white and then mixed with pigment. Orange paint isn’t made by just using orange ingredients. There isn’t any extra work in generating white noise. $\endgroup$ – Stanley Pawlukiewicz Sep 22 at 12:59
  • $\begingroup$ @StanleyPawlukiewicz In electronics you are righe because a noise generator and a filter are two very simple "objects". In programming, a filter is complex in number of instructions way more than just generating the needed data. So when programming is preferable my approach if you have time critical applications. If you downvoted I suggest you to think again about it. $\endgroup$ – Zibri Sep 23 at 6:21
  • 1
    $\begingroup$ your noise isn’t preferable. the spectrum isn’t flat across the band. calling a transcendental function on the fly isn’t faster than filtering. your arguments are unsubstantiated $\endgroup$ – Stanley Pawlukiewicz Sep 23 at 11:37
  • 1
    $\begingroup$ Actually the inband ripple is a design parameter. To say they peak at the center frequency is also false $\endgroup$ – Stanley Pawlukiewicz Sep 24 at 12:32
  • 1
    $\begingroup$ since your technique so easy to modify, why don’t you write your own sine wave routine instead of linking to one and claiming that your code is less complex and compare that to a biquad. while you are add it, how about a fixed point version. you might also think about how your technique scales as you increase the number of samples $\endgroup$ – Stanley Pawlukiewicz Sep 24 at 13:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.