|
1 | | -function matrix = normspectrogram(t, acc, regname) |
2 | | -% NORMSPECTROGRAM(T, ACC) |
3 | | -% t: Time array |
4 | | -% acc: Acceleration array (g) |
5 | | -% regname: Name of the seismic file |
6 | | -% |
7 | | -% This function create a normalized spectrogram matrix by doing the following |
8 | | -% algorithm: |
| 1 | +function [matrix, varargout] = norm_spectrogram(t, acc) |
| 2 | +% NORMSPECTROGRAM This function create a normalized spectrogram matrix by |
| 3 | +% doing the following algorithm: |
9 | 4 | % |
10 | 5 | % Each spectrum is divided on 5-second windows overlapped by 2.5 seconds |
11 | 6 | % (50%), on each window is applied: |
12 | | -% 1. Baseline correction |
13 | | -% 2. Tuckey window is applied with r=5%. |
14 | | -% 3. FFT on window signal. |
15 | | -% 4. Spectrum is smoothed by 5 points halfwidth moving average. |
16 | | -% 5. Each element of spectrum is normalized by maximum epsectral amplitude. |
| 7 | +% 1. Baseline correction |
| 8 | +% 2. Tuckey window is applied with r=5%. |
| 9 | +% 3. FFT on window signal. |
| 10 | +% 4. Spectrum is smoothed by 5 points halfwidth moving average. |
| 11 | +% 5. Each element of spectrum is normalized by maximum epsectral |
| 12 | +% amplitude. |
| 13 | +% |
| 14 | +% Usage: |
| 15 | +% matrix = normspectrogram(t, acc) |
| 16 | +% [matrix, matrix_t, matrix_f] = normspectrogram(t, acc) |
| 17 | +% |
| 18 | +% Where: |
| 19 | +% t: Time array |
| 20 | +% acc: Acceleration array (g) |
17 | 21 | % |
18 | 22 | % Author: Pablo Pizarro @ppizarror.com, 2017. |
19 | 23 | % |
|
31 | 35 | % along with this program; if not, write to the Free Software |
32 | 36 | % Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
33 | 37 |
|
34 | | -%% Constantes |
| 38 | +%% Constants |
35 | 39 | MAX_FREQ = 14; % Max frequency of the matrix |
36 | 40 | NORMALIZE = true; % Do normalize windows |
37 | 41 | WINDOW_TIME = 5; % Time of each window |
|
74 | 78 | end |
75 | 79 |
|
76 | 80 | %% Create matrix |
77 | | - |
78 | 81 | % Calculate matrix length by time |
79 | 82 | t_ini = 0; |
80 | 83 | tarrsize = 1; |
|
98 | 101 | t_ini = 0; % Initial time |
99 | 102 | t_indx = 1; % Index of initial time on t array |
100 | 103 | u = 1; % Number of window |
| 104 | + |
| 105 | +% Start iteration |
101 | 106 | while true |
102 | 107 |
|
103 | 108 | % Create window and acceleration window |
|
147 | 152 | matrix(freq, u) = acc_norm(freq); |
148 | 153 | end |
149 | 154 |
|
150 | | - % Advance initial window time |
| 155 | + %% Advance initial window time |
151 | 156 | t_ini = t_ini + WINDOW_TIME_MOVEMENT; |
152 | 157 | if t_ini + WINDOW_TIME > t(end) |
153 | 158 | break; |
|
157 | 162 |
|
158 | 163 | end |
159 | 164 |
|
160 | | -%% If regname is not defined |
161 | | -if ~exist('regname', 'var') |
162 | | - regname = ''; |
163 | | -end |
164 | | - |
165 | | -%% Plot matrix |
166 | | -figure(); |
167 | | - |
168 | | -% Plot matrix |
169 | | -subplot(2, 1, 1); |
170 | | -title(regname); |
171 | | -hold on; |
172 | | -pcolor(matrix_t, matrix_f, matrix); shading interp; % Plot colormap |
173 | | -[~, h] = contour(matrix_t, matrix_f, matrix, [0.8, 0.8]); % Plot contour at 80% |
174 | | -h.LineWidth = 0.5; |
175 | | -h.LineColor = 'red'; |
176 | | -hold off; |
177 | | -ylabel('frequency (Hz)'); |
178 | | -xlim([0 matrix_t(end)]); |
179 | | -ylim([0.4 matrix_f(end)]); |
180 | | - |
181 | | -% Plot seismic |
182 | | -subplot(2, 1, 2); |
183 | | -plot(t, acc, 'k'); |
184 | | -xlabel('Time (s)'); |
185 | | -ylabel('a (g)'); |
186 | | -xlim([0 t(end)]); |
187 | | -grid on; |
| 165 | +%% Store results in varargout |
| 166 | +varargout{1} = matrix_t; |
| 167 | +varargout{2} = matrix_f; |
188 | 168 |
|
189 | 169 | end |
190 | 170 |
|
0 commit comments