-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanayze.m
79 lines (42 loc) · 1.01 KB
/
anayze.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
clc
clear all;
filename='C4_fl.wav';
[y,fs]=audioread(filename,[1,44100]);
t=linspace(0,length(y)/fs,length(y));
figure
plot(t, y)
% 连续小波变换时频图
wavename='cmor3-3';
totalscal=2048;
Fc=centfrq(wavename); % 小波的中心频率
c=2*Fc*totalscal;
scals=c./(1:totalscal);
f=scal2frq(scals,wavename,1/fs); % 将尺度转换为频率
coefs=cwt(y,scals,wavename); % 求连续小波系数
figure
imagesc(t,f,abs(coefs));
set(gca,'YDir','normal')
colorbar;
set(gca,'ColorScale','log')
xlabel('时间 t/s');
ylabel('频率 f/Hz');
ylim([0,2000])
title('小波时频图');
% 短时傅里叶变换时频图
figure
spectrogram(y,2048,1536,2048,fs);
set(gca,'YDir','normal')
figure
stft(y,fs,'Window',hamming(2048,'periodic'),'OverlapLength',1536,'FFTLength',2048);
ylim([0,2])
% 时频分析工具箱里的短时傅里叶变换
f = 0:fs/2;
tfr = stft(y');
%tfr = tfr(1:floor(length(fs)/2), :);
figure
imagesc(t, f, abs(tfr));
set(gca,'YDir','normal')
colorbar;
xlabel('时间 t/s');
ylabel('频率 f/Hz');
title('短时傅里叶变换时频图');