shawkikislam

jjjj

Aug 24th, 2025
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.03 KB | None | 0 0
  1. % Frequency (Hz) and measured linear gain (unitless)
  2. f = [610, 1220, 3050, 4270, 5490, 6100, 7320, 12200, 24400, 36600, 61000].';
  3. G = [1.5, 1.48, 1.38, 1.32, 1.1, 0.98, 0.73, 0.34, 0.09, 0.04, 0.02].';
  4.  
  5. % Convert to magnitude in dB
  6. GdB = 20*log10(G);
  7.  
  8. % Bode-style magnitude plot (frequency log scale)
  9. figure;
  10. semilogx(f, GdB, '-o', 'LineWidth', 1.5, 'MarkerSize', 6);
  11. grid on;
  12. grid minor;
  13. xlim([min(f)*0.9, max(f)*1.1]);
  14.  
  15. xlabel('Frequency (Hz)');
  16. ylabel('Magnitude (dB)');
  17. title('Measured Bode Magnitude Plot');
  18.  
  19. % Optional: annotate corner-like points (e.g., where gain crosses 0 dB)
  20. zcrossIdx = find(diff(sign(GdB))~=0, 1, 'first');
  21. if ~isempty(zcrossIdx)
  22.     % Linear interpolation of zero-crossing on log-frequency axis
  23.     x1 = log10(f(zcrossIdx));   y1 = GdB(zcrossIdx);
  24.     x2 = log10(f(zcrossIdx+1)); y2 = GdB(zcrossIdx+1);
  25.     xz = x1 + (0 - y1)*(x2 - x1)/(y2 - y1);
  26.     fz = 10^xz;
  27.     hold on;
  28.     plot(fz, 0, 'rs', 'MarkerFaceColor', 'r');
  29.     text(fz, 0, '  0 dB crossing', 'VerticalAlignment', 'bottom');
  30. end
  31.  
Advertisement
Add Comment
Please, Sign In to add comment