eddie-water / SubCraft

0 stars 0 forks source link

Sharpen (normalize?) the higher frequency magnitudes in the scalogram plot #10

Open eddie-water opened 2 months ago

eddie-water commented 2 months ago

UPDATE 10/10/2024 This example from matplotlib looks really promising and I can't believe I haven't seen this until now: https://matplotlib.org/stable/gallery/statistics/time_series_histogram.html#sphx-glr-gallery-statistics-time-series-histogram-py

At the bottom they do logarithmic vs linear color scale and the logarthmic one looks way better

I think this: image

... is going to fix how the upper frequency data is way more pale than the lower frequencies colors.

Look at this example of a Time Series plots and their Continuous Wavelet Transform Plot aka CWT Plot aka Scalogram

image

Notice here how each Time Series has differing frequencies and time supports and how the last one is the sum of all of them. Even though each signal has equal amplitudes in the Time Series, it doesn't look like they do in the CWTs. The color intensity gets weaker the higher you go in frequency. To accurately visualize the signal, shouldn't they be equal in color intensity?

I think the solution is that the frequency goes up, the power of those signals should be mapped logarithmically spaced colors? Right? Does that make sense or am I just stoned...? What does log space colors even mean.... hmmm need to find a better way of making that make sense. Right now I'm kind of just going on a hunch and need to try it out.

Anyways, in the example, I think they link the color scale logarithmically to the "walk" of the signal variation. I think I need to just link the color scale (effectively is my z-axis except its color) kinda like I logarithmically plot the frequency axis (y-axis). Looking at it like that... does that make sense? I'm not sure, but I think it does. Right? If I plot the y-axis on a log scale, I don't see why I couldn't do it the z-axis, as long as its in my favor to do so.

Still don't know why the intensity drops off like that in the first place...

ORIGINAL POST: I think there is a need to sharpen the higher frequency activity.

This is from plot_cwt_example.py: https://github.com/eddie-water/lightbeats/issues/3#issuecomment-2212690990 Three individual sinusoids of equal magnitudes and different amounts of time support have been summed up together into a resultant signal. The signal has been analyzed using the wavelet.py module and its scalograms have been plotted right underneath the signal plotted as a time series.

For some reason the data points corresponding to the higher frequency components are much more dull than the lower frequency components of the resultant signal. A duller color implies that the magnitudes of these contributions are weaker/less significant the brighter data points. This is weird because all the components were generated using the same magnitude so they should be the same brightness.

eddie-water commented 2 months ago

I think I saw in a Mike X Cohen video on youtube that the you have to "normalize" the data in a logarithmic fashion for some reason. I'm going to try and find the video. I think it was the one in his freq-time analysis video series where he first plotted the continuous wavelet transform using wavelets of different "number of scales" (which I'm really hoping is the same concept of Matlab's notion of "number of voices"). As far as I understand it, the number of voices controls the scale resolution. The scale resolution controls how dilated each wavelet is going to be. Therefore, it also controls the resolution of the frequencies being analyzed. Anyways if you have a scale resolution that is a logarithmic constant, the frequency resolution will be have a logarithmic variable length (which is what we want) because the conventional musical scale has logarithmic frequencies (doubles every 12 "steps"). That was a lot of rambling but I had to write that thought stream out and see if it makes sense later when I come back to this.

Anyways I think before he got to that point, he said you could multiply or divide all the coefficients logarithmically with its frequency to sort of "normalize" the values. Basically I just want the contribution of each sinusoid component to be on an even playing field.

eddie-water commented 2 months ago

I can't find the video where I first found it but this seems promising https://www.youtube.com/watch?v=4m3d5eQzCYk&list=PLn0OLiymPak2BYu--bR0ADNBJsC4kuRWs&index=11