Calculate spectrogram with logarithmic-spaced frequencies
24 views (last 30 days)
Show older comments
Commented: William Rose on 23 Dec 2022
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.
More Answers (1)
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.
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.
Find more on Time-Frequency Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!