Fixed noise generation
This commit is contained in:
parent
c4c7a7176a
commit
0270e7fcad
|
|
@ -61,7 +61,7 @@ class RecordingGenerator:
|
||||||
def generate_wb(self, num: int = 2, length: int = 8192):
|
def generate_wb(self, num: int = 2, length: int = 8192):
|
||||||
for i in range(num):
|
for i in range(num):
|
||||||
recording = create_noise_recording(
|
recording = create_noise_recording(
|
||||||
length=length, rms_power=0.2, counter=random.choice([2, 4, 8, 16, 32])
|
length=length, rms_power=0.2, seed=num
|
||||||
)
|
)
|
||||||
recording.to_npy(filename=f"wb{i + 1}", overwrite=True)
|
recording.to_npy(filename=f"wb{i + 1}", overwrite=True)
|
||||||
print(f"wb{i + 1} file saved.")
|
print(f"wb{i + 1} file saved.")
|
||||||
|
|
|
||||||
|
|
@ -99,24 +99,23 @@ def create_lfm_recording(
|
||||||
def create_noise_recording(
|
def create_noise_recording(
|
||||||
rms_power: float,
|
rms_power: float,
|
||||||
length: int,
|
length: int,
|
||||||
counter: int,
|
seed: int | None = None
|
||||||
) -> Recording:
|
) -> Recording:
|
||||||
"""Generate a Recording of Additive White Gaussian Noise (AWGN)."""
|
"""Generate a Recording of Additive White Gaussian Noise (AWGN)."""
|
||||||
# 1. Create a repeating pseudo-random envelope
|
# 1. Create a repeating pseudo-random envelope
|
||||||
np.random.seed(256 + counter)
|
if seed is not None:
|
||||||
chunk = np.random.rand(length // 4)
|
np.random.seed(seed)
|
||||||
tiled = np.tile(chunk, 4)
|
|
||||||
amplitude_envelope = np.sqrt(tiled)
|
# 2. Sigma for complex AWGN:
|
||||||
|
sigma = np.sqrt(rms_power / 2)
|
||||||
|
|
||||||
# 2. Generate complex Gaussian noise with unit power
|
# 3. Generate complex Gaussian noise with correct power
|
||||||
real = np.random.normal(0, 1, length)
|
real = np.random.normal(0, sigma, length)
|
||||||
imag = np.random.normal(0, 1, length)
|
imag = np.random.normal(0, sigma, length)
|
||||||
complex_noise = real + 1j * imag
|
complex_noise = real + 1j * imag
|
||||||
|
|
||||||
# 3. Scale noise by desired power and envelope
|
metadata = {"interference": "wb", "signal_type": "noise", "rms_power": rms_power}
|
||||||
scaled_noise = complex_noise * amplitude_envelope * np.sqrt(rms_power)
|
return Recording(data=complex_noise, metadata=metadata)
|
||||||
metadata = {"interference": "wb", "signal_type": "noise"}
|
|
||||||
return Recording(data=scaled_noise, metadata=metadata)
|
|
||||||
|
|
||||||
|
|
||||||
def create_ctnb_recording(length: int) -> Recording:
|
def create_ctnb_recording(length: int) -> Recording:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user