Esempio n. 1
0
def test_iir_filter():
    sign = SignalGenerator(sampling_freq=50, signal_freq=2, signal_ampl=25, signal_length=10)
    sign.add_noise(3.5)
    data = sign.get_data_into_pandas_format()
    nb_lin, nb_col = data.shape

    assert nb_lin == 501
    assert nb_col == 2

    iir_design = iirFilter(sampling_freq=50,
                           low_freq=3,
                           high_freq=4,
                           attenuation_pass=1,
                           attenuation_stop=60,
                           typ='cheby2')
    freq_response = iir_design.compute_frequency_response(sampling_res=.1, display=False)
    nb_lin_fr, _ = freq_response.shape
    assert nb_lin_fr == 250

    filter_out = iir_design.apply_filter(data)
    nb_lin_filt, nb_col_filt = filter_out.shape

    assert nb_lin_filt == 501
    assert nb_col_filt == 2
    return None
def test_signal_generator_use_case_2():
    sign = SignalGenerator(sampling_freq=250, signal_freq=10, signal_ampl=25, signal_length=1)
    sign.add_noise(3.5)
    data = sign.get_data_into_pandas_format()

    nb_lin, nb_col = data.shape
    assert nb_lin == 251
    assert nb_col == 2
    return None
def test_signal_generator_use_case_1():
    sign = SignalGenerator(sampling_freq=250, signal_length=2,
                           multiple_sine=[(2.5, 5), (5, 3), (2, 7)])
    sign.add_noise(3.5)
    data = sign.get_data_into_pandas_format()

    nb_lin, nb_col = data.shape
    assert nb_lin == 501
    assert nb_col == 2
    return None
Esempio n. 4
0
def main():

    sign1 = SignalGenerator(sampling_freq=500,
                            signal_length=10,
                            multiple_sine=[(2, 5), (50, 25), (20, 10)])
    sign1.add_noise(5)
    data1 = sign1.get_data_into_pandas_format()
    data1.plot()
    spec1 = SpectralAnalysis(sign1)
    #    data2 = spec1.compute_fourier_spectrum()
    #    data2.plot()
    #    data1.plot()

    #    data3 = spec1.compute_spectral_density_using_periodogram(typ='dB')
    #    print(list(data3))
    #    data4 = data3[['raw_data(spectral)', 'noise_data(spectral)']]
    #    data4.plot()
    #    data3.plot()

    data5 = spec1.compute_spectral_density_using_welch(sampling_res=.5)
    print(data5.head(3))
    data5.plot()
    #    plt.show()

    dat = iirFilter(sampling_freq=50,
                    low_freq=5,
                    high_freq=10,
                    attenuation_pass=1,
                    attenuation_stop=80,
                    typ='cheby2')

    dat.compute_frequency_response(sampling_res=.05, display=False)
    data6 = dat.apply_filter(data1)
    data6.plot()

    dat2 = firFilter(num_taps=50,
                     cut_off=1.5,
                     width=5.0,
                     window=('gaussian', 11),
                     fs=50)
    did = dat2.compute_frequency_response(sampling_res=.05, display=False)
    dodo = dat2.apply_filter(data1)
    dodo.plot()
    print(did.head(5))
    plt.show()
Esempio n. 5
0
def test_compute_fourier_spectrum():
    sign = SignalGenerator(sampling_freq=250,
                           signal_length=10,
                           multiple_sine=[(2.5, 5), (5, 3), (2, 7)])
    sign.add_noise(3.5)
    data = sign.get_data_into_pandas_format()
    spec = SpectralAnalysis(sign)
    data_spec = spec.compute_fourier_spectrum()
    data_spec_dB = spec.compute_fourier_spectrum(typ='dB')

    nb_lin, nb_col = data.shape
    assert nb_lin == 2501
    assert nb_col == 2

    nb_l_spec, nb_c_spec = data_spec.shape
    assert nb_l_spec == 1250
    assert nb_c_spec == 2

    nb_l_spec_dB, nb_c_spec_dB = data_spec_dB.shape
    assert nb_l_spec_dB == 1250
    assert nb_c_spec_dB == 4
    return None
Esempio n. 6
0
def test_fir_filter():
    sign = SignalGenerator(sampling_freq=50, signal_freq=2, signal_ampl=25, signal_length=10)
    sign.add_noise(3.5)
    data = sign.get_data_into_pandas_format()
    nb_lin, nb_col = data.shape

    assert nb_lin == 501
    assert nb_col == 2

    fir_design = firFilter(num_taps=50,
                           cut_off=3.,
                           width=1.0,
                           window=('gaussian', 11),
                           fs=50)
    freq_response = fir_design.compute_frequency_response(sampling_res=.1, display=False)
    nb_lin_fr, _ = freq_response.shape
    assert nb_lin_fr == 250

    filter_out = fir_design.apply_filter(data)
    nb_lin_filt, nb_col_filt = filter_out.shape

    assert nb_lin_filt == 501
    assert nb_col_filt == 2
    return None