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 - Creates a filled contour plot of the interpolated PSD data.
31 - Configures axes, labels, and colorbar with LaTeX formatting.
32 - Uses a custom colormap (`sky`) for visualization.
33
34 Dependencies:
35 - Requires the `merged_pxx.mat` file containing the following variables:
36 - `f_merge`: Frequency data (Hz).
37 - `Y_merge`: Vertical positions (m).
38 - `pxx_merge`: PSD values.
39 - Requires the `sky` colormap function for custom color mapping.
40
41 Output:
42 - Individual PSD plots saved in the `mergePSD-figure` folder.
43 - Combined PSD plot saved as `.fig`, `.emf`, and `.jpg` files.
44 - Contour plot displayed with interpolated PSD data.
45
46 Notes:
47 - Ensure the `merged_pxx.mat` file is in the same directory as the script or provide the correct path.
48 - The `sky` colormap function must be available in the MATLAB path.
49
50 Author: L-N1988
51 Date: 2025-3-30
52
53 clc; clear; close all;
54 mergeData = load('merged_pxx.mat');
55
56
57 xv = mergeData.f_merge;
58 yv = repmat(double(mergeData.Y_merge), 1, size(xv, 2));
59 vv = xv .* mergeData.pxx_merge;
60
61
62 outputFolder = 'mergePSD-figure';
63 if ~exist(outputFolder, 'dir')
64 mkdir(outputFolder);
65 end
66
67 for ii = 1:length(mergeData.Y_merge)
68 figure;
69 plot(xv(ii, :), vv(ii, :), 'LineWidth', 2);
70 set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
71 set(gca, 'FontSize', 16);
72 set(xlabel("$f$ (Hz)"), 'Interpreter', 'latex');
73 set(ylabel("$fS_{uu}(f) (\rm m^2/s^2)$"), 'Interpreter', 'latex');
74 set(title(sprintf("PSD at $z = %.3f$ m", mergeData.Y_merge(ii))), 'Interpreter', 'latex');
75 saveas(gcf, fullfile(outputFolder, sprintf("merged_psd_z%.3f.png", mergeData.Y_merge(ii))));
76 end
77
78 %%
79
80 figure;
81
82
83 indices = 10:10:length(mergeData.Y_merge);
84
85
86 z_values = mergeData.Y_merge(indices);
87
88
89 z_min = min(z_values);
90 z_max = max(z_values);
91 z_normalized = (z_values - z_min) / (z_max - z_min);
92
93
94 cmap = sky(length(indices));
95
96
97 hold on;
98 for idx = 1:length(indices)
99 ii = indices(idx);
100
101 color_idx = round(z_normalized(idx) * (size(cmap, 1) - 1)) + 1;
102 plot(xv(ii, :), vv(ii, :), 'LineWidth', 1.5, 'Color', cmap(color_idx, :));
103 end
104 hold off;
105
106
107 set(gca, 'XScale', 'log');
108 set(gca, 'YScale', 'log');
109 set(gca, 'FontSize', 16);
110
111
112 set(xlabel('$f$ (Hz)'), 'Interpreter', 'latex', 'FontSize', 16);
113 set(ylabel('$fS_{uu}(f) (\rm m^2/s^2)$'), 'Interpreter', 'latex', 'FontSize', 16);
114 set(title('Pre-multiplied Power Spectral Density'), 'Interpreter', 'latex', 'FontSize', 16);
115
116
117 colormap(cmap);
118 cbar = colorbar;
119 set(cbar, 'FontSize', 16);
120 set(get(cbar, 'Label'), 'String', '$z$ (m)', 'Interpreter', 'latex', 'FontSize', 16);
121 clim([z_min z_max]);
122
123
124 base_filename = fullfile(outputFolder, 'merged_psd_selected');
125
126 savefig(gcf, [base_filename '.fig']);
127
128
129 print(gcf, [base_filename '.emf'], '-dmeta');
130
131
132 print(gcf, [base_filename '.jpg'], '-djpeg', '-r500');
133 %%
134
135
136 [grid_row, grid_col] = deal(max(400, size(yv, 1)*10), max(50, round(size(xv, 2)/100)));
137 xq = logspace(
138 log10(min(xv(xv > 0))), log10(max(xv(:))),
139 grid_col);
140 yq = linspace(
141 min(yv(:)), max(yv(:)),
142 grid_row);
143 [xq, yq] = meshgrid(xq, yq);
144
145 vq = griddata(xv, yv, vv, xq, yq);
146
147 %% Plot contour
148 contourf(xq, yq, vq, 10, 'LineStyle', '--');
149 set(gca, 'XScale', 'log'); set(gca, 'FontSize', 16);
150 set(xlabel("$f$ (Hz)"), 'Interpreter', 'latex');
151 set(ylabel("$z(\rm m)$"), 'Interpreter', 'latex');
152 colormap("sky");
153 col = colorbar();
154 set(ylabel(col,"$fS_{uu}(f) (\rm m^2/s^2)$"), 'Interpreter', 'latex');