-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from ywatanabe1989/develop
v1.1.0
- Loading branch information
Showing
39 changed files
with
1,780 additions
and
328 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,3 +28,10 @@ wheel | |
pybids | ||
scikit-image | ||
icecream | ||
Pyarrow | ||
ruamel.yaml | ||
pytest | ||
pytest-cov | ||
pytest-xdist | ||
pytest-env | ||
umap-learn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
#!/usr/bin/env python3 | ||
# Time-stamp: "2024-02-03 16:06:22 (ywatanabe)" | ||
# Time-stamp: "2024-03-08 20:48:06 (ywatanabe)" | ||
|
||
from . import dsp | ||
from . import general | ||
from . import general as gen | ||
from . import gists, io, linalg, ml, nn, plt, resource, stats | ||
from . import gists, io, linalg, ml, nn, os, plt, resource, stats | ||
from .general.debug import * | ||
|
||
__copyright__ = "Copyright (C) 2021 Yusuke Watanabe" | ||
__version__ = "1.0.1" | ||
__copyright__ = "Copyright (C) 2024 Yusuke Watanabe" | ||
__version__ = "1.1.0" | ||
__license__ = "GPL3.0" | ||
__author__ = "ywatanabe1989" | ||
__author_email__ = "[email protected]" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ywatanabe@ywata-note-win.2006005053169024153 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
# Time-stamp: "2024-02-21 08:58:35 (ywatanabe)" | ||
|
||
import torch | ||
|
||
|
||
def psd_torch(signal, samp_rate): | ||
""" | ||
# Example usage: | ||
samp_rate = 480 # Sampling rate in Hz | ||
signal = torch.randn(480) # Example signal with 480 samples | ||
freqs, psd = calculate_psd(signal, samp_rate) | ||
# Plot the PSD (if you have matplotlib installed) | ||
import matplotlib.pyplot as plt | ||
plt.plot(freqs.numpy(), psd.numpy()) | ||
plt.xlabel('Frequency (Hz)') | ||
plt.ylabel('Power/Frequency (V^2/Hz)') | ||
plt.title('Power Spectral Density') | ||
plt.show() | ||
""" | ||
# Apply window function to the signal (e.g., Hanning window) | ||
window = torch.hann_window(signal.size(-1)) | ||
signal = signal * window | ||
|
||
# Perform the FFT | ||
fft_output = torch.fft.fft(signal) | ||
|
||
# Compute the power spectrum (magnitude squared of the FFT output) | ||
power_spectrum = torch.abs(fft_output) ** 2 | ||
|
||
# Normalize the power spectrum to get the PSD | ||
# Usually, we divide by the length of the signal and the sum of the window squared | ||
# to get the power in terms of physical units (e.g., V^2/Hz) | ||
psd = power_spectrum / (samp_rate * (window**2).sum()) | ||
|
||
# Since the signal is real, we only need the positive half of the FFT output | ||
# The factor of 2 accounts for the energy in the negative frequencies that we're discarding | ||
psd = psd[: len(psd) // 2] * 2 | ||
|
||
# Adjust the DC component (0 Hz) and Nyquist component (if applicable) | ||
psd[0] /= 2 | ||
if len(psd) % 2 == 0: # Even length, Nyquist freq component is included | ||
psd[-1] /= 2 | ||
|
||
# Frequency axis | ||
freqs = torch.fft.fftfreq(signal.size(-1), 1 / samp_rate)[: len(psd)] | ||
|
||
return freqs, psd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.