Skip to content

Commit 09d2a5e

Browse files
committed
ENH: pseudorandom for odd number of samples
1 parent 7977113 commit 09d2a5e

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

example/example_signals.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@
5858
plt.ylabel('Random signal [Unit]')
5959
plt.legend()
6060
plt.show()
61-
print(uniform_random[:5])
62-
6361

6462
# burst random
6563
N = 1000

pyExSi/signals.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def pseudo_random(N, rg=None):
104104
'`rg` must be initialized Generator object (numpy.random._generator.Generator)!'
105105
)
106106

107-
burst = np.fft.irfft(R_prand)
107+
burst = np.fft.irfft(R_prand, n=N)
108108
return burst / np.max(np.abs(burst))
109109

110110

@@ -419,7 +419,7 @@ def random_gaussian(N, PSD, fs, rg=None):
419419
'`rg` must be initialized Generator object (numpy.random._generator.Generator)!'
420420
)
421421

422-
burst = np.fft.irfft(ampl_spectra_random) # time signal
422+
burst = np.fft.irfft(ampl_spectra_random, n=N) # time signal
423423
return burst
424424

425425

@@ -592,10 +592,9 @@ def _get_nonstationary_signal_beta(N, PSD, fs, delta_n, alpha=1, beta=1, rg=None
592592
t_beta = np.copy(
593593
t[: n * delta_n + 1 : delta_n]
594594
) # time vector for modulating signal, with step delta_n
595-
t_beta = np.append(t_beta, t[-1])
596-
if N % delta_n != 0:
597-
n += 1
598-
t_beta[-1] = t[-1]
595+
if N % delta_n == 0:
596+
t_beta = np.append(t_beta, t[-1])
597+
599598

600599
if rg == None:
601600
rg = np.random.default_rng()

0 commit comments

Comments
 (0)