-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlungSoundVisulization.m
More file actions
123 lines (83 loc) · 2.28 KB
/
Copy pathlungSoundVisulization.m
File metadata and controls
123 lines (83 loc) · 2.28 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
close all
figure
plot(rawTime,rawWholeSignal)
for i=1:length(cycleStart)
vline([cycleStart(i)],['g'])
end
hold on
for i=1:length(cycleEnd)
vline([cycleEnd(i)],['r'])
end
figure
plot(rawTime, filter_out)
for i=1:length(cycleStart)
vline([cycleStart(i)],['g'])
end
hold on
for i=1:length(cycleEnd)
vline([cycleEnd(i)],['r'])
end
win_time = 40/1000; % sec
overlap_per = 0.5;
time_interval = win_time * overlap_per; % sec
window = round(Fs*win_time);
noverlap = round(window*overlap_per);
F = 2048*2;
figure
spectrogram(filter_out,window,noverlap,Fs/2,Fs,'yaxis')
[s,w,t] = spectrogram(filter_out,window,noverlap,Fs/2,Fs,'yaxis');
ylim([0 .5])
for i=1:length(cycleStart)
vline([cycleStart(i)],['g'])
end
hold on
for i=1:length(cycleEnd)
vline([cycleEnd(i)],['r'])
end
bandPower = [];
bandEnergy = [];
fh = 1000;
fl = 80;
for k = 1:length(s(1,:))
rawBand = s(:,k);
Ex = norm(rawBand,2)^2; % the energy
Px = (1/(fh-fl))* 1/numel(rawBand)*norm(rawBand,2)^2; % power
bandPower(k)= Px;
bandEnergy(k)= Ex;
end
smoothBandPower = smoothn(bandPower,10);
figure
title('Band Power Unsmooth')
hold on
plot(t, bandPower)
%find the local min
[TFmin, minTimeIndicies] = islocalmin(smoothBandPower);
plot(t,smoothBandPower,t(TFmin),smoothBandPower(TFmin),'r*')
%find the local max
[TFmax, maxTimeIndicies] = islocalmax(smoothBandPower);
plot(t,smoothBandPower,t(TFmax),smoothBandPower(TFmax),'b*')
for i=1:length(cycleStart)
vline([cycleStart(i)],['g'])
end
for i=1:length(cycleEnd)
vline([cycleEnd(i)],['r'])
end
figure
hold on
plot(t,smoothBandPower,t(TFmin),smoothBandPower(TFmin),'r*')
plot(t,smoothBandPower,t(TFmax),smoothBandPower(TFmax),'b*')
for i=1:length(cycleStart)
vline([cycleStart(i)],['g'])
end
for i=1:length(cycleEnd)
vline([cycleEnd(i)],['r'])
end
%% This find the distance between the first minmum and the next max
timeBandPowerMins = t(TFmin);
timeBandPowerMaxs = t(TFmax);
bandPowerMins= smoothBandPower(TFmin);
bandPowerMaxs = smoothBandPower(TFmax);
bandPowerMaxs = bandPowerMaxs(2:end); %match the length of mins
deltasMinMax = bandPowerMaxs- bandPowerMins;
[deltasMinMax, deltasMinMaxIndicies] = sort(deltasMinMax, 'descend');
scatter(timeBandPowerMins(I(1:8)),bandPowerMins(I(1:8)),'k*')