# Simulate a pulse of specific power

Suppose you produce a pulse x in discrete samples of duration dt each (e.g. in Matlab) according to a function. I was given some notes in which it shows that if I want it to let it have a specific power I have to first normalize it by doing

energy = sum((x.^2).*dt) %first calculate the pulse energy
x = x./sqrt(energy) %normalize its energy to 1


then you calculate the target energy

power = 0 %target power in dBm
power = (10^(power/10))/1000 %target power in W
energy = power*len(x)*dt %target energy of the pulse


and finally you scale the pulse so that it has the target power

x = x .* sqrt(energy) %the pulse at the target power


My question is, how does that really work? Why dividing x by sqrt(E) normalize it to unit energy? And why multiplying the resulting normalized x by the new sqrt(E) brings it to the target power? Why not just divide by E for example? and then multiply by E? Does it have any relation to RMS values? And finally is it something that can be used in any arbitrary pulses, e.g. in sinusoids as well?

Well, for a signal $x[k]$, the energy is: $$E=dt*\sum_{k=-\infty}^{\infty}x^2[k]$$
You want the energy to be one by dividing $x[k]$ through a value $a$, hence: $$1=dt*\sum_{k=-\infty}^{\infty}(\frac{x}{a})^2[k]$$ which by multiplying with $a^2$ becomes $$a^2=dt*\sum_{k=-\infty}^{\infty}x^2[k]$$ Comparing this to the first equation, it can be easily seen that $a^2=E$ and since $E$ is always positive, we can conclude $a=\sqrt{E}$. And that is why you divide by the square root of $E$.
From there it should be easy to see why multiplying this with $\sqrt{E'}$ makes a signal of energy $E'$.