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

Troubles with spectrogram frequency Y-scale #2

Open
Rinkode opened this issue Oct 28, 2024 · 4 comments
Open

Troubles with spectrogram frequency Y-scale #2

Rinkode opened this issue Oct 28, 2024 · 4 comments

Comments

@Rinkode
Copy link

Rinkode commented Oct 28, 2024

Hello Spectrum Viewer team,

I'm a PhD student using the Open Ephys GUI (v0.6.7 (Plugin API v8)) to record LFP signals, and I’ve encountered a potential issue with the Spectrum viewer plugin's frequency scaling on my two Windows 10 laptops. (version 0.2.0-API8, 2023-04-11)

Since I'm in France, the power line frequency is 50 Hz, with harmonics expected at 100 Hz, etc. However, in real-time analysis with the Spectrum viewer in spectrogram mode, changing the Y-axis frequency scale doesn’t seem to impact the displayed power as expected. I’ve attached sample data where I've alligned 3 different timescale displays, first alligned in full screen, then with frequency alligned (with noise bands in orange).

Spectrum viewer spectograms exemples at different freq range

You can observe that:

  • The noise bands appear misaligned with 50 Hz when adjusting the frequency scale.
  • These noise bands sometimes align inconsistently with various frequencies, depending on the scale.

I would expect the Spectrum viewer to display frequency bands consistently, reflecting the 50 Hz power line noise and harmonics, even when the Y-axis frequency scale is adjusted.

Additional Feedback:
If you’re considering feature updates, it would be incredibly useful to have options to adjust the power colorscale and timescale in the Spectrum viewer to better assess signal stability over time.

Thanks for your help and any insights you may have!

Best regards,
Rinkode

@anjaldoshi
Copy link

Hi @Rinkode,

Thanks for the detailed report. We'll take a closer look at it and update you as soon as we have figured out what's going on.

@anjaldoshi
Copy link

Hi @Rinkode,

I’ve had some time to work on this issue. I tested the plugin with sine wave test data that included various sine wave frequencies (50Hz, 60Hz, 70Hz, etc.). I noticed that changing the Y-axis frequency range didn’t update the output correctly in either the spectrogram or power spectrum view. After some debugging, I found a bug in the code that failed to update the incoming data’s buffer size when changing the frequency range (since each frequency range requires a separate window size). Once I resolved this issue, I observed that the power was plotted correctly when changing the frequency range, and the 50Hz sine wave correctly aligned with the y-axis.

I’ve updated the plugin and released a new version (v0.2.1). To update, please remove the plugin from the signal chain, launch Plugin Installer, update the plugin, and then re-insert it into the signal chain. Finally, test the plugin to ensure everything looks correct.

Thanks again for bringing this to our attention. Please let me know if you need any further assistance.

@Rinkode
Copy link
Author

Rinkode commented Jan 15, 2025

Thank you for fixing this issue!

I updated the plugin, tried different scales and the 50Hz from my data is now following the scale update.
Even if it seems there is a few seconds delay between the displayed spectrum and the signal, I'm confident your plugin will now be useful to assess the global spectrum obtained from my real-time data.

Regarding other questions about the plugin, I was wondering how the color scale of the spectrogram is calculated, if it is dynamically updated or not. I would like to see if there is a drift of my signal over time or not, which would not be visible if the color scale updates constantly. Can you clarify this point for me ?

Thank you for your help.

Best regards,
Rinkode

@anjaldoshi
Copy link

Thanks for confirming that the fix is working. Regarding the spectrogram color scale, it currently dynamically updates based on the current power values. It determines the minimum and maximum power values and uses them to map all other values between 0 and 1. This value is then used to set the hue and brightness of the color.

Here’s the relevant code:

void CanvasPlot::drawSpectrogram(std::vector<float> chanData)
{
auto imageWidth = spectrogramImg->getWidth() - 1;
auto imageHeight = spectrogramImg->getHeight();
// first, shuffle our image rightwards by 1 pixel..
spectrogramImg->moveImageSection (1, 0, 0, 0, imageWidth, imageHeight);
// find the range of values produced, so we can scale our rendering to
// show up the detail clearly
auto powerRange = juce::FloatVectorOperations::findMinAndMax (chanData.data(), chanData.size());
for (auto y = 0; y < imageHeight - 1; ++y)
{
auto skewedProportionY = 1.0f - (float) y / (float) imageHeight;
auto dataIndex = (size_t) jlimit (0, (int)(chanData.size() - 1), (int) (skewedProportionY * (chanData.size() - 1)));
float logPower = chanData[dataIndex] > 0.0f ? std::log10(1.0f + chanData[dataIndex]) : 0.0f;
float logMax = powerRange.getEnd() > 0.0f ? std::log10(1.0f + powerRange.getEnd()) : 0.0f;
float logMin = powerRange.getStart() > 0.0f ? std::log10(1.0f + powerRange.getStart()) : 0.0f;
auto level = juce::jmap (logPower, logMin, juce::jmax(logMax, 1e-5f), 0.0f, 1.0f);
spectrogramImg->setPixelAt (0, y, juce::Colour::fromHSV (level, 1.0f, level, 1.0f));
}
repaint();
}

Regarding feature updates, we can consider adding an option to disable the dynamic color scale update if you prefer that. We’ll also work on adding the color scale and time scale features you requested. Currently, we’re focused on Open Ephys GUI v1.0, which we plan to release soon. We’ll work on incorporating these features into Spectrum Viewer after the v1.0 release.

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

No branches or pull requests

2 participants