Nupur
Nupur

Reputation: 1

Is there a MATLAB function to count the number of encirclements of (-1, 0) when I have an FRD model?

I have an FRD model, and I am able to draw a Nyquist plot. I want to determine the number of encirclements of the critical point (-1, 0) in MATLAB.

I am attempting to use the real and imaginary parts obtained from [re_n, im_n, f_n] = nyquist(sys), where sys is a known FRD model. However, I have noticed that the real and imaginary parts extracted from the plot do not match those in 're_n' and 'im_n'. Is there a method in MATLAB to determine the number of encirclements without the need for manual inspection?

My code is as follows for reference:

function encirclements = countEncirclements(frd_model)
custom_frequencies = frd_model.Frequency;
[real_part, imag_part, frequencies] = nyquist(frd_model);

clockwise_crossings = 0;
counterclockwise_crossings = 0;

point_to_check = [-1, 0];

for ijn = 1:length(frequencies)-1

% Check if the Nyquist path crosses the line from (-1, 0)
if imag_part(ijn) > point_to_check(2)
if (real_part(ijn) < point_to_check(1)) && (real_part(ijn+1) >= point_to_check(1))
        clockwise_crossings = clockwise_crossings + 1;
       
elseif (real_part(ijn) > point_to_check(1)) && (real_part(ijn+1) <= point_to_check(1))
        counterclockwise_crossings = counterclockwise_crossings + 1;
       
end
end
end

% Calculate the number of encirclements
encirclements =  counterclockwise_crossings - clockwise_crossings;
disp(['Number of encirclements around (-1, 0): '   num2str(encirclements)]);
end

Upvotes: 0

Views: 88

Answers (0)

Related Questions