Question: Can someone check this MATLAB code and help me get it running? thanks. function [Z1,Z2,Z3] = Sinc_PadeApp(order,T) if nargout == 0 Z1 = []; Z2
Can someone check this MATLAB code and help me get it running?
thanks.
function [Z1,Z2,Z3] = Sinc_PadeApp(order,T)
if nargout == 0
Z1 = []; Z2 = []; Z3 = [];
end
% ZOH/SINC:
T=0.1;
k = [-100:100]; % 10 cycles, 5 cycles each side, total 20 intervals/side
w = k*2*pi*10/length(k)/T; % 10 cycle both sides
SINC = exp(-j*w*T/2).*sin(w*T/2)./(w*T/2);
%T*exp(- j*w*T/2).*sin(w*T/2)./(w*T/2);
magZ = abs(SINC);
angZ = angle(SINC);
% Pade Approximation:
s = tf('s');
[num,den]= pade(T,order(1));
padeapp1 = tf(num,den);
[num,den] = pade(T,order(2));
padeapp2 = tf(num,den);
[num,den]= pade(T,order(3));
padeapp3 = tf(num,den);
Z1 = (1 - padeapp1)/s/T;
Z2 = (1 - padeapp2)/s/T;
Z3 = (1 - padeapp3)/s/T;
% Frequency Response:
H1 = freqresp(Z1,w);
ga1 = abs(H1);
ph1 = angle(H1);
ga1 = squeeze(ga1); ph1 = squeeze(ph1);
H2 = freqresp(Z2,w);
ga2 = abs(H2);
ph2 = angle(H2);
ga2 = squeeze(ga2); ph2 = squeeze(ph2);
H3 = freqresp(Z3,w);
ga3 = abs(H3);
ph3 = angle(H3);
ga3 = squeeze(ga3); ph3 = squeeze(ph3);
strname{1,1} = ['Sinc Function'];
strname{2,1} = [num2str(order(1)) 'st Pade Approx.'];
strname{3,1} = [num2str(order(2)) 'th Pade Approx.'];
if order(2) == 2
strname{3,1} = ['2nd Pade Approx.'];
end
strname{4,1} = [num2str(order(3)) 'th Pade Approx.'];
% Plotting:
figure(1)
subplot(211)
plot(w/pi*T,magZ,'b:.',w/pi*T,ga1,'r',w/pi*T,ga2,'g',w/pi*T,ga3,'k')
grid on
title(['Frequency Response of SINC Fcn (Ts = ' num2str(T) ' sec)'])
xlabel('Normalized to w/(pi/T)')
ylabel('|SINC|')
legend(strname{1,1},strname{2,1},strname{3,1},strname{4,1})
subplot(212)
plot(w/pi*T,angZ/pi*180,'b:.',w/pi*T,ph1/pi*180,'r',w/pi*T,ph2/pi*180,'g',w/pi*T,ph3/pi*180,'k')
grid on
xlabel('Normalized to w/(pi/T)')
ylabel('ang(SINC) deg')
legend(strname{1,1},strname{2,1},strname{3,1},strname{4,1})
figure(2)
subplot(211)
semilogx(w/pi*T,magZ,'b:.',w/pi*T,ga1,'r',w/pi*T,ga2,'g',w/pi*T,ga3,'k')
grid on
title(['Frequency Response of SINC Fcn (Ts = ' num2str(T) ' sec)'])
xlabel('Normalized to w/(pi/T)')
ylabel('|SINC|')
legend(strname{1,1},strname{2,1},strname{3,1},strname{4,1})
subplot(212)
semilogx(w/pi*T,angZ/pi*180,'b:.',w/pi*T,ph1/pi*180,'r',w/pi*T,ph2/pi*180,'c',w/pi*T,ph3/pi*180,'k')
grid on
xlabel('Normalized to w/(pi/T)')
ylabel('ang(SINC) deg')
legend(strname{1,1},strname{2,1},strname{3,1},strname{4,1});
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
