Spectrogram time axis samples to actual time

7 ビュー (過去 30 日間)
Please delete
Please delete 2018 年 4 月 21 日
コメント済み: Rik 2022 年 6 月 21 日
Hi. I'm trying to plot the result of a spectrogram like: y-axis frequency and x-axis for time, but instead of time in seconds, it plots samples and I don't know how to convert samples to time. Normally, it would be Sample_number / Sampling_rate, but the original signal has 7813 samples and the spectrogram has only 961. Any ideas? Thank you.
  2 件のコメント
Rishikesh Shetty
Rishikesh Shetty 2022 年 4 月 14 日
Same issue here. Did you figure it out?
Please delete
Please delete 2022 年 4 月 15 日
Man, it's been 4 years since I asked the question. I think I've managed to solve or at least bypass the problem, but I can't remember how. I'm working in a totally different field now.

サインインしてコメントする。

採用された回答

Star Strider
Star Strider 2018 年 4 月 21 日

Include the sampling frequency, and the result is a time-frequency plot (rather than an index-frequency plot). See for example: Spectrogram and Instantaneous Frequency (link). Note that fs must be the fifth input to spectrogram. To input a sample rate and still use the default values of the preceding optional arguments, specify these arguments as empty, [].

  3 件のコメント
Star Strider
Star Strider 2018 年 4 月 21 日

I would simply change the filenames for each spectrogram your function creates by adding a number to the end, for example ‘spectrogram_001.ext’ etc., where ‘.ext’ determines how you want to save it (as .fig, .png, etc.). You can do that with sprintf, possibly saving the number as a persistent (link) variable inside the function, then updating it in each iteration if necessary.

I’m guessing what you’re doing, and my ‘solution’, such as it is, reflects that.

Rik
Rik 2022 年 6 月 21 日
Deleted comments:
Dear @Star Strider, Thank you for your answer. Unfortunately, I was doing this already with no luck. My piece of code is
window=kaiser(128,18);
noverlap=120;
freq=128;
fs=50e10;
sp=spectrogram(signal,window, noverlap, freq,fs,'yaxis');
imagesc(abs(sp))
EDIT: it works if i call
spectrogram(signal,window, noverlap, freq,fs,'yaxis')
but because I integrate it in another function, when I plot it with "imagesc" it doesn't display properly. Any ideas?
How do I do this function-in-function save? Alongside with "spectrogram" being called inside my created function, I'm doing additional processing and I must call this function for 100 signals. It's rather tedious to manually save each figure.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTime-Frequency Analysis についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by