Plotting a spectrogram with y axis values as whole numbers and time set to seconds
26 ビュー (過去 30 日間)
古いコメントを表示
Hi,
i want to plot the spectrogram of an audio file using spectrogram function. However, it seems like i can't set the x axis to seconds (it appears as 0.1 ... 1.1 Minutes)- i want the x axes Tick set to 10 seconds Ticks. Also, i want the values on y axis to be shown as whole numbers instead of powers to the base 10 and i want the frequency in Hz instead of kHz... can anybody help me? Heres the code:
[signal, sampleRate] = audioread(filename);
FrontLeft = signal(:, 1); % Front Left
Center = signal(:, 2); % Center
FrontRight = signal(:, 3); % Front Right
SurroundLeft = signal(:, 4); % Surround Left
SurroundRight = signal(:, 5); % Surround Right
LFE = signal(:, 6); % LFE
N = length(signal);
t = (0:N-1)/sampleRate;
N/sampleRate;
figure(1);
fighandle = figure(1);
fighandle.Color = [1 1 1];
axesHandle = gca;
%Spektrogramm
spectrogram(FrontLeft, 128, 64, 128, sampleRate, 'yaxis');
axesHandle.YScale = "log";
1 件のコメント
dpb
2023 年 8 月 9 日
Attach the audio file if expect anybody to try to figure out what is what...nothing can be done with an image that can't even read.
The log10 display is owing to you have set .YScale='log'; it's not at all clear what you mean by _" i want the values on y axis to be shown as whole numbers", the results of the spectrogram are going to be what they turn out to be; it may not be possible to make the display integral and show the results.
採用された回答
その他の回答 (1 件)
Paul
2023 年 8 月 9 日
Hi Felix,
Return the output arguments of spectrogram and then you can make any plot you want with any units in any of the dimensions, customize the ticks, etc.
2 件のコメント
Paul
2023 年 8 月 10 日
Hard for me to day without being able to recreate the problem. If you want, you can attach the .wav file using the paperclip icon in the Insert portion of the ribbon.
I played around with some example data and had trouble with imagesc, but I'm not familiar with that function. However, pcolor seemed to work fine, though I think (but I'm not sure) that there is a subtle difference between how pcolor and imagesc interpret where the data points are located relative to the four corners of each bin. Check the doc, or look for posts here on Answers, where I think it's been discussed.
Here's an example using pcolor.
rng(100);
fs = 100;
N = 2048;
t = (0:N-1)/fs;
x = 5*sin(2*pi*10*t) + randn(1,N);
x = x - mean(x);
[s,f,t] = spectrogram(x,[],[],[],fs,'yaxis');
figure
pcolor(t,f,10*log10(abs(s))),shading flat,colorbar
ylim([0.1 100])
set(gca,'YScale','log')
参考
カテゴリ
Help Center および File Exchange で Time-Frequency Analysis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!