55from adc_eval .eval import calc
66
77
8- def calc_psd (data , fs , nfft = 2 ** 12 ):
9- """Calculate the PSD using the Bartlett method."""
8+ def calc_psd (data , fs = 1 , nfft = 2 ** 12 ):
9+ """
10+ Calculate the PSD using the Bartlett method.
11+
12+ Parameters
13+ ----------
14+ data : ndarray
15+ Time-series input data.
16+ fs : float, optional
17+ Sample frequency of the input time series data in Hz. Default is 1Hz.
18+ nfft : int, optional
19+ Number of FFT samples to use for PSD calculation. Default is 2^12.
20+
21+ Returns
22+ -------
23+ list
24+ [freq_ss, psd_ss, freq_ds, psd_ds]
25+ List containing single and double-sided PSDs along with frequncy array.
26+ """
1027 nwindows = max (1 , int (np .floor (len (data ) / nfft )))
1128 nfft = int (nfft )
1229 xs = data [0 : int (nwindows * nfft )]
@@ -29,15 +46,49 @@ def calc_psd(data, fs, nfft=2**12):
2946
3047
3148def get_spectrum (data , fs = 1 , nfft = 2 ** 12 , single_sided = True ):
32- """Get the power spectrum for an input signal."""
49+ """
50+ Get the power spectrum for an input signal.
51+
52+ Parameters
53+ ----------
54+ data : ndarray
55+ Time-series input data.
56+ fs : float, optional
57+ Sample frequency of the input time series data in Hz. Default is 1Hz.
58+ nfft : int, optional
59+ Number of FFT samples to use for PSD calculation. Default is 2^12.
60+ single_sided : bool, optional
61+ Set to `True` for single-sided spectrum or `False` for double-sided.
62+ Default is `True`.
63+
64+ Returns
65+ -------
66+ tuple
67+ (freq, psd)
68+ Tuple containing frequency array and PSD of input data.
69+ """
3370 (freq_ss , psd_ss , freq_ds , psd_ds ) = calc_psd (np .array (data ), fs = fs , nfft = nfft )
3471 if single_sided :
3572 return (freq_ss , psd_ss * fs / nfft )
3673 return (freq_ds , psd_ds * fs / nfft )
3774
3875
3976def window_data (data , window = "rectangular" ):
40- """Applies a window to the time-domain data."""
77+ """
78+ Applies a window to the time-domain data.
79+
80+ Parameters
81+ ----------
82+ data : ndarray
83+ Time-series input data.
84+ window : str, optional
85+ Window to use for input data. Default is rectangular.
86+
87+ Returns
88+ -------
89+ ndarray
90+ Windowed version of input data.
91+ """
4192 try :
4293 wsize = data .size
4394 except AttributeError :
@@ -71,7 +122,41 @@ def plot_spectrum(
71122 single_sided = True ,
72123 fscale = ("MHz" , 1e6 ),
73124):
74- """Plot Power Spectrum for input signal."""
125+ """
126+ Plot Power Spectrum for input signal.
127+
128+ Parameters
129+ ----------
130+ data : ndarray
131+ Time-series input data.
132+ fs : float, optional
133+ Sample frequency of the input time series data in Hz. Default is 1Hz.
134+ nfft : int, optional
135+ Number of FFT samples to use for PSD calculation. Default is 2^12.
136+ dr : float, optional
137+ Dynamic range for input data to be referenced to. Default is 1.
138+ harmonics : int, optional
139+ Number of harmonics to calculate and annotate on plot. Default is 7.
140+ leak : int, optional
141+ Number of leakage bins to use in signal and harmonic calculation. Default is 1.
142+ window : str, optional
143+ Type of input window to use for input data. Default is rectangular.
144+ no_plot : bool, optional
145+ Selects whether to plot (`False`) or not (`True`). Default is `False`.
146+ yaxis : str, optional
147+ Selects y-axis reference units. Example: `power`, `fullscale`, etc. Default is `power`.
148+ single_sided : bool, optional
149+ Set to `True` for single-sided spectrum or `False` for double-sided.
150+ Default is `True`.
151+ fscale : tuple, optional
152+ Selects x-axis scaling and units. Default is ('MHz', 1e6).
153+
154+ Returns
155+ -------
156+ tuple
157+ (freq, psd, stats)
158+ Tuple containing frequency array, PSD of input data, and calculated statstics dictionary.
159+ """
75160 (freq , pwr ) = get_spectrum (data , fs = fs , nfft = nfft , single_sided = single_sided )
76161
77162 # Calculate the fullscale range of the spectrum in Watts
@@ -210,7 +295,41 @@ def analyze(
210295 single_sided = True ,
211296 fscale = "MHz" ,
212297):
213- """Perform spectral analysis on input waveform."""
298+ """
299+ Perform spectral analysis on input waveform.
300+
301+ Parameters
302+ ----------
303+ data : ndarray
304+ Time-series input data.
305+ nfft : int
306+ Number of FFT samples to use for PSD calculation.
307+ fs : float, optional
308+ Sample frequency of the input time series data in Hz. Default is 1Hz.
309+ dr : float, optional
310+ Dynamic range for input data to be referenced to. Default is 1.
311+ harmonics : int, optional
312+ Number of harmonics to calculate and annotate on plot. Default is 7.
313+ leak : int, optional
314+ Number of leakage bins to use in signal and harmonic calculation. Default is 1.
315+ window : str, optional
316+ Type of input window to use for input data. Default is rectangular.
317+ no_plot : bool, optional
318+ Selects whether to plot (`False`) or not (`True`). Default is `False`.
319+ yaxis : str, optional
320+ Selects y-axis reference units. Example: `power`, `fullscale`, etc. Default is `power`.
321+ single_sided : bool, optional
322+ Set to `True` for single-sided spectrum or `False` for double-sided.
323+ Default is `True`.
324+ fscale : str, optional
325+ Selects x-axis units. Default is 'MHz'.
326+
327+ Returns
328+ -------
329+ tuple
330+ (freq, psd, stats)
331+ Tuple containing frequency array, PSD of input data, and calculated statstics dictionary.
332+ """
214333 fscalar = {
215334 "uHz" : 1e-6 ,
216335 "mHz" : 1e-3 ,
0 commit comments