MATLAB: Plotting multiple Magnitudes in one plot

bandpassfreqz

Hello everyone,
I intend to use freqz() function I need to plot the magnitude for different border frequencies. But first I need to determine the cut off frequencies.
I used this code but which seems to not give me even a close response to this
%% INitializing Matlab Environment
close all;
clc;
clearvars;
%% 1.1
b=log10(8000);%stop frequency and 100Hz is the pass frequency
yc1=logspace(2,b,23);
yd=stem(yc1);
grid on
xlabel('Borders','FontSize',12);
ylabel('F (Hz)','FontSize',12);
set(gca,'YScale', 'log')
%%
m={};
n={};
h={};
ph={};
j={};
fs=21e3 %sampling frequency
for i= 1:1:23
[u,o] = butter(1,[2*100/fs, (2*yc1(i))/fs],'bandpass');
m{i}=u;
n{i}=o;
%freqz(m{i},n{i});
[h{i},ph{i}]=freqz(m{i},n{i});
figure
subplot(2,1,1)
hold on
plot(ph{i},20*log10(abs(h{i})));
end
hold off
grid
set(gca,'XLim',[0 1e4],'XTick',10.^(0:4),'YLim',[-12 0],'YTick',-12:2:0,'XScale', 'log')
Any Idea on what I am missing ?

Best Answer

Put the figure call before the loop, and remove the subplot call:
figure
hold on
for i= 1:1:23
[u,o] = butter(1,[2*100/fs, (2*yc1(i))/fs],'bandpass');
m{i}=u;
n{i}=o;
%freqz(m{i},n{i});
[h{i},ph{i}]=freqz(m{i},n{i});
plot(ph{i},20*log10(abs(h{i})));
end
hold off
This does not exactly produce the plot you posted, however it will get you closer.
I leave the other details to you.