forked from vishaldas/viscoelastic_scale_effects_1D
-
Notifications
You must be signed in to change notification settings - Fork 1
/
transfer_functions_periodic.m
333 lines (277 loc) · 8.91 KB
/
transfer_functions_periodic.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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
close all
clear all
% Creating the samples
vel_plastic = 2487; % 2487m/sec
vel_steel = 5535; % 5535m/sec
den_plastic = 1.210*1000; % 1.210 g/cc
den_steel = 7.900 *1000; % 7.900 g/cc
D = 52e-3; % Length of sample 52e-3
P1 = 0.5; % Proportion of plastic
P2 = 1-P1; % Proportion of steel
Q_plastic =10; % 10
Q_steel = 20; % 20
fdom = 200e3;
dt_nyquist = 1/(2*fdom);
dt = 0.0351*dt_nyquist;
N_sample = round(dt_nyquist./dt);
time = 0:dt:70e-3-dt;
fdom1 = 115e3;
% -------------------- Periodicity ----------------------------------------
M_period = [1 2 3 5 6 7 8 9 10 12 14 16 32 64 128 256]; % Periodicity
% M_period = [1 2 3 4 5 6 7 8 9 10 12 14 16 32 64];
% M_period = [1 4 10 16 32 128]; % Periodicity
velocity_cal = zeros(length(M_period),1);
wavelength = zeros(length(M_period),1);
R = zeros(length(M_period),1);
Q_phase = zeros(length(M_period),1);
tf = cell(length(M_period),1);
kf = cell(length(M_period),1);
vel_eff = cell(length(M_period),1);
invq_eff = cell(length(M_period),1);
pz_pick = zeros(length(M_period),1);
time_pick = zeros(length(M_period),1);
offset = 0;
ytick_location = zeros(length(M_period),1);
disp ('Initializing the calculations');
% For elastic media
for i = 1:length(M_period)
disp (['Iteration no ' num2str(i) '/' num2str(length(M_period))]);
M = M_period(i);
n_layers = 2*M; % Number of layers
d = D/M; % Spatial period
d1 = P1*d; %thickness of plastic
d2= P2*d; %thickness of steel
lyr = zeros(n_layers,3);
vel = [vel_plastic; vel_steel];
den = [den_plastic; den_steel];
thick = [d1; d2];
Q = [Q_plastic; Q_steel];
lyr(:,1) = repmat(vel,[M,1]);
lyr(:,2) = repmat(den,[M,1]);
lyr(:,3) = repmat(thick,[M,1]);
Q_layer = repmat(Q, [M,1]);
% Transfer functions for range of frequency
om = 2.*pi.*logspace(3,6,1000);
% [wz,pz_temp,tf_temp] = kennet(lyr,wvlt,dt,2,1,-1);
[tf_temp] = kennettQ2_tf(lyr,om,2,0,Q_layer*1e10,2*pi*fdom1);
tf(i) = {tf_temp};
end
disp ('Plotting');
% For viscoelastic media
tf_ve = cell(length(M_period),1);
for i = 1:length(M_period)
disp (['Iteration no ' num2str(i) '/' num2str(length(M_period))]);
M = M_period(i);
n_layers = 2*M; % Number of layers
d = D/M; % Spatial period
d1 = P1*d; %thickness of plastic
d2= P2*d; %thickness of steel
lyr = zeros(n_layers,3);
vel = [vel_plastic; vel_steel];
den = [den_plastic; den_steel];
thick = [d1; d2];
Q = [Q_plastic; Q_steel];
lyr(:,1) = repmat(vel,[M,1]);
lyr(:,2) = repmat(den,[M,1]);
lyr(:,3) = repmat(thick,[M,1]);
Q_layer = repmat(Q, [M,1]);
% Transfer functions for range of frequency
om = 2.*pi.*logspace(3,6,1000);
% [wz,pz_temp,tf_temp] = kennet(lyr,wvlt,dt,2,1,-1);
[tf_temp] = kennettQ2_tf(lyr,om,2,0,Q_layer,2*pi*fdom1);
tf_ve(i) = {tf_temp};
end
disp ('Plotting');
%% Plotting few of the power spectrum and comparing elastic and viscoelastic
% Q total will be related to the width of the peak at half power
% High Q = narrow peak
figure;
plot_M = [1 2 7 12 13 16];
for i = 1:length(plot_M)
tf1 = cell2mat(tf(plot_M(i)));
tf2 = cell2mat(tf_ve(plot_M(i)));
power_tf1 = (abs(tf1(2:end,3))).^2;
power_rf1 = (abs(tf1(2:end,2))).^2;
power_tf2 = (abs(tf2(2:end,3))).^2;
power_rf2 = (abs(tf2(2:end,2))).^2;
tf1_freq = tf1(2:end,1);
tf2_freq = tf2(2:end,1);
subplot (3,2,i);
semilogx(tf1_freq,power_tf1, '-k');
hold on;
semilogx(tf2_freq,power_tf2, '-r');
semilogx(tf1_freq, power_rf1, '--k');
semilogx(tf2_freq, power_rf2, '--r');
set(gca, 'Layer', 'top');
set(gca, 'XTick', logspace(3,6,4));
% y1=get(gca,'ylim');
% semilogx([fdom fdom], y1, '--k');
xlim([1e3 1e5]);
ylim([0 1]);
xlabel('Frequency'); ylabel('Power');
title(['Number of periods = ' num2str(M_period(plot_M(i)))]);
end
legend('Transmission', 'Reflection', 'Transmission', 'Reflection');
% %% Plotting power spectrum (subplot)
%
% figure;
%
%
% for i = 1:length(M_period)
% tf1 = cell2mat(tf(i));
% power_tf1 = (abs(tf1(2:end,3))).^2;
% power_rf1 = (abs(tf1(2:end,2))).^2;
%
% power_total = power_tf1 + power_rf1;
%
% % Calculate phase from transfer functions
% phase_tf = unwrap(angle(tf1(2:end,3)));
%
% tf1_freq = tf1(2:end,1);
%
% subplot (4,4,i);
% ax = gca;
% semilogx(tf1_freq,power_tf1, '-k');
% ylabel('Power');
% hold on;
% % yyaxis right;
% semilogx(tf1_freq, power_rf1, '-b');
% % ax.YScale = 'log';
% % ax.YColor = 'b';
% ylabel('Power');
% ylim([0 1]);
%
% % y1=get(gca,'ylim');
% % semilogx([fdom fdom], y1, '--k');
% xlabel('Frequency');
% title(['Number of periods = ' num2str(M_period(i))]);
% end
% legend('Transmission', 'Reflection');
%
%
% %% Plotting (full scale) power spectrum
%
%
% for i = 1:length(M_period)
% tf1 = cell2mat(tf(i));
% power_tf1 = (abs(tf1(2:end,3))).^2;
% power_rf1 = (abs(tf1(2:end,2))).^2;
%
% tf1_freq = tf1(2:end,1);
% figure;
% loglog(tf1_freq,power_tf1, '-k');
% hold on;
% loglog(tf1_freq, power_rf1, '-b');
% set(gcf,'pos',[10 10 812 650]);
% % y1=get(gca,'ylim');
% % semilogx([fdom fdom], y1, '--k');
% xlabel('Frequency'); ylabel('power');
% title(['Number of periods = ' num2str(M_period(i))]);
% legend('Transmission', 'Reflection', 'Position', [0.716338263185349 0.926410258427644 0.176108370640595 0.0746153825979965]);
% set(gca, 'Layer', 'top'); % To bring axis on top
% end
%
% %% Plotting few of the power spectrum
% % Q total will be related to the width of the peak at half power
% % High Q = narrow peak
%
% figure;
% plot_M = [1 2 7 12 13 16];
%
% for i = 1:length(plot_M)
% tf1 = cell2mat(tf(plot_M(i)));
% power_tf1 = (abs(tf1(2:end,3))).^2;
% power_rf1 = (abs(tf1(2:end,2))).^2;
%
% tf1_freq = tf1(2:end,1);
% subplot (3,2,i);
% semilogx(tf1_freq,power_tf1, '-k');
% hold on;
% semilogx(tf1_freq, power_rf1, '--k');
% set(gca, 'Layer', 'top');
% set(gca, 'XTick', logspace(3,6,4));
% % y1=get(gca,'ylim');
% % semilogx([fdom fdom], y1, '--k');
% xlim([1e3 1e5]);
% ylim([0 1]);
% xlabel('Frequency'); ylabel('Power');
% title(['Number of periods = ' num2str(M_period(plot_M(i)))]);
% end
% legend('Transmission', 'Reflection');
%
%
%
%
% %% Approx lambda/d for each of the selected plots
%
% lambdaoverd = [0.3426 0.6922 2.0451 2.1868 5.3811 44.7974];
%
% M_period = [1 2 8 16 32 256]; % Periodicity
%
%
% title(['Number of periods = ' num2str(M_period(i)) ', \lambda/d \approx ' ...
% num2str(lambdaoverd(i))]);
%
% %% Relative phase shift with respect to fastest (ray theory)
% % and then the phase lag for different periods
%
% % phase_tf = zeros(length(om)-1, length(M_period));
% % phase_rf = zeros(length(om)-1, length(M_period));
% phase_tf1 = zeros(length(om)-1, length(M_period));
% phase_rf1 = zeros(length(om)-1, length(M_period));
%
% for i = 1:length(M_period)
% tf1 = cell2mat(tf(i));
% tf_relative = cell2mat(tf(1));
%
% % % Calculate phase from transfer functions
% % phase_tf(:,i) = (angle(tf1(2:end,3)));
% % phase_rf(:,i) = (angle(tf1(2:end,2)));
%
% % Relative phase difference
%
% phase_tf1(:,i) = angle(tf1(2:end,3) ./tf_relative(2:end,3));
% phase_rf1(:,i) = angle(tf1(2:end,2) ./tf_relative(2:end,2));
%
%
% tf1_freq = tf1(2:end,1);
%
% end
%
% % % Relative phase shift
% % phase_lag_tf = phase_tf(:, 1:end) - ...
% % repmat(phase_tf(:,1), [1 length(M_period)]);
% % phase_lag_rf = phase_rf(:, 1:end) - ...
% % repmat(phase_rf(:,1), [1 length(M_period)]);
%
% figure;
%
% for i = 1:length(M_period)
% subplot (4,4,i);
% semilogx(tf1_freq,phase_tf1(:,i), '-k');
% hold on;
% semilogx(tf1_freq,phase_rf1(:,i), '-b');
% xlabel('Frequency'); ylabel('Phase shift (in radians)');
% title(['Number of periods = ' num2str(M_period(i))]);
% axis tight;
% ylim([-pi pi]);
%
% end
% legend('Transmission', 'Reflection');
%
%
% figure;
% plot_M = [1 2 7 12 13 16];
% for i = 1:length(plot_M)
% subplot (3,2,i);
% semilogx(tf1_freq,phase_tf1(:,plot_M(i)), '-k');
% hold on;
% semilogx(tf1_freq,phase_rf1(:,plot_M(i)), '--k');
% xlabel('Frequency'); ylabel('Phase shift (in radians)');
% title(['Number of periods = ' num2str(M_period(plot_M(i)))]);
% axis tight;
% ylim([-pi pi]);
% xlim([1e3 1e5]);
%
% end
% legend('Transmission', 'Reflection');