This repository has been archived by the owner on Nov 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtd_analysis.m
82 lines (68 loc) · 2.13 KB
/
td_analysis.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
80
81
82
function [tm_frame, frame_mean, frame_max, frame_min, frame_change] = td_analysis(s, tm, Fs, L, R, window_type, debug_fig)
% TD_ANALYSIS window and extract features from signals.
%
% Input:
% s input signal
% tm Nx1 vector of doubles representing the sampling intervals.
% Fs 1xM Double, sampling frequency in Hz of all the signals in the
% record.
% L window size
% n window range
% R window shift
% window_type = 1; --> Rectangular window
% = 0; --> Hamming window
% debug_fig set below to 1, if want to show debug figures
%
% Output: mean min max change along with frame indexing
%
%%
% Window setup
n=0:(L-1); % window range temp
if window_type == 1
w=0*(n<0)+1*(n>=0&n<=(L-1))+0*(n>(L-1)); %Rectangular window
else
w=0.54*(n>=0&n<=(L-1))-0.46*cos(2*pi*n/(L-1)).*(n>=0&n<=(L-1)); %Hamming window
end
% calculate the total number of frames (dividing sig_length by frame_length)
signal_length=length(s);
frame_number=floor((signal_length-L)/R)+1;
% Initialization
frame_mean = [zeros(frame_number, 1)];
frame_max = [zeros(frame_number, 1)];
frame_change = [zeros(frame_number, 1)];
frame_min = [zeros(frame_number, 1)];
tm_frame = [zeros(frame_number, 1)];
for i=1:frame_number
frame_index=(i-1)*R+(1:L);
framesignal1=s(frame_index).*w';
% frame start time stamp using 'tm'£¬ time stamp by frame
tm_frame(i) = tm(frame_index(1));
% mean
frame_mean(i) = mean(framesignal1);
% max
frame_max(i) = max(framesignal1);
% min
frame_min(i) = min(framesignal1);
% change
frame_change(i) = framesignal1(1) - framesignal1(end);
end
%% Debug Plots
if debug_fig
figure
subplot(411)
plot(0:(1/Fs):((signal_length-1)/Fs),s)
ylabel('Waveform')
subplot(412)
plot((1:frame_number)*R/Fs,frame_mean)
ylabel({'frame mean'})
subplot(413)
plot((1:frame_number)*R/Fs,frame_max); hold on;
plot((1:frame_number)*R/Fs,frame_min)
ylabel({'framevmax & frame mean'})
subplot(414)
% plot((1:frame_number)*R/Fs,frame_change)
plot(tm_frame(1:frame_number),frame_change)
xlabel('time(s)')
ylabel({'frame change'})
end
end