diff --git a/Band Elimination Chebyshev/band_elimination_design.m b/Band Elimination Chebyshev/band_elimination_design.m new file mode 100644 index 0000000..e69de29 diff --git a/Band Elimination Chebyshev/plot_transfer_function.m b/Band Elimination Chebyshev/plot_transfer_function.m new file mode 100644 index 0000000..b56e2d2 --- /dev/null +++ b/Band Elimination Chebyshev/plot_transfer_function.m @@ -0,0 +1,44 @@ +function plot_transfer_function( tf, frequency_markers ) +%PLOT_TRANSFER_FUNCTION Plots bode of a transfer function with markers +% +% tf - The transfer function (created using tf) +% frequency_markers - A matrix of frequencies in Hz +% +% Example: +% plot_transfer_function( tf([1000], [1 1000]), [10 1000 10000] ); + +figure; +x_space = logspace(1,5,1000); % 1000 points between 10^1 and 10^5 +x_space = 2 * pi * x_space; % to rad / sec +[mag,~,wout] = bode(tf,x_space); +mag = squeeze(mag); +wout = squeeze(wout); +mag = 20*log10(mag); +wout = wout/2/pi; +semilogx(wout,mag,'-b'); +axis([min(wout) max(wout) min(mag)-10 max(mag)+10]); +[num,den] = tfdata(tf); +syms s; +d1 = digits(5); +ltx = latex(vpa(poly2sym(cell2mat(num),s)/poly2sym(cell2mat(den),s))); +digits(d1); +title(strcat('$',ltx,'$'), 'Interpreter','latex', 'FontSize', 24); +xlabel('Frequency (Hz)', 'FontSize', 18); +ylabel('Magnitude (dB)', 'FontSize', 18); +grid on; +hold on; +[dbMarks,~,frequency_markers] = bode(tf,2 * pi * frequency_markers); +dbMarks = squeeze(dbMarks); +frequency_markers = squeeze(frequency_markers); +dbMarks = 20*log10(dbMarks); +frequency_markers = frequency_markers/2/pi; +Aw = cell(size(frequency_markers, 1) + 1, 1); +Aw{1} = 'Transfer function'; +for i = 1 : size(frequency_markers, 1) + semilogx(frequency_markers(i),dbMarks(i),'o'); + Aw{i+1} = sprintf('Attenuation at %.2f Hz is %.2f dB', ... + frequency_markers(i), dbMarks(i)); +end +legend(Aw,'Location','best','FontSize',12); +set(gca,'FontSize',14); +end \ No newline at end of file