Mathematical library for calculating the signal spectrum
The main functionality is the calculation of raw spectrum values and the calculation of EEG spectrum values. Working with the library is possible in iterative mode (adding new data to the internal buffer, calculating spectrum values) and in one-time spectrum calculation mode for a given array. When working in the iterative mode, the spectrum is calculated with the frequency set during initialization.
Initialization
Main parameters
- Raw signal sampling frequency. Need to be >= 1.
- Spectrum calculation frequency. Need to be <= 16 kHz.
- Spectrum calculation window length. Need to be <= signal sampling frequency.
Optional parameters
- Upper bound of frequencies for spectrum calculation. Default value is sampling_rate / 2.
- Normalization of the EEG spectrum by the width of the wavebands. Disabled by default.
- Weight coefficients for alpha, beta, theta, gamma, delta waves. By default has 1.0 value.
Creation
sampling_rate = 250 # raw signal sampling frequency
fft_window = sampling_rate * 4 # spectrum calculation window length
process_win_rate = 5 # spectrum calculation frequency
spectrum_math = SpectrumMath(sampling_rate, fft_window, process_win_rate)
Optional initialization
- Additional spectrum settings:
bord_frequency = 50 # upper bound of frequencies for spectrum calculation
normalize_spect_by_bandwidth = True # normalization of the EEG spectrum by the width of the wavebands
pectrum_math.init_params(bord_frequency, normalize_spect_by_bandwidth)
- Waves coefficients:
delta_coef = 0.0
theta_coef = 1.0
alpha_coef = 1.0
beta_coef = 1.0
gamma_coef = 0.0
spectrum_math.set_waves_coeffs(delta_coef, theta_coef, alpha_coef, beta_coef, gamma_coef)
- Setting the smoothing of the spectrum calculation by Henning (by default) or Hemming window:
spectrum_math.set_hanning_win_spect() # by Hanning (by default)
spectrum_math.set_hamming_win_spect() # by Hamming
Initializing a data array for transfer to the library
Array of double values with length less or equals then 15 * saignal sampling frequency.
Types
RawSpectrumData
Structure containing the raw spectrum values (with boundary frequency taken into library).
Fields:
- all_bins_nums - Integer value. Number of FFT bars. Contained only in the C++ interface.
- all_bins_values - Double array. Raw FFT bars values.
- total_raw_pow - Double value. Total raw spectrum power.
WavesSpectrumData
Structure containing the waves values.
Absolute frequency values (double type):
- delta_raw
- theta_raw
- alpha_raw
- beta_raw
- gamma_raw
Relative (percent) values (double type):
- delta_rel
- theta_rel
- alpha_rel
- beta_rel
- gamma_rel
FFT band resolution
The library automatically matches the optimal buffer length (degree 2) to calculate the FFT during initialization, depending on the specified window length. Receiving resolution for the FFT bands (number of FFT bands per 1 Hz):
spectrum_math.get_fft_bins_for_1_hz()
Spectrum calculation in iterative mode
- Adding and process data:
samples = [0 for _ in range(sample_count)]
spectrum_math.push_and_process_data(samples)
- Getting the results:
raw_spectrum_data = spectrum_math.read_raw_spectrum_info_arr()
waves_spectrum_data = spectrum_math.read_waves_spectrum_info_arr()
- Updating the number of new samples. Is necessary for correct calculation of elements in the array of obtained structures, if a large portion of data is added to the library all at once.
spectrum_math.set_new_sample_size()
Spectrum calculation for a single array
- Compute spectrum:
samples = [0 for _ in range(sample_count)]
spectrum_math.compute_spectrum(samples)
- Getting the results:
raw_spectrum_data = spectrum_math.read_raw_spectrum_info()
waves_spectrum_data = spectrum_math.read_waves_spectrum_info()
Finishing work with the library
del spectrum_lib
Metadata
Release files for pyspectrum-lib 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyspectrum_lib-1.0.2.tar.gz | 81.1 kB | Without provenance | Details for pyspectrum_lib-1.0.2.tar.gz |
Release files / pyspectrum_lib-1.0.2.tar.gz
| Download URL | pyspectrum_lib-1.0.2.tar.gz |
|---|---|
| Size | 81.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fd4abf6b153198fc53de5b0ed8dbc9b9ea480a841657469fa3b8d7130dfaafee
|
|
BLAKE2b-256 checksum How to use checksums |
ff6e84e4658cdcd796ac3d3a07b6987b9d6b20ce7d714c7a5ca7300e77d9d114
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.6
|
Security for pyspectrum-lib 1.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.