How to plot spectrogram on Matlab App Designer with UIAxes?

조회 수: 49 (최근 30일)
a bc
a bc 2017년 11월 26일
댓글: Andrew Cline 2022년 12월 1일
Hello, I'm trying to use spectrogram function to plot spectrogram with Matlab App Designer, not the old GUI. This means I got uifigures and uiaxes, not figure and axes in the old GUI system. There are some answers about using spectrogram function in the old GUI system, which are using axes() function to set current axes, unfortunately, I haven't seen something about using spectrogram function in App Designer, can anyone help, plz?
  댓글 수: 1
a bc
a bc 2017년 11월 26일
TO make this clear, I try to use the Matlab spectrogram function in App Designer to plot spectrogram
s=spectrogram(x)
The keypoint is use this function to plot with UIFigures and UIAxes. I hope it's clear now. Any advice will be appreciated!

댓글을 달려면 로그인하십시오.

채택된 답변

Birdman
Birdman 2017년 11월 26일
편집: Birdman 2017년 11월 26일
Imagine you have a 2D axes and you hold it in a variable:
axesSpec=app.UIAxes;
Then, I assume that you already obtain the output of spectrogram, and which actually means the psd of a signal, you need to plot it on a semilogx plot. Consider the following notation(assume that y and f are the outputs and frequency for the signal respectively):
axesSpec.XScale='log';
plot(axesSpec,f,y);
This notation should do it. Hope I am clear.
  댓글 수: 8
Jan Kuttruff
Jan Kuttruff 2018년 4월 12일
Hello, I also try to plot my spectrogram into my App like your ideal_result.png . I have tried to understand the code lines of Birdman but I don't get it how to get it right for the result like the ideal_result. Can you show how you have done it?
a bc
a bc 2018년 4월 13일
편집: a bc 2018년 4월 13일
Hi Jan
If you use the new MATLAB App Designer to build your App, I can't find the solution to draw spectrogram like ideal_result.png till the time I raised the question. So finally I switched to the old GUI tool to build my App and draw ideal_result.png successfully. Since the new MATLAB App Designer is far from mature, I recommend you to use the old GUI tool for full functionality for now.
If so, refer to my_github_project for the implemention detail on the old GUI tool.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

John
John 2021년 5월 12일
편집: John 2021년 5월 12일
Please see below for an update using AppDesigner - Using 2021a
Requires signal processing toolbox - but spectrogram outputs should be similar to pspectrum outputs
% dimensions of app.dat2plot = [1 2886144]
% Sampling frequency is 4kHz
[S,F,T] = pspectrum(transpose(app.dat2plot),4000,'spectrogram', 'FrequencyLimits',[0 50],'MinThreshold',-110);
imagesc(app.UIAxes2, T, flipud(F), rot90(log(abs(S')))); %plot the log spectrum
set(app.UIAxes2,'YDir', 'normal'); % flip the Y Axis
Outputs image below in AppDesigner
  댓글 수: 1
Andrew Cline
Andrew Cline 2022년 12월 1일
Thanks for this answer. Never would have figured this out myself.
Also, you can do this afterwards to fit it to the window
axis(app.UIAxes2,'tight')

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 时频分析에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!