一个示例子,功率谱部分没有绘制,自己完成吧
- % cwt_test
- clear all
- close all
- clc
-
- %%
- Ts = 0.001;
- Fs = 1/Ts;
- f1 = 20;
- f2 = 50;
- f3 = 100;
-
- dt = 0.2;
- t1 = (0:Ts:dt-Ts) + 0;
- t2 = (0:Ts:dt-Ts) + dt;
- t3 = (0:Ts:dt-Ts) + 2*dt;
-
- y1 = sin(2*pi*f1*t1);
- y2 = sin(2*pi*f2*t2);
- y3 = sin(2*pi*f3*t3);
-
- t = [t1 t2 t3];
- y = [y1 y2 y3];
-
- subplot(4,4,[2,3,4])
- plot(t,y)
- xlim([t(1) t(end)])
- ylim([min(y) max(y)])
- xlabel('时间t')
- ylabel('信号y(t)')
- title('原始信号')
-
- %%
- scale = 1:50;
- cw2 = cwt(y,scale,'morl');
- %%
- subplot(4,4,[5,9,13])
- subplot(4,4,[6,7,8,10,11,12,14,15,16])
- [X,Y] = meshgrid(t,5/(2*pi)./scale*Fs);
- mesh(X,Y,abs(cw2))
- title('时频图')
- xlabel('时间')
- ylabel('频率')
- xlim([t(1) t(end)])
- set(gca,'ylim',[0,max(max(Y))])
- set(gca,'YScale','log')
复制代码
|