Beispiel #1
0
    def __init__(self,
                 signal_in: np.ndarray,
                 wavelet_in: str = 'dog',
                 order: int = 2,
                 padding: str = 'none',
                 frequency_resolution: float = 0.5) -> None:
        """
        Parameters
        ----------
        signal_in : numpy.ndarray
            1D input signal.
        wavelet_in : str
            Wavelet function ('dog' or 'morlet').
        order : int
            Order of the wavelet function.
        padding : str
            Padding method ('zero', 'mirror', or 'none').
        frequency_resolution : float
            Wavelet space resolution in scale/frequency.

        Returns
        -------
        NoneType
            None
        """

        # save input data
        self.m_supported_wavelets = ['dog', 'morlet']

        # check supported wavelets
        if wavelet_in not in self.m_supported_wavelets:
            raise ValueError(f'Wavelet {wavelet_in} is not supported')

        if wavelet_in == 'dog':
            self._m_c_reconstructions = {2: 3.5987,
                                         4: 2.4014,
                                         6: 1.9212,
                                         8: 1.6467,
                                         12: 1.3307,
                                         16: 1.1464,
                                         20: 1.0222,
                                         30: 0.8312,
                                         40: 0.7183,
                                         60: 0.5853}
        elif wavelet_in == 'morlet':
            self._m_c_reconstructions = {5: 0.9484,
                                         6: 0.7784,
                                         7: 0.6616,
                                         8: 0.5758,
                                         10: 0.4579,
                                         12: 0.3804,
                                         14: 0.3254,
                                         16: 0.2844,
                                         20: 0.2272}
        self.m_wavelet = wavelet_in

        if padding not in ['none', 'zero', 'mirror']:
            raise ValueError('Padding can only be none, zero or mirror')

        self._m_data = signal_in - np.ones(len(signal_in)) * np.mean(signal_in)
        self.m_padding = padding
        self.__pad_signal()
        self._m_data_size = len(self._m_data)
        self._m_data_mean = np.mean(signal_in)

        if order not in self._m_c_reconstructions:
            raise ValueError('Wavelet ' + str(wavelet_in) + ' does not support order '
                             + str(order) + ". \n Only orders: " +
                             str(sorted(self._m_c_reconstructions.keys())).strip('[]') +
                             " are supported")
        self.m_order = order
        self._m_c_final_reconstruction = self._m_c_reconstructions[order]

        # create scales for wavelet transform
        self._m_scales = autoscales(N=self._m_data_size,
                                    dt=1,
                                    dj=frequency_resolution,
                                    wf=wavelet_in,
                                    p=order)

        self._m_number_of_scales = len(self._m_scales)
        self._m_frequency_resolution = frequency_resolution

        self.m_spectrum = None
Beispiel #2
0
    def __init__(self,
                 signal_in,
                 wavelet_in='dog',
                 order=2,
                 padding="none",
                 frequency_resolution=0.5):
        """
        Constructor of the WaveletAnalysisCapsule
        :param signal_in: A 1d input signal
        :param wavelet_in: mother wavelet function can be either "dog" or "morlet"
        :type wavelet_in: str
        :param order: order of the mother wavelet function
        :param padding: padding strategy. Zero and mirror padding ara supported.
        :param frequency_resolution: wavelet space resolution in scale / frequency
        """

        # save input data
        self.m_supported_wavelets = ['dog', 'morlet']

        # check supported wavelets
        if wavelet_in not in self.m_supported_wavelets:
            raise ValueError('Wavelet ' + str(wavelet_in) +
                             ' is not supported')

        if wavelet_in == 'dog':
            self._m_c_reconstructions = {
                2: 3.5987,
                4: 2.4014,
                6: 1.9212,
                8: 1.6467,
                12: 1.3307,
                16: 1.1464,
                20: 1.0222,
                30: 0.8312,
                40: 0.7183,
                60: 0.5853
            }
        elif wavelet_in == 'morlet':
            self._m_c_reconstructions = {
                5: 0.9484,
                6: 0.7784,
                7: 0.6616,
                8: 0.5758,
                10: 0.4579,
                12: 0.3804,
                14: 0.3254,
                16: 0.2844,
                20: 0.2272
            }
        self.m_wavelet = wavelet_in

        if padding not in ["none", "zero", "mirror"]:
            raise ValueError("Padding can only be none, zero or mirror")

        self._m_data = signal_in - np.ones(len(signal_in)) * np.mean(signal_in)
        self.m_padding = padding
        self.__pad_signal()
        self._m_data_size = len(self._m_data)
        self._m_data_mean = np.mean(signal_in)

        if order not in self._m_c_reconstructions:
            raise ValueError(
                'Wavelet ' + str(wavelet_in) + ' does not support order ' +
                str(order) + ". \n Only orders: " +
                str(sorted(self._m_c_reconstructions.keys())).strip('[]') +
                " are supported")
        self.m_order = order
        self._m_c_final_reconstruction = self._m_c_reconstructions[order]

        # create scales for wavelet transform
        self._m_scales = autoscales(N=self._m_data_size,
                                    dt=1,
                                    dj=frequency_resolution,
                                    wf=wavelet_in,
                                    p=order)

        self._m_number_of_scales = len(self._m_scales)
        self._m_frequency_resolution = frequency_resolution

        self.m_spectrum = None
        return