Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in PSD Plotting: Incorrect dB Scaling for Amplitude in MNE #13034

Closed
DingkunLiu opened this issue Dec 17, 2024 · 2 comments · Fixed by #13036
Closed

Bug in PSD Plotting: Incorrect dB Scaling for Amplitude in MNE #13034

DingkunLiu opened this issue Dec 17, 2024 · 2 comments · Fixed by #13036
Assignees

Comments

@DingkunLiu
Copy link

DingkunLiu commented Dec 17, 2024

Description

When plotting the Power Spectral Density (PSD) using mne.time_frequency.Spectrum.plot() or related functions with dB=True and amplitude=True, the decibel scaling appears to be incorrect. This issue arises because the conversion between power and amplitude dB follows different logarithmic relationships, and amplitude requires a factor of 20 in the scaling, whereas power uses a factor of 10 (implement here).

Example to reproduce

import mne
import numpy as np

# Generate sample data
sfreq = 1000  # Sampling frequency
times = np.linspace(0, 2, 2 * sfreq)
data = np.sin(2 * np.pi * 10 * times)  # 10 Hz sine wave
info = mne.create_info(ch_names=['sin_wave'], sfreq=sfreq, ch_types='eeg')
raw = mne.io.RawArray([data], info).load_data()

# Plot PSD with dB=True
raw.plot_psd(dB=True, amplitude=True)

Expected result

The peak at 10Hz is expected to be $120=20 * log(10^6)$, but the plot returns 60.

Copy link

welcome bot commented Dec 17, 2024

Hello! 👋 Thanks for opening your first issue here! ❤️ We will try to get back to you soon. 🚴

@drammock
Copy link
Member

thanks for the very clear example @DingkunLiu! Fix is in #13036

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants