# Adding AWGN noise with certain power

Assume I have a signal(BPSK) and it has a certain amplitude. I would like to add a noise with a certain power to it. Assume I am using coding rate Rc as well. One method I am thinking would be to consider

EbNo="value" Eb=sum(signal.^2)/(length(signal)

sigma^2=Eb/(2*Rc*EbNo);
noise=sqrt(sigma^2)*randn(1,length(signal));
rec=signal=noise;


However it seems power of my noise does not match what I expect. Does anyone have any other suggestion or algorithm or do you guys know if there is anything wrong with what I wrote.

• "does not match what you've expected": could you please state what you expected, and what you've observed? Aug 5 '16 at 8:06
• I assume EbNo means $\frac{E_b}{N_0}$, i.e. bit energy to noise energy ratio? Because your $E_b$ calculation just gives you the signal power, as sum of sample energies divided by number of samples, not respecting the fact that a) your BPSK might have pulse shape, and b) more important here, because you respect that elsewhere, the fact that bit energy is energy per info bit, not per code bit, usually, because that's the whole point of using it to compare different codes. Aug 5 '16 at 8:09

First consider the case with no noise. In this scenario, the matched filter's output is an array of numbers, each of which is equal to $+\sqrt{E_b}$ or $-\sqrt{E_b}$. The average energy per sample is then equal to $E_b$.
Now consider the case where only white noise is present at the matched filter's input. The sampled filter output is a sequence of random values with variance $\sigma_n^2$. The signal-to-noise ratio is defined as $E_b/\sigma_n^2$. By convention, $\sigma_n^2$ is denoted $N_0/2$, which means that $\text{SNR}=2E_b/N_0$. (This is because when the filter input is white noise with power spectral density $N_0/2$ and the matched filter's impuse response has energy equal to 1, then the variance of the sampled filtered noise is also $N_0/2$. This is a technical detail that you may omit for now and come back to when you're more comfortable with the theory).
Then, $$\sigma_n^2=\frac{N_0}{2}=\frac{E_b}{SNR}.$$ Using this equation you can easily simulate any SNR you want. A word of caution: it is common, when plotting the bit error rate vs the SNR, to use $E_b/N_0$. Be aware of this when comparing your results to those published elsewhere.