Question: Hi , I found this code on Chegg from the expert, and I never used the polar function, so could you please provide the comments

Hi, I found this code on Chegg from the expert, and I never used the polar function, so could you please provide the "comments"` on the code line below so I can understand it? Thank you!
``
clear
close all
clc
h = fir1(10,0.3); %FIR filter
figure; frevalz01(h,1);
%4
[b1, a1]=butter(10,0.3);%IIR filter
figure; frevalz01(b1,a1);
%5
N=20;
n=0:1:N-1;
```
```
%Fir filtering
y1=filter(h,1,x);
%IIR filtering
y2=filter(b1,a1,x);
figure;
subplot(211)
stem(n,y1);grid;xlabel('n');ylabel('y(n)');title('Output of FIR filter')
subplot(212)
stem(n,y2);grid;xlabel('n');ylabel('y(n)');title('Output of IIR filter')
Function script
function [P]= frevalz01(b,a,Ts)
%To get pole zero plot
P =[zeros(length(b)-1,1);roots(a)];
NP = length(P);
z =[zeros(length(a)-1,1);roots(b)];
NZ = length(z);
while P(1)== Z(1)
P = P(2:NP);
Z = Z(2:NZ);
NP = length(P);
NZ = length(Z);
end
if(nargin==2),Ts=1;end
clf; N =1024;
Rep = real(P);Imp = imag(P);
Rez = real(Z);Imz = imag(Z);
Ap = abs(P);Pp = angle(P);
Az = abs(Z);PZ = angle(Z);
maxz = max([AZ' Ap'1.1]);
if((NP==0) & (NZ =0))
polar( Pz, Az,'ro');hold on;
elseif((NZ==0) & (NP~=0))
polar( Pp, Ap,'mx');hold on;
else
if max(AZ)>max(Ap)
polar( PZ, AZ,'bo');hold on;
polar( Pp, Ap,'mx')
polar( Pp, Ap,'bx');hold on;
polar( Pz, Az,'mo')
end
end
[H1, w]= freqz(b,a,N,'whole');
Amp = abs(H1)';
Pha = angle(H1)';
w = w';
Amp =[ Amp(N/2+1:N ) Amp(1:N/2)];
w =[-w( N/2+1:-1:2) w(1:N/2)];
Pha =[ Pha( N/2+1:N ) Pha(1:N/2)];
w =-1:2/(length(w)-1):1;
w = w/2;
subplot(221)
maxz = max([Az' Ap'1.1]);
if((NP==0) & (NZ =0))
polar( PZ, Az,'mo');hold on;
elseif((NZ==0) & (NP~=0))
polar( Pp, Ap,'bx');hold on;
else
if max(Az)>max(Ap)
polar( PZ, Az,'mo');hold on;
polar( Pp, Ap,'bx')
else
polar( Pp, Ap,'bx');hold on;
polar( PZ, Az,'mo')
end
end
grid
c =-pi:2*pi/200:pi;
polar(c, ones(1,length(c)),'r');
title('Pole-Zero Plot of Filter')
axis([-maxz,maxz, -maxz, maxz])
hold off;
%Impulse response
h=filter(b,a,[1 zeros(1,49)]);
subplot(222)
stem(0:Ts:49*Ts,h,'r');
title('Impulse Response');grid;xlabel('n');ylabel('h(n)')
%Magnitude and phase responses
for k=1:N
if (Amp(k)==0) M(k)=-60;
else, M(k)=2*10* log10(Amp(k)); end
end
subplot(223), plot(w, M,'b')
title('Magnitude Response');grid;
xlabel('Normalized Frequency ')
ylabel('|H| in dB')
subplot(224), plot(w, Pha,'g')
title('Phase Response');grid;
xlabel('Normalized Frequency ')
ylabel('')
end
```
Hi , I found this code on Chegg from the expert,

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Electrical Engineering Questions!