You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -439,23 +439,58 @@
if np.any(np.iscomplex(amplitude)) or not is_real_value_transform:
spectrum_array = np.fft.fft(amplitude, size)
if frequency is None or isinstance(frequency, int):
np_frequency = np.fft.fftfreq(amplitude.size, d=time.sample)
spectrum_array = spectrum_array[np_frequency.argsort()]
np_frequency = np.sort(np_frequency)
+ frequency = axis.Axis.get_from_array(np_frequency)
else:
spectrum_array = np.fft.rfft(amplitude, size)
if frequency is None or isinstance(frequency, int):
np_frequency = np.fft.rfftfreq(amplitude.size, d=time.sample)
+ frequency = axis.Axis.get_from_array(np_frequency)++ return spectrum.Spectrum(frequency, spectrum_array)+++def get_frequency_axis(+ time_size: int, + time_sample: float, + is_complex_data: bool = False+) -> 'Frequency':+ """Get frequency axis from size and sample of time.++ Function for getting a frequency axis using size and sample of time.+ If the data is complex, then the frequency axis will contain negative part.++ Args:+ time_size (int): size of time++ time_sample (float): sample of time++ is_complex_data (bool): If the data is complex, then the frequency+ axis will contain a negative part. If not, then vice versa.+ Defaults to False.++ Return:+ Axis: frequency axis.++ """+ if is_complex_data:+ np_frequency = np.fft.fftfreq(time_size, d=time_sample)+ np_frequency = np.sort(np_frequency)+ else:+ np_frequency = np.fft.rfftfreq(time_size, d=time_sample)
frequency = axis.Axis.get_from_array(np_frequency)
- return spectrum.Spectrum(frequency, spectrum_array)+ return frequency+
def spectrum2signal(
relation_data: relation.Relation,
time: Optional[Union['Time', int]] = None,
time_start: Union[float, None] = None,
) -> 'signal.Signal':
"""Inverse Fourier Transform.
@@ -255,14 +255,42 @@
"""
sp_other = _input2spectrum(other)
return type(self).get_from_amplitude_phase(
self.get_amplitude_spectrum(),
self.get_phase_spectrum() - sp_other.get_phase_spectrum(),
)
+ @staticmethod+ def get_frequency_axis_from_time(+ time: Axis, + is_complex_data: bool = False+ ) -> Axis:+ """Get frequency axis from axis of time.++ Function for getting a frequency axis using time axis.+ If the data is complex, then the frequency axis will contain negative + part.++ Args:+ time (Axis): axis of time.++ is_complex_data (bool): If the data is complex, then the frequency+ axis will contain a negative part. If not, then vice versa.+ Defaults to False.++ Return:+ Axis: frequency axis.++ """+ return default_methods.get_frequency_axis(+ time.size,+ time.sample,+ is_complex_data,+ )+
@classmethod
def get_from_amplitude_phase(
cls: Type[SP], amplitude_spectrum: Relation, phase_spectrum: Relation
) -> SP:
"""Calculate of the spectrum from the amplitude and phase spectrum.
The spectrum is calculated through the amplitude and phase spectrum
@@ -13,15 +13,15 @@
extras_require = \
{':python_version >= "3.6" and python_version < "3.8"': ['numpy<=1.19',
'scipy>=1.2,<1.8'],
':python_version >= "3.8"': ['numpy>1.19', 'scipy>=1.8']}
setup_kwargs = {
'name': 'signal-design',
- 'version': '0.2.2',+ 'version': '0.3.0',
'description': 'The project for creation and analysis signals.',
'long_description': '# signal-design\n\nSimple way to create signals.\n\n## The project is intended for designing signals.\n\nThe package is intended to create and develop signals of\nvarying complexity.\n\nThe project can be used both for educational and work purposes.\n\nIt is convenient to use [`Jupyter Lab`](https://jupyter.org/) or\n[`Jupyter Notebook`](https://jupyter.org/) to speed up the development\nof signals, to compare their parameters with other signals,\nand to visualize them.\n\nThe project is designed so that you can easily change the creation of\nsignals.\n\nIn addition, documentation consist tutorial how to work with library\nand examples of ready-made signals. You can write own signal creation.\n\n# Installation\n\nTo install use:\n\n```bash\n$ pip install signal-design\n```\n\nor using `poetry`\n\n```bash\n$ poetry add signal-design\n```\n\nAlso you can clone or load project from [GitHub](https://github.com/Omnivanitate/signal-design),\nand install requirement packages using the\n\n```bash\n$ pip install -r requirements/build.txt\n```\n\nor if you want develop, use\n\n```bash\n$ pip install -r requirements/dev.txt\n\n```\n\nor\n\n```bash\n$ poetry install\n```\n\nor coping pieces of code and create your own.\n\n## Usage\n\nThe project is a library. Working with it is the same as with\nother third-part libraries of the python language. \nAn example of how to include the library is described\n[here](https://docs.python.org/3/tutorial/modules.html).\n\nThe library consists sub-modules:\n\n- `signal_design.core` - contains basic classes `MathOperation` and `RelationProtocol`.\n- `signal_design.exc` - contains exceptions.\n- `signal_design.axis` - contains class `Axis`\n- `signal_design.relation` - contains class `Relation`\n- `signal_design.signal` - contains class `Signal`\n- `signal_design.spectrum` - contains class `Spectrum`\n- `signal_design.default_methods` - contains default methods for class above.\n\nFor convenient base classes:\n`Axis`, `Relation`, `Signal`, `Spectrum` - can be imported from\nthe `signal_design` module.\n\nFor example:\n\n```python\nfrom signal_design import Signal\n```\n\n### Quick start. Simple work flow.\n\nBelow is a simple example of creating a signal and visualizing it.\nA more extended description of the work of the library in the documentation.\nOther examples are contained in the documentation contains in _Tutorial_\nsection.\n\nFor the following code [`Matplotlib`](https://matplotlib.org/) need be used\nto visualize a result of work. But `Matplotlib` can be replaced with another\nlibrary that you use.\n\n```python\nimport numpy as np\nimport matplotlib.pyplot as plt\n\nfrom signal_design import Axis, Signal\n\ntime = Axis.get_using_end(start=0., end=10., sample=0.01)\namplitude = np.sin(2*np.pi*time.array)\nsignal = Signal(time, amplitude)\n\nplt.plot(*signal.get_data())\nplt.xlabel(\'Time, s\')\nplt.ylabel(\'Amplitude\')\nplt.title(\'Sin 1Hz\')\n```\n\nResult:\n\n\n\n## Credits\n\n`signal-design` was created with \n[`numpy`](https://numpy.org/) \n[`scipy`](https://scipy.org/)\n',
'author': 'Omnivanitate',
'author_email': '[email protected]',
'maintainer': 'None',
'maintainer_email': 'None',
'url': 'https://github.com/Omnivanitate/signal-design',