Contourf plot Yscale log2 vs log10
조회 수: 11 (최근 30일)
이전 댓글 표시
I have frequencies ranging from 2-194 in a base-2 logarithmic spacing (10 voices per octave) like this:
frex = 2.^([10:76]/10);
I want to plot a spectrogram with contourf using them and make the yaxis logarithmically scaled. I know that the below command does this for base-10 log, but how can I do it for base-2 log? I saw some other questions asking similar, but I don't think the answers actually changed the scale of the y-axis. One person said that log10 and log2 scale shape will be the same. Is that correct?
set(gca,'YScale','log')
댓글 수: 0
채택된 답변
Star Strider
2022년 7월 14일
You can change the base of the logarithm by dividing it by the desired base, then use the appropriate code to change the tick labels:
frex = 2.^((10:76)/10)
frex2 = log(frex)/log(2)
N = 1024;
n = 0:N-1;
w0 = 2*pi/5;
x = sin(w0*n)+10*sin(2*w0*n);
% Compute the short-time Fourier transform using the function defaults. Plot the spectrogram.
figure
spectrogram(x,'yaxis');
figure
spectrogram(x,'yaxis')
Ax = gca;
yt = Ax.YTick;
Ax.YTickLabel = log(yt)/log(2);
This example is from the spectrogram documentation, with my changes to the y-axis labels.
.
댓글 수: 6
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!