We have seen in the previous sections how analyze various random sequences. Now we want to go the other way. Let's say that we need to simulate some random noise. Maybe to test out a filter or some other algorithm. We want the random sequence to have certain characteristics to mimic what we expect in the field. How can we do that.
The matlab command we are going to want here is wgn() from the communications toolbox. wgn stands for ``white gaussian noise'', where ``white'' means equal PSD at all frequencies, and gaussian means the amplitude has a gaussian distribution. Review the two previous sections if this does not make sense to you.
The basic syntax according to the help is y = wgn(m,n,p) where p is the power. What matlab's help does not do is give you much help on understanding how to pick the power. By default, power is specified in dB watts. Let's say what we want is a power spectral density of 10 V^2/Hz across the bandwidth 0 to 1 kHz. How many watts is that? Remember the two basical electrical relations are V=IR, and P=IV. Therefore, P=V^2/R. So we can convert from watts to volts squared if we know the resistance (or impedance). If we read a little farther in the help, we see a second form y = wgn(m,n,p,imp), where imp is the impedance. If we don't specify imp, then the default is 1. So, by default, if we specify 1 dB W, that is the same as 1 dB V^2. So, if we want 10 V^2/Hz, across the bandwidth 0 to 1 kHz, we just need 10 * 1000 = 10000 V^2 = 40 dB W.
The code to generate this is quite simple:
Fs = 2000; t = 0:(1/Fs):300; sig = wgn(length(t), 1, 40); [spectra,freq] = pwelch(sig, floor(length(t)/512) ,[],[],Fs); figure; plot(freq, spectra); xlabel('Freq (Hz)'); ylabel('PSD (V^2 / Hz)');
/' $I