AWGN for a specific dBc

I have a square-ware signal with 1V peak-to-peak (alternating between -500 and +500mV, so its absolute value is a constant 500mV) and I would like to add to this an AWGN expressed in dBc ("decibels relative to the carrier").

How I should generate such normal distribution noise?

I got a hint that - for e.g. -40dBc - the following code would work:

normal(0, (m.pow(10, (-40 / 20)) / 2), ..)


However this ends up generating a lower dBc value (around -31 dBc), meaning "stronger" noise than expected.

Reading around made me find the description of "half-normal distribution", which states that the expected absolute value scales not with sigma, but with sigma*sqrt(2/pi). I tried the following code - and it does seem to work - but I would like to ask for your kind input on whether my thinking was correct and if this code is the appropriate one:

normal(0, (m.pow(10, (-40 / 20)) / 2 / m.sqrt(2 / m.pi)), ..)


• Integrate carrier (in this case it is t*0.5 [V] <- let us call this a
• Integrate the output of normal() <- let us call this b
• Calculate 20 * log10(b / a)

Notes:

• The code sniplets above are Python-like
• The "/ 2" is there as my carrier is 1V peak-to-peak
• so, can you, mathematically, what the power of the square wave you're describing is? Because your dBc values are "power relative to the carrier power", and I feel like your question would be a lot easier to answer by yourself if you understood that – but I might simply be mistaken, which is why I'm asking. – Marcus Müller Oct 3 at 11:12
• Thanks for the edit and your answer Marcus. Right, and I assume a constant impedance. – user45441 Oct 3 at 11:29
• so, what is the power of your square wave? – Marcus Müller Oct 3 at 11:30
• sorry, I phrased myself vaguely. I meant that I have a constant resistive R and the signal generator is an ideal voltage source, so the power of the carrier will just be P = V*V/R, where V is the modulated carrier – user45441 Oct 3 at 11:41
• exactly, so your square wave "carrier" has a power of 0.5²/R. Let's arbitrarily set R=1, so then we end up with a power of ¼ for your carrier. Was this known to you? Great! So, what's the power of zero-mean noise with variance $\sigma^2$? – Marcus Müller Oct 3 at 11:53