Mercurial > hg > map
comparison userProgramsTim/cutsignal.m @ 38:c2204b18f4a2 tip
End nov big change
author | Ray Meddis <rmeddis@essex.ac.uk> |
---|---|
date | Mon, 28 Nov 2011 13:34:28 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
37:771a643d5c29 | 38:c2204b18f4a2 |
---|---|
1 function outsignal = cutsignal(insignal,samplingfrequency,vocabularyset) | |
2 | |
3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
4 % | |
5 % This function cuts the silence before and after the audiosignal | |
6 % | |
7 % (c) Tim Jürgens, Medizinische Physik, Feb.2006 | |
8 % | |
9 % usage: outsignal = cutsignal(insignal,samplingfrequency,vocabularyset) | |
10 % | |
11 % | |
12 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
13 | |
14 % initial_energythreshold = 0.11; | |
15 % final_energythreshold = 0.05; | |
16 % | |
17 % % choose initial and final delay due to different vocabularysets | |
18 % if (strcmp(vocabularyset,'f_f') > 0) | |
19 % initial_delay = 0.17; % the speech started delay seconds before trespassing threshold (default 0.01, for f_f: 0.17) | |
20 % final_delay = 0.2; %default 0.1, for f_f: 0.2 | |
21 % else | |
22 % initial_delay = 0.01; % the speech started delay seconds before trespassing threshold (default 0.01, for f_f: 0.2) | |
23 % final_delay = 0.1; %default 0.1, for f_f: 0.2 | |
24 % end | |
25 % | |
26 % [initialsample_of_frame, energy] = compute_energy(insignal, samplingfrequency); | |
27 % for i = 1:length(initialsample_of_frame) | |
28 % if (energy(i) > initial_energythreshold) | |
29 % initialsample = initialsample_of_frame(i)-samplingfrequency*initial_delay; | |
30 % break; | |
31 % end | |
32 % end | |
33 % | |
34 % time_inverted_energy = energy(end:-1:1); %turn signal around | |
35 % time_inverted_initialsample = initialsample_of_frame(end:-1:1); | |
36 % | |
37 % for i = 1:length(time_inverted_initialsample) | |
38 % if (time_inverted_energy(i) > final_energythreshold) | |
39 % finalsample = time_inverted_initialsample(i)+samplingfrequency*final_delay; | |
40 % break; | |
41 % end | |
42 % end | |
43 % | |
44 % if (finalsample > length(insignal)) | |
45 % finalsample = length(insignal); | |
46 % end | |
47 % outsignal = insignal(initialsample:finalsample); | |
48 | |
49 if nargin < 3 | |
50 vocabularyset = 'a_a'; %default vocabularyset | |
51 end | |
52 | |
53 | |
54 | |
55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
56 initial_threshold = 0.15; %amplitude threshold for detection of speech | |
57 final_threshold = 0.1; | |
58 | |
59 % choose initial and final delay due to different vocabularysets | |
60 if (strcmp(vocabularyset,'f_f') > 0) | |
61 initial_delay = 0.2; % the speech started delay seconds before trespassing threshold (default 0.01, for f_f: 0.2) | |
62 final_delay = 0.2; %default 0.1, for f_f: 0.2 | |
63 else | |
64 initial_delay = 0.01; % the speech started delay seconds before trespassing threshold (default 0.01, for f_f: 0.2) | |
65 final_delay = 0.1; %default 0.1, for f_f: 0.2 | |
66 end | |
67 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
68 | |
69 | |
70 %cut signal with taking initial delay into account | |
71 for(i = 1:length(insignal)) | |
72 if (abs(insignal(i)) > initial_threshold) | |
73 initialsample = i - samplingfrequency*initial_delay; | |
74 break; | |
75 end | |
76 end | |
77 | |
78 | |
79 time_inverted_insignal = insignal(end:-1:1); %turn signal around | |
80 % cut it with taking a final delay into account | |
81 for(i = 1:length(time_inverted_insignal)) | |
82 if (abs(time_inverted_insignal(i)) > final_threshold) | |
83 finalsample = i - samplingfrequency*final_delay; | |
84 break; | |
85 end | |
86 end | |
87 | |
88 if (finalsample < 0) | |
89 finalsample = 0; | |
90 end | |
91 if (initialsample < 1) | |
92 initialsample = 1; | |
93 end | |
94 | |
95 %% output %%% | |
96 outsignal = insignal(initialsample:end-finalsample); |