Calculate spectrogram with logarithmic-spaced frequencies

19 views (last 30 days)
I'm trying to calculate a spectrogram where the frequencies are logarithmicaly spaced, instead of the usual linear.
I think my test script follows the documentation, but my two spectrograms are identical and are both clearly using linear frequency spacing.
Am I doing something wrong?
Attached is my test script and the data.
  3 Comments
William Rose
William Rose on 21 Dec 2022
Your quesiton is clear. You have provided plots that show what is odd. You have provided your code and you have provided your data. The code shows the issue in question, and does not have a ot of extraneous things going on which distract from the quesiton at hand. It would be great if all quesitons on this site were as well posed as yours.
dormant
dormant on 21 Dec 2022
Unfortunately, the code I provided doesn't run, because I forgot to specify one variable that is normally read in. But I appreciate your comments.

Sign in to comment.

Accepted Answer

dormant
dormant on 21 Dec 2022
Edited: dormant on 21 Dec 2022
After some more research, I think it's impossible to do what I want with the spectrogram function. I think it only works with a vector of linear-spaced frequencies.
I think I have to do what is called a Time Frequency Representation (TFR). I have got some python code that does this but it's beyond my comprehension. I've found some old MATLAB scripts (e.g. http://www.physics.lancs.ac.uk/research/nbmphysics/diats/tfr/).
The MATLAB cwt function (in the wavelet toolbox) seems to do what I want to do, so I'll try and explore that.

More Answers (1)

William Rose
William Rose on 21 Dec 2022
@dormant, I agree that the bottom plot in your example, which should have the frequencies evenly spaced on a log scale, appears to have frequencies that are evenly spaced on a linear scale, contrary to what you expect and what you want. The help for spectrogram, for the "f" option, says "Cyclical frequencies, specified as a vector. f must have at least two elements, because otherwise the function interprets it as nfft. The units of f are specified by the sample rate, fs." I think this means f should be specified as frequencies normalized by fs. (Which is interesting, since Matlab's filtering routines normalize frequencies by the Nyquist frequency.) Your specification of f is not normalized by fs. Perhaps your f vector is ignored because the values are not all less than 1, which they should be, according to the help quoted above.
  3 Comments
dormant
dormant on 22 Dec 2022
Edited: dormant on 22 Dec 2022
@William Rose and anyone else following this, here is the comparison between the spectogram and the scalogram (which seems to be the name of this plot using the cwt function).
detail:
I had to fiddle the scalogram to make the images appear similar - dividing each value in the scalogram by the square root of the frequency. I have no idea why this works.
The scalogram appears to have better resolution overall, but I need to read up more about wavelet stuff before I feel confident in its use.
William Rose
William Rose on 23 Dec 2022
@dormant, Thank you for shairng your results. I'm glad you like the scalogram.
Even with the scalogram, the frequencies still appear to be linearly spaced, not log-spaced. I say this because the scalogram plot with a logarithmic frequency axis shows finer divisions at higher frequencies than at lower frequencies. In this respect the scalogram plot is not diferent than the spectrogram plots in your original post, which you did not like, due to the linear spacing of frequency samples.
I agree with you that the scalogram appears to have better resolution (better time-bandwidth product) than the spectrogram. I would have to compare spectrograms and scalograms of signals with simple, well defined time-varying frequency content, before having confidence in this conclusion. I am not fond of wavelets due to the difficulty in interpreting the results, and because the mother wavelet choice is somewhat arbitrary and will influence the results.

Sign in to comment.

Categories

Find more on Time-Frequency Analysis in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!