veeresht / CommPy

Digital Communication with Python
http://veeresht.github.com/CommPy
BSD 3-Clause "New" or "Revised" License
551 stars 179 forks source link

Adding AWGN to a signal #94

Open adeeb10abbas opened 3 years ago

adeeb10abbas commented 3 years ago

Adding Gaussian noise to a signal of a specific SNR. The signal may or may not have noise already

BastienTr commented 3 years ago

Hi @adeeb10abbas,

Could you be more precise on your issue. Is this a question? Do you report a bug? Do you ask for a feature?

adeeb10abbas commented 3 years ago

Yes sorry about that. I am asking for a feature! Thanks!

BastienTr commented 3 years ago

Did you have a look to the SISOFlatChannel class? It should do what you ask for. There are several variants possible, like using a complex signal but this snippet should be enough to start.

from commpy.channels import SISOFlatChannel
from commpy.utilities import signal_power
import numpy as np

channel = SISOFlatChannel()
noiseless_signal = np.random.choice((-1, 1), 10)  # Use your own signal here
channel.set_SNR_dB(10, Es=signal_power(noiseless_signal))  # I compute the signal power but if you know it, you can just specified the right argument
noisy_signal = channel.propagate(noiseless_signal)

Is it OK for you? If so, I let you close this issue.

adeeb10abbas commented 3 years ago

Yes, this works but partially. I am looking for something that can add noise to a signal that already has some amount of noise.

BastienTr commented 3 years ago

Replace noiseless_signal with your already noisy signal and it's done, isn't it?