How to do subplot using cwt()

조회 수: 54 (최근 30일)
Shengjie Gao
Shengjie Gao 2021년 3월 7일
편집: Jeremy Scholze 2022년 7월 29일
Hey, I would like to plot a 3*3 subplots containing 9 figures from cwt(). However, I found it impossible to do that by simply doing
subplot(3,3,1)
cwt(data1)
subplot(3,3,2)
cwt(data2)
My guess is that we have to manually extract the cwt features and plot by ourselves under the subplot(). If yes, could anyone share a sample code for this part? If not, what should I do to draw such a subplot?
Thank you very much!
  댓글 수: 3
Shengjie Gao
Shengjie Gao 2021년 3월 7일
Hey Walter,
Thank you for your quick reply. The code works but it did not show a 2 by 1 layout with each scalogram created by using cwt(). It only shows the last one, here in your case it will only deliver data2's result. I would like to show both data1 and data2's cwt result in one figure (2-by-1 layout) here. Could you tell me how to do that?
Walter Roberson
Walter Roberson 2021년 3월 7일
Ah, I see what you mean. The code specifically clears the current figure before plotting.
In some cases, the code creates two axes, but I have not figured out yet which cases that corresponds to.
The code is taking the wavelet transform information (what would normally be the first output) and abs() it, and effectively does an imagesc() of that.

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

채택된 답변

Monisha Nalluru
Monisha Nalluru 2021년 3월 11일
Hi Shengjie,
cwt() would support subplots only with complex valued input signals that will plot the analytic and anti-analytic parts into seperate subplot.
In all other case, the output of cwt can be used with surface,pcolor or image to produce similar plot
As an example
load mtlb
figure
subplot(211)
[wt1,f1] = cwt(mtlb,'bump',Fs);
pcolor(1:numel(mtlb),log2(f1),abs(wt1));
shading interp;
subplot(212)
[wt2,f2] = cwt(mtlb,Fs);
pcolor(1:numel(mtlb),log2(f2),abs(wt2));
shading interp
Example cwt supporting subplots for complex valued iput ,
load npg2006;
plot(npg2006.cx); hold on; grid on;
xlabel('Eastward Displacement (km)');
ylabel('Northward Displacement (km)');
plot(npg2006.cx(1),'^','markersize',11,'color','r',...
'markerfacecolor',[1 0 0 ]);
figure;
cwt(npg2006.cx,npg2006.dt);
Hope this helps!
  댓글 수: 2
Shengjie Gao
Shengjie Gao 2021년 3월 11일
Great! That works! Thank you very much!
Shengjie Gao
Shengjie Gao 2021년 3월 11일
Hey Monisha,
Just a quick follow-up. Could you tell me how to modify both the xy-axis to the time-frequency range and also add the colorbar based on the magnitude?
Really appreciate your help!

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

추가 답변 (1개)

Jeremy Scholze
Jeremy Scholze 2022년 7월 27일
편집: Jeremy Scholze 2022년 7월 29일
Option 1: My Solution
Use
[cfs, frq] = cwt(data,Fs);
tms = (0:numel(data)-1)/Fs;
to calculate the wavelet transform and then do
imagesc(tms,frq,abs(C)); c = colorbar; c.Label.String = 'Magnitude';
axis tight; shading flat;
xlabel('Time (s)')
ylabel('Frequency (Hz)')
set(gca,'yscale','log')
to generate the plot. Your axes will be screwed up and you won't have the frequency bounds area greyed out but it'll work.
Option 2: MATLAB's Solution (less efficient)
openExample('wavelet/PlotCWTScalogramInSubplotExample')
They address this issue. Just run this in your command window ^
Edit: My method is apparently WAY more efficient than using the surface command in MATLAB's solution. Would recommend imagesc before surface. surface crashed my computer. The axis controls in MATLAB's solution will still work with imagesc.

카테고리

Help CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by