@@ -183,19 +183,19 @@ def burst_random(
183
183
184
184
185
185
def sine_sweep (
186
- time , phi = 0 , f_start = 1 , sweep_rate = None , f_stop = None , mode = 'linear' , phi_end = False
186
+ time , phi = 0 , freq_start = 1 , sweep_rate = None , freq_stop = None , mode = 'linear' , phi_end = False
187
187
):
188
188
"""
189
189
Generate a sine sweep signal time series.
190
190
191
191
:param time: array of shape (N,), time vector.
192
192
:param phi: float, initial phase of the sine signal in radians.
193
193
Defaults to 0.
194
- :param f_start : float, initial frequency in Hz.
194
+ :param freq_start : float, initial frequency in Hz.
195
195
:param sweep_rate: float, the rate of sweep. In Hz/s for a linear sweep,
196
196
in octaves/minute for a logarithmic sweep. If not given it is
197
- calculated from `time`, `f_start ` and `f_stop `.
198
- :param f_stop : float, final frequency in Hz.
197
+ calculated from `time`, `freq_start ` and `freq_stop `.
198
+ :param freq_stop : float, final frequency in Hz.
199
199
:param mode: 'linear' or 'logarithmic', type of sweep, optional.
200
200
Defaults to 'linear'.
201
201
:param phi_end: If True, return (`sweep_sine`, `phi_end`), where
@@ -211,16 +211,16 @@ def sine_sweep(
211
211
>>> import pyExSi as es
212
212
213
213
>>> t = np.linspace(0,10,1000)
214
- >>> x = es.sine_sweep(time=t, f_start =0, f_stop =5)
214
+ >>> x = es.sine_sweep(time=t, freq_start =0, freq_stop =5)
215
215
>>> plt.plot(t, x)
216
216
>>> plt.show()
217
217
"""
218
218
if sweep_rate is None :
219
- if not f_stop is None :
219
+ if not freq_stop is None :
220
220
T = time [- 1 ] - time [0 ]
221
- sweep_rate = _sweep_rate (T , f_start , f_stop , mode )
221
+ sweep_rate = _sweep_rate (T , freq_start , freq_stop , mode )
222
222
else :
223
- raise ValueError ('`sweep_rate` is not given, please supply `f_stop `.' )
223
+ raise ValueError ('`sweep_rate` is not given, please supply `freq_stop `.' )
224
224
if phi_end :
225
225
# prepare time
226
226
time_ = np .zeros (len (time ) + 1 )
@@ -230,13 +230,13 @@ def sine_sweep(
230
230
time_ = time
231
231
232
232
if mode == 'linear' :
233
- phase_t = 2 * np .pi * (sweep_rate * 0.5 * time_ ** 2 + f_start * time_ )
233
+ phase_t = 2 * np .pi * (sweep_rate * 0.5 * time_ ** 2 + freq_start * time_ )
234
234
elif mode == 'logarithmic' :
235
235
phase_t = (
236
236
2
237
237
* np .pi
238
238
* 60
239
- * f_start
239
+ * freq_start
240
240
/ (sweep_rate * np .log (2 ))
241
241
* (2 ** (sweep_rate * time_ / 60 ) - 1 )
242
242
)
@@ -250,15 +250,15 @@ def sine_sweep(
250
250
return s
251
251
252
252
253
- def _sweep_rate (T , f_start , f_stop , mode = 'linear' ):
253
+ def _sweep_rate (T , freq_start , freq_stop , mode = 'linear' ):
254
254
"""
255
255
Calculate the sweep rate given the time difference, initial and end
256
256
frequency values and sweep mode. For internal use by `sweep`.
257
257
"""
258
258
if mode == 'linear' :
259
- sweep_rate = (f_stop - f_start ) / T # Hz/s
259
+ sweep_rate = (freq_stop - freq_start ) / T # Hz/s
260
260
elif mode == 'logarithmic' :
261
- sweep_rate = np .log ((f_stop / f_start ) ** (60 / T / np .log (2 ))) # octaves/min
261
+ sweep_rate = np .log ((freq_stop / freq_start ) ** (60 / T / np .log (2 ))) # octaves/min
262
262
else :
263
263
raise ValueError ('Invalid sweep mode `{mode}`.' )
264
264
return sweep_rate
@@ -323,16 +323,16 @@ def impulse(N, n_start=0, width=None, amplitude=1.0, window='sine'):
323
323
return pulse
324
324
325
325
326
- def get_psd (f , f_low , f_high , variance = 1 ):
326
+ def get_psd (freq , freq_lower , freq_upper , variance = 1 ):
327
327
"""
328
328
One-sided flat-shaped power spectral density (PSD).
329
329
330
- :param f : Frequency vector [Hz]
331
- :type f : array
332
- :param f_low : Lower frequency of PSD [Hz]
333
- :type f_low : float
334
- :param f_high: Higher frequency of PSD [Hz]
335
- :type f_high : float
330
+ :param freq : Frequency vector [Hz]
331
+ :type freq : array
332
+ :param freq_lower : Lower frequency of PSD [Hz]
333
+ :type freq_lower : float
334
+ :param freq_upper: Upper frequency of PSD [Hz]
335
+ :type freq_upper : float
336
336
:param variance: Variance of random process, described by PSD [unit^2]
337
337
:type variance: float
338
338
:returns: one-sided flat-shaped PSD [unit^2/Hz]
@@ -347,19 +347,19 @@ def get_psd(f, f_low, f_high, variance=1):
347
347
>>> fs = 100 # sampling frequency [Hz]
348
348
>>> t = np.arange(0,N)/fs # time vector
349
349
>>> M = N // 2 + 1 # number of data points of frequency vector
350
- >>> f = np.arange(0, M, 1) * fs / N # frequency vector
351
- >>> f_min = 10 # PSD upper frequency limit [Hz]
352
- >>> f_max = 20 # PSD lower frequency limit [Hz]
350
+ >>> freq = np.arange(0, M, 1) * fs / N # frequency vector
351
+ >>> freq_lower = 10 # PSD lower frequency limit [Hz]
352
+ >>> freq_upper = 20 # PSD upper frequency limit [Hz]
353
353
354
- >>> PSD = es.get_psd(f, f_min, f_max ) # one-sided flat-shaped PSD
355
- >>> plt.plot(f ,PSD)
354
+ >>> PSD = es.get_psd(freq, freq_lower, freq_upper ) # one-sided flat-shaped PSD
355
+ >>> plt.plot(freq ,PSD)
356
356
>>> plt.xlabel(f [Hz])
357
357
>>> plt.ylabel(PSD [unit^2/Hz])
358
358
>>> plt.show()
359
359
"""
360
- PSD = np .zeros (len (f ))
361
- indx = np .logical_and (f >= f_low , f <= f_high )
362
- PSD_width = f [indx ][- 1 ] - f [indx ][0 ]
360
+ PSD = np .zeros (len (freq ))
361
+ indx = np .logical_and (freq >= freq_lower , freq <= freq_upper )
362
+ PSD_width = freq [indx ][- 1 ] - freq [indx ][0 ]
363
363
PSD [indx ] = variance / PSD_width # area under PSD is variance
364
364
return PSD
365
365
@@ -395,11 +395,11 @@ def random_gaussian(N, PSD, fs, rg=None):
395
395
>>> fs = 100 # sampling frequency [Hz]
396
396
>>> t = np.arange(0,N)/fs # time vector
397
397
>>> M = N // 2 + 1 # number of data points in frequency vector
398
- >>> f = np.arange(0, M, 1) * fs / N # frequency vector
399
- >>> f_min = 10 # PSD upper frequency limit [Hz]
400
- >>> f_max = 20 # PSD lower frequency limit [Hz]
398
+ >>> freq = np.arange(0, M, 1) * fs / N # frequency vector
399
+ >>> freq_lower = 10 # PSD lower frequency limit [Hz]
400
+ >>> freq_upper = 20 # PSD upper frequency limit [Hz]
401
401
402
- >>> PSD = es.get_psd(f, f_min, f_max ) # one-sided flat-shaped PSD
402
+ >>> PSD = es.get_psd(freq, freq_lower, freq_upper ) # one-sided flat-shaped PSD
403
403
>>> x = es.random_gaussian(N, PSD, fs)
404
404
>>> plt.plot(t,x)
405
405
>>> plt.xlabel(t [s])
@@ -463,11 +463,11 @@ def stationary_nongaussian_signal(N, PSD, fs, s_k=0, k_u=3, mean=0, rg=None):
463
463
>>> fs = 100 # sampling frequency [Hz]
464
464
>>> t = np.arange(0,N)/fs # time vector
465
465
>>> M = N // 2 + 1 # number of data points of frequency vector
466
- >>> f = np.arange(0, M, 1) * fs / N # frequency vector
467
- >>> f_min = 10 # PSD upper frequency limit [Hz]
468
- >>> f_max = 20 # PSD lower frequency limit [Hz]
466
+ >>> freq = np.arange(0, M, 1) * fs / N # frequency vector
467
+ >>> freq_lower = 10 # PSD lower frequency limit [Hz]
468
+ >>> freq_upper = 20 # PSD upper frequency limit [Hz]
469
469
470
- >>> PSD = es.get_psd(f, f_min, f_max ) # one-sided flat-shaped PSD
470
+ >>> PSD = es.get_psd(freq, freq_lower, freq_upper ) # one-sided flat-shaped PSD
471
471
>>> x_gauss = es.random_gaussian(N, PSD, fs)
472
472
>>> x_ngauss = es.stationary_nongaussian_signal(N, PSD, fs, k_u = 5)
473
473
>>> plt.plot(t, x_gauss, label='gaussian')
@@ -705,16 +705,16 @@ def nonstationary_signal(
705
705
>>> fs = 100 # sampling frequency [Hz]
706
706
>>> t = np.arange(0,N)/fs # time vector
707
707
>>> M = N // 2 + 1 # number of data points of frequency vector
708
- >>> f = np.arange(0, M, 1) * fs / N # frequency vector
709
- >>> f_min = 10 # signals's PSD upper frequency limit [Hz]
710
- >>> f_max = 20 # signals' PSD lower frequency limit [Hz]
711
- >>> f_min_mod = 1 # modulating signals's PSD upper frequency limit [Hz]
712
- >>> f_max_mod = 2 # modulating signals's PSD lower frequency limit [Hz]
708
+ >>> freq = np.arange(0, M, 1) * fs / N # frequency vector
709
+ >>> freq_lower = 10 # PSD lower frequency limit [Hz]
710
+ >>> freq_upper = 20 # PSD upper frequency limit [Hz]
711
+ >>> freq_lower_mod = 1 # modulating signals's PSD lower frequency limit [Hz]
712
+ >>> freq_upper_mod = 2 # modulating signals's PSD upper frequency limit [Hz]
713
713
714
714
PSD of stationary and modulating signal
715
715
716
- >>> PSD = es.get_psd(f, f_low = f_min, f_high = f_max ) # one-sided flat-shaped PSD
717
- >>> PSD_modulating = es.get_psd(f, f_low = f_min_mod, f_high = f_max_mod ) # one-sided flat-shaped PSD
716
+ >>> PSD = es.get_psd(freq, freq_lower, freq_upper ) # one-sided flat-shaped PSD
717
+ >>> PSD_modulating = es.get_psd(freq, freq_lower_mod, freq_upper_mod ) # one-sided flat-shaped PSD
718
718
719
719
Specify kurtosis and return non-stationary signal
720
720
0 commit comments