MATLAB: [Beginner] How to plot the resonance frequency with bandwidth

bandwidthcircuitscurrentelectricalfrequencygraphsplotresistance

Been looking for ages and struggling to find how to plot a bandwidth line onto a graph for an AC circuit. I've managed to gather the resonance frequency, bandwidth and current. How would I go about plotting these into the graph? Image shows what I'm looking for. Thanks in advance.

Best Answer

Try this:
f = linspace(0, 10); % Create Data: Frequency
h = exp(-(f-5).^2); % Create Data: Transfer Function
[hmax,idx] = max(h); % Maximum
dB3 = hmax * 10^(-3/20); % -3 dB Amplitude
f_lower3dB = interp1(h(1:idx), f(1:idx), dB3); % Lower -3 dB Frequency
f_upper3dB = interp1(h(idx+1:end), f(idx+1:end), dB3); % Upper -3 dB Frequency
figure(1)
plot(f, h, '-r')
hold on
plot(xlim, [1 1]*hmax, '-k')
plot(xlim, [1 1]*dB3, '-k')
plot([1 1]*f_lower3dB, [0 dB3], '-b')
plot([1 1]*f_upper3dB, [0 dB3], '-b')
plot([1 1]*f(idx), [0 hmax], ':b')
hold off
text(7, hmax, ' 0 dB', 'HorizontalAlignment','left', 'VerticalAlignment','bottom')
text(7, dB3, '-3 dB', 'HorizontalAlignment','left', 'VerticalAlignment','bottom')
text(f_lower3dB, 0.3, '\leftarrow', 'HorizontalAlignment','left', 'VerticalAlignment','middle')
text(f_upper3dB, 0.3, '\rightarrow', 'HorizontalAlignment','right', 'VerticalAlignment','middle')
text(5.2, 0.3, '\itB\rm', 'HorizontalAlignment','right', 'VerticalAlignment','middle')
axis([xlim [0 1.1*hmax]])
Experiment to get the result you want.