I have a GMSK modulator in MATLAB and wish to generate AWGN with a specific SNR, and I'm having some issues figuring out just how.
I have found this step-by-step process to generate zero-mean Gaussian noise with a specified power spectral density W0:
- Form Gaussian distributed random variable: w = randn(1,N)
- Map top zero mean: w = w - sum(w)/N
- Compute average power: Pw = sum(w.^2)/N
- Form w = w.*sqrt(W0*fs/Pw)
Note: As pointed out by Deve, steps 2 and 3 should not be necessary, since randn() generates a random variable with zero-mean and power 1. However, it is possible that the mean and power may be slightly off, since the vector is of finite length. For my application, neglecting these steps give a slightly less accurate SNR.
So, how do I determine which power spectral density I need to achieve a specified SNR? I understand that SNR is defined as $SNR=P_s/P_n$. Measuring the signal power using $P_s=\frac{1}{N}\sum_{n=0}^{N-1} s[n]^2$ and then isolating $P_n=P_s/SNR$ seems trivial, but how do I relate $P_n$ to $W_0$?
Thanks in advance!
Edit: Using Deves answer, I have written the following code:
s = signal;
L = length(s);
% Convert SNR from dB
SNRdB = 10;
SNR = 10^(SNRdB/10);
% Measure average power of signal
Ps = sum(s.^2)/L;
% Calculate wanted noise power
Pn = Ps/SNR;
% Generate random vector and ensure 0-mean
w = randn(1,L);
w = w-sum(w)/L;
% Scale to wanted power
Pw = 1/L*sum(w.^2);
w = sqrt(Pn/Pw).*w;
% Measure resulting SNR
Pw_meas = 1/L*sum(w.^2);
SNRdB_meas = 10*log10( Ps/Pw_meas ); % Gives 10.0000
And here's a plot in time domain for anyone interested:
It doesn't seem like a lot of noise - but I guess the calculation of SNRdB_meas
is quite foolproof.
[PSD plot removed]