Package: pyspectrum-lib
Mathematical library for calculating the signal spectrumThe 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.InitializationMain parametersRaw 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 parametersUpper 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.CreationPythonsampling_rate=250# raw signal sampling frequencyfft_window=sampling_rate*4# spectrum calculation window lengthprocess_win_rate=5# spectrum calculation frequencyspectrum_math=SpectrumMath(sampling_rate,fft_window,process_win_rate)Optional initializationAdditional spectrum settings:Pythonbord_frequency=50# upper bound of frequencies for spectrum calculationnormalize_spect_by_bandwidth=True# normalization of the EEG spectrum by the width of the wavebandspectrum_math.init_params(bord_frequency,normalize_spect_by_bandwidth)Waves coefficients:Pythondelta_coef=0.0theta_coef=1.0alpha_coef=1.0beta_coef=1.0gamma_coef=0.0spectrum_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:Pythonspectrum_math.set_hanning_win_spect()# by Hanning (by default)spectrum_math.set_hamming_win_spect()# by HammingInitializing a data array for transfer to the libraryArray of double values with length less or equals then 15 * saignal sampling frequency.TypesRawSpectrumDataStructure 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.WavesSpectrumDataStructure containing the waves values.Absolute frequency values (double type):delta_rawtheta_rawalpha_rawbeta_rawgamma_rawRelative (percent) values (double type):delta_reltheta_relalpha_relbeta_relgamma_relFFT band resolutionThe 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):Pythonspectrum_math.get_fft_bins_for_1_hz()Spectrum calculation in iterative modeAdding and process data:Pythonsamples=[0for_inrange(sample_count)]spectrum_math.push_data(samples)spectrum_math.process_data()Getting the results:Pythonraw_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.Pythonspectrum_math.set_new_sample_size()Spectrum calculation for a single arrayCompute spectrum:Pythonsamples=[0for_inrange(sample_count)]spectrum_math.compute_spectrum(samples)Getting the results:Pythonraw_spectrum_data=spectrum_math.read_raw_spectrum_info()waves_spectrum_data=spectrum_math.read_waves_spectrum_info()Finishing work with the libraryPythondelspectrum_lib