Hello everyone,
I was trying to change the line-width of the zplane figure in order to make it more visible.I tried the set command but it didnt work.How can i fix it so it can work?
Thanks in advance.
This is my code so far:
function Lab2_Part_One
close all;
clearvars;
% Create directory if it doesn't exist
directory = 'Ask1';
if ~isfolder(directory) %For versions before R2017b use exist
% instead of is folder
mkdir(directory);
end
% Given transfer function
num = [0.2 0]; % Numerator coefficients
den = [1 -0.7 -0.18]; % Denominator coefficients
w = -pi:pi/128:pi; % Frequency range
% Function calls
plotPoleZeroPlot(num, den, directory);
end
function plotPoleZeroPlot(num, den, directory)
% Function to plot the pole-zero plot
figure;
h = zplane(num, den);
% Set the properties for poles (red lines)
set(h_poles, 'Color', 'green', 'LineWidth', 2); % Change color to green and line width
% Set the properties for zeros (blue lines)
set(h_zeros, 'Color', 'magenta', 'LineWidth', 1.5); % Change color to magenta and line width
% Redraw the unit circle with the desired linewidth
hold on;
t = 0:0.01:2 * pi; % Define points for the unit circle
plot(cos(t), sin(t), 'Color', [0 0.4470 0.7410], 'LineWidth', 1); % Plot the unit circle with the desired linewidth
%grid on;
title('Pole-Zero Plot of the Transfer Function H(z)');
% Save the pole-zero plot in the specified directory as a PNG file
filename = fullfile(directory, 'pole_zero_plot.png');
saveas(gcf, filename);
end

 Akzeptierte Antwort

Star Strider
Star Strider am 3 Nov. 2023

1 Stimme

Changing the properties requirees a bit of handle-spelunking, however it is possible.
Try this —
[z,p,k] = ellip(4,3,30,200/500);
figure
zplane(z,p)
grid
title('4th-Order Elliptic Lowpass Digital Filter')
figure
hzp = zplane(z,p);
grid
title('4th-Order Elliptic Lowpass Digital Filter')
getgca = get(gca);
Kids = getgca.Children;
Kids(2).Color = 'g';
Kids(2).LineWidth = 2;
Kids(3).Color = 'm';
Kids(3).LineWidth = 1.5;
% figure
% hold on
% plot(Kids(1).XData, Kids(1).YData, ':')
% plot(Kids(2).XData, Kids(2).YData, 'xg', 'LineWidth',2)
% plot(Kids(3).XData, Kids(3).YData, 'om', 'LineWidth',1.5)
% hold off
% axis([[-1 1]*1.5 [-1 1]*1.25])
% grid
The zplane function creates 3 different line objects, and once they are found, changing their properties is straightforward.
.

7 Kommentare

Konstantinos
Konstantinos am 4 Nov. 2023
Thanks a lot
Star Strider
Star Strider am 4 Nov. 2023
As always, my pleasure!
Additionally:
Kids(1): Unit Circle
Kids(2): Poles
Kids(3): Zeros
These are each line objects with their own properties. That should hold for all recent releases.
.
Well this is not always the case.When i use the zplane(b,a) where b and a are the numerator and denominator coefficients already defined by the user the unit circle and the zeros are "connected" and i dont know why.But when i use the zplace(d,g) with:
d = roots(numerator)
g = roots(denominator)
it works fine.
This image is without the use of function root:without the use of function root
The image above is generated by using the function roots.
Also in the second image the number 2 is disappearing.
So much for consistency. I was hoping that ordering would always work, It doesn’t.
So, Plan ‘B’
num = [0.2 0]; % Numerator coefficients
den = [1 -0.7 -0.18]; % Denominator coefficients
figure
zplane(num, den)
getgca = get(gca);
Kids = getgca.Children;
% Number = findobj(Kids','Type','text')
Lines = findobj(Kids, 'Type','line');
for k = 1:numel(Lines) % Match Markers To 'Lines' Indices
if strcmp(Lines(k).Marker, 'x')
Poles = k;
elseif strcmp(Lines(k).Marker, 'o')
Zeros = k;
elseif strcmp(Lines(k).Marker, 'none')
UnitCircle = k;
end
end
% Poles
% Zeros
% UnitCircle
Lines(Poles).Color = 'g';
Lines(Poles).LineWidth = 2;
Lines(Zeros).Color = 'm';
Lines(Zeros).LineWidth = 1.5;
This looks up the markers, saves the appropriate indices, and then does the appropriate assignments. You can change the ‘UnitCircle’ properties as well, if you want to. The same syntax works.
The ‘2’ is a separate text object. (This can be seen by removing the semicolon from the end of the ‘Kids’ assignment.) You would have to add that to your plot using roots. It always appears to be the first entry, so you can either refer to it as ‘Kids(1)’ or do:
Number = findobj(Kids','Type','text')
I added it (to be certain that it does what I want it to do) and then commented it out. Un-comment it to explore its properties to see how that text call works.
.
Nice solution.
I tried this instead which is based on your first comment.
num = [0.2 0]; % Numerator coefficients
den = [1 -0.7 -0.18]; % Denominator coefficients
plotPoleZeroPlot(num, den);
function plotPoleZeroPlot(num, den)
% Function to plot the pole-zero plot
figure;
% Obtain zeros and poles of the system
zeros_of_system = roots(num); % Zeros
poles_of_system = roots(den); % Poles
% Plot pole-zero plot
zplane(zeros_of_system, poles_of_system );
% Customize plot appearance
getgca = get(gca); %Returns the current axes.
Kids = getgca.Children;
Kids(1).Color = [0 0.4470 0.7410];
Kids(1).LineWidth = 2;
Kids(2).Color = 'r';
Kids(2).LineWidth = 2;
Kids(3).Color = 'r';
Kids(3).LineWidth = 2;
% Add title and grid to the plot
title('Pole-Zero Plot of the Transfer Function H(z)');
grid on;
end
It seems a little bit easier and less complex.
Star Strider
Star Strider am 4 Nov. 2023
Thank you!
It is easier, however it appears that the line objects do not always appear in the same order, for whatever reason. If you want them to all be the same colours and sizes, the first solution is easier. If you want them to be specifically different, the strcmp approach is necessary. It all depends on what you want.
Konstantinos
Konstantinos am 4 Nov. 2023
Thanks.I will keep in mind

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Version

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by