For my Master Thesis i need to have good quality visualisations of a bodeplot. I need a level of customization, which lead me to the usage of subplots where i used semilogx. But i found out, that my x-axis seems to be shifted by 10^1 to the left. Not just visually but my bodeplot has a magnitude at lets say 10^2 which it should have at 10^3. Can anyone help me with finding the error because i am missing it. Here is my Code:
%% Bode Plot of the Transfer Function
% Common parameters
%f = logspace(1, 6, 1000);
w = 2*pi*logspace(log10(10e0), log10(10e5), 1000);
% get magnitude response of closed loop current control with CCF
[mag, phase, w] = bode(G_sys_ol, w);
mag = squeeze(mag);
phase = squeeze(phase);
% Interpolate the magnitude response at the fo
mag_f_o = interp1(w, mag, 2*pi*f_b);
mag_f_o_dB = 20 * log10(mag_f_o)
% Create a figure for Bode plots
figure_CCF = figure('Name', 'REsulting OL Bodeplot of CCF', 'Visible', 'on', 'Color', 'white');
% Plot magnitude responses on the same subplot
ax1 = subplot(2,1,1);
% plot magnitude response
semilogx(w/(2*pi), 20*log10(squeeze(mag)), 'LineWidth', 2);
hold on;
x_norm = 0.2485;
%y1_norm = 0.5;
y1_norm = 0.81;
y2_norm = 0.865;
% Add the double arrow annotation
annotation('doublearrow', [x_norm x_norm],[y1_norm y2_norm]);
% plot settings
grid on;
ylabel('Magnitude (dB)', 'FontSize', figFontsize);
ax = gca;
ax.FontSize = figFontsize; % Apply font size to axis ticks
ax.TickLength = tickLength; % Adjust the length of the ticks
% Remove x-ticks
ax.XTickLabel = [];
% create y-axis margin
ax.YLimMode = 'auto';
ylim_values = ylim;
new_ylim = ylim_values + [-1 1] * 0.1 * diff(ylim_values);
ylim(new_ylim);
% highlight resonance, crosover and grid frequency
% line([f_r f_r], new_ylim, 'Color', 'k', 'LineStyle', '--', 'LineWidth', 0.8); % Vertical line
% line([f_cr f_cr], new_ylim, 'Color', 'k', 'LineStyle', '--', 'LineWidth', 0.8); % Vertical line
line([f_b f_b], new_ylim, 'Color', 'k', 'LineStyle', '--', 'LineWidth', 0.8); % Vertical line
% Calculate and mark gain and phase margin
[GM, PM, wcg, wcp] = margin(G_sys_ol);
% Convertn GM to dB
GM_dB = 20*log10(GM);
% Mark gain margin on magnitude plot
%text(wcg/(2*pi), (new_ylim(1) + 0)/2, '}', 'FontSize', 24, 'Color', 'r', 'HorizontalAlignment', 'center');
%text(wcg/(2*pi), -3, ['Gain Margin = ', num2str(GM_dB), ' dB'], 'FontSize', figFontsize, 'Color', 'r', 'VerticalAlignment', 'top');
%rectangle('Position', [wcg/(2*pi)*0.75, -GM_dB-5, wcg/(2*pi)*0.9, GM_dB+10], 'EdgeColor', 'k', 'LineWidth', 0.75)
% Adjust subplot position
ax1.Position = [0.1 0.58 0.85 0.4];
% Legend
legend('$G_{mathrm{cc}}^mathrm{ol}$', 'FontSize', figFontsize, 'Location', 'northeast');
%% Plot phase responses on the same subplot
ax2 = subplot(2,1,2);
% get phase response of closed loop current control with CCF
semilogx(w/(2*pi), squeeze(phase), 'LineWidth', 2);
%hold on;
grid on;
xlabel('Frequency (Hz)', 'FontSize', figFontsize);
ylabel('Phase ($^circ$)', 'FontSize', figFontsize);
ax = gca;
ax.FontSize = figFontsize; % Apply font size to axis ticks
ax.TickLength = tickLength; % Adjust the length of the ticks
% create y-axis margin
ax.YLimMode = 'auto';
ylim_values = ylim;
new_ylim = ylim_values + [-1 1] * 0.1 * diff(ylim_values);
ylim(new_ylim);
% highlight resonance, crossover and grid frequency
% line([f_r f_r], new_ylim, 'Color', 'k', 'LineStyle', '--', 'LineWidth', 0.8); % Vertical line
% line([f_cr f_cr], new_ylim, 'Color', 'k', 'LineStyle', '--', 'LineWidth', 0.8); % Vertical line
line([f_b f_b], new_ylim, 'Color', 'k', 'LineStyle', '--', 'LineWidth', 0.8); % Vertical line
% text(f_r-3000, min(new_ylim)-7, '$f_mathrm{r,LCL}$', 'FontSize', figFontsize, 'Interpreter', 'latex', 'HorizontalAlignment', 'left', 'VerticalAlignment', 'top');
% text(f_cr-400, min(new_ylim)-7, '$f_mathrm{cr}$', 'FontSize', figFontsize, 'Interpreter', 'latex', 'HorizontalAlignment', 'left', 'VerticalAlignment', 'top');
text(f_b-5, min(new_ylim)-1, '$f_mathrm{o}$', 'FontSize', figFontsize, 'Interpreter', 'latex', 'HorizontalAlignment', 'left', 'VerticalAlignment', 'top');
% Mark phase margin on phase plot
%line([wcp wcp]/(2*pi), [new_ylim(1) -180+PM], 'Color', 'b', 'LineStyle', '--', 'LineWidth', 1.5);
%text(wcp/(2*pi), -180+PM+10, ['Phase Margin = ', num2str(PM), '°'], 'FontSize', figFontsize, 'Color', 'b', 'VerticalAlignment', 'top');
% Adjust subplot position
ax2.Position = [0.1 0.1 0.85 0.4];
% Legend
legend('$G_{mathrm{cc}}^mathrm{ol}$', 'FontSize', figFontsize, 'Location', 'northeast');
I tried to have a high quality custom bodeplot, which i did achieve but my x-axis is shifted by 10^1