2

I am trying to plot the following using subplot how can I do that? Thank you

[n,wc]= buttord(Wp,Ws,Rp,Rs);  
[z,p,k]=butter(n,wc);
sos = zp2sos(z,p,k);   


freqz(sos) ;
grpdelay(sos) ; 

Note that this is non-trivial since freqz yields a subplot already.

Tobias Kienzler
  • 25,759
  • 22
  • 127
  • 221
  • 2
    You should have been more elaborate with your question, without [this comment](http://stackoverflow.com/questions/27374467/plot-two-figures-on-the-same-figure-using-subplot#comment43200085_27374898) clarifying on [`freqz`](http://ch.mathworks.com/help/signal/ref/freqz.html#bt8l89o-1) creating a subplot this question seemed trivial. – Tobias Kienzler Dec 09 '14 at 09:11
  • 1
    @TobiasKienzler - I agree that this is no longer a duplicate. I will vote to reopen. The OP should have explicitly stated that `subplot` did not work out of the box. – rayryeng Dec 12 '14 at 17:11

2 Answers2

4

The following would work if the functions you are using plotted one figure each: call subplot right before each function that produces a graphic output. It is kind of straightforward from the manual, subplot(m,n,p) splits the figure into a grid of m x n graphics and draws the p-th one. However, as pointed by @hbaderts, freqz produces a subplot of its own, so you would need to rearrange it to include the upcoming output of grpdelay.

This is how you could do it, as per the workaround proposed in this thread (see it for the more general solution).

freqz(sos);
h = get(gcf, 'children');
fig2=figure;
figure(fig2)
g=subplot(3,1,1)
set(h(1), 'pos', get(g, 'pos'))
figure(fig2)
g=subplot(3,1,2)
set(h(2), 'pos', get(g, 'pos'))
close
g=subplot(3,1,3)
grpdelay(sos)
Lord Henry Wotton
  • 1,332
  • 1
  • 10
  • 11
2

Probably the easiest solution is calculating the frequency response with freqz and plotting it with freqzplot. This is not the best solution because freqzplot is obsolete. A better solution would be to manually create the plots (e.g. 20*log10(abs(h))).

[h,w] = freqz(sos);
subplot(2,2,1);
freqzplot(h,w,'mag');
subplot(2,2,3);
freqzplot(h,w,'phase');
subplot(2,2,[2,4]);
grpdelay(sos);
hbaderts
  • 14,136
  • 4
  • 41
  • 48