How to convert trajectory of the current vector to grayscale.

37 views (last 30 days)
Dear sir,
Could you make help for coding. I attached the data.mat
First, I read the three phase current. After I use clarke transform and I get current vector (Is).
1. I established a 60×60 2D matrix to depict the trajectory, with (30,30) as the origin and 1 step size.
2. I calculate the trajectory of the current vector on the α-β plane. But it is not like the below picture.
why is it that picture?
3. The probability that each point in the current vector trajectory falls into a certain grid is calculated as the grayscale of the point.
4. I want use mean value filtering algorithm to filter out the points with low probability,
5. I want normalize the value of each pixel in the 2D matrix according to the min-max normalization.
But ı get very bad result like that. The circle should be large.
The circle should be large, like below picture
load("data.mat")
Ia = data(:,1);
Ib = data(:,2);
Ic = data(:,3);
%% Clarke (3 phase → αβ)
I_alpha = Ia;
I_beta = (1/sqrt(3))*(Ia + 2*Ib); % Clarke formülü
% Current vector
Is = I_alpha + 1j*I_beta;
plot(Is)
%% 1⃣ 60×60 2D matrix
grid_size = 60; % 60x60 matrix
origin = [30, 30]; % (30,30) origin
step = 1; % 1
traj_matrix = zeros(grid_size, grid_size);
%% 2⃣ Place the current vector on 2D matrix
for i = 1:length(Is)
Ia_val = real(Is(i));
Ib_val = imag(Is(i));
xi = round(Ia_val/step + origin(1));
yi = round(Ib_val/step + origin(2));
if xi >= 1 && xi <= grid_size && yi >= 1 && yi <= grid_size
traj_matrix(yi, xi) = traj_matrix(yi, xi) + 1;
end
end
plot(traj_matrix)
%%3⃣ Probability matrix (grayscale intensity)
traj_prob = traj_matrix / sum(traj_matrix(:));
%%4⃣ Mean Value filtering (noise reduction)
kernel = fspecial('average', [3 3]); % 3x3 mean filter
traj_filtered = imfilter(traj_prob, kernel, 'replicate');
%%5⃣ Min–max normalization
min_val = min(traj_filtered(:));
max_val = max(traj_filtered(:));
traj_norm = (traj_filtered - min_val) / (max_val - min_val);
%%6⃣ visualization
figure;
imshow(traj_norm, []);
title('Normalized 2D Current Vector Trajectory (αβ plane)');
xlabel('\alpha axis');
ylabel('\beta axis');
colormap('gray');
colorbar;

Accepted Answer

Matt J
Matt J on 9 Oct 2025 at 3:16
Edited: Matt J on 9 Oct 2025 at 3:45
Maybe this is what you wanted?
load("data.mat")
Ia = data(:,1);
Ib = data(:,2);
Ic = data(:,3);
%% Clarke (3 phase → αβ)
I_alpha = Ia;
I_beta = (1/sqrt(3))*(Ia + 2*Ib); % Clarke formülü
plot(I_alpha, I_beta,'.'); axis equal
%% 1⃣ 60×60 2D matrix
grid_size = 60; % 60x60 matrix3
traj_prob = histcounts2(I_alpha,I_beta, grid_size, Norm="prob");
%%4⃣ Mean Value filtering (noise reduction)
kernel = fspecial('average', [3 3]); % 3x3 mean filter
traj_norm = rescale( imfilter(traj_prob, kernel, 'rep') );
%%6⃣ visualization
figure;
imagesc(traj_norm)
title('Normalized 2D Current Vector Trajectory (αβ plane)');
xlabel('\alpha axis');
ylabel('\beta axis');
colormap gray; colorbar;
  2 Comments
Bahadir
Bahadir on 13 Oct 2025 at 11:00
Edited: Bahadir on 13 Oct 2025 at 11:46
@Matt J Thank you,
The circle you drew at above is exactly the graph I wanted. Because it is not contain any error data, it shuold be perfectly circle.
But I have some questions.
1) My matrix is 60x60. How do I draw the radius of the circle as 25 within this matrix?
Because the circle is fixed to edge of matrix.
2) Although the circle drawn above is perfectly circular, when I look at the matrix values on the right and left sides of the circle, I see that the circle is not circular.
How can ı make perfectly circular?
3) The Plot of "Normalized 2D Current Vector Trajectory (αβ plane)" is grey scale picture.
How can I make it more distinct? In other words, how can I make the values of the gray pixels more distinct?
4) I attached new data which s3 fault.
load("data_s3.mat")
Ia = data(:,1);
Ib = data(:,2);
Ic = data(:,3);
%% Clarke (3 phase → αβ)
I_alpha = Ia;
I_beta = (1/sqrt(3))*(Ia + 2*Ib); % Clarke formülü
plot(I_alpha, I_beta,'.'); axis equal
This graph is incorrect because it should not be a perfect circle.
It should be like below. Because The semicircle should contain error information; the semicircle should be without error.
Thank you
Matt J
Matt J on 13 Oct 2025 at 14:42
Edited: Matt J on 13 Oct 2025 at 15:03
(1) You can use padarray and imresize to adjust the proportions of the circle, relative to the surrounding grid area.
(2) The spatial distribution of (I_alpha, I_beta) is not uniform around the circumference of the circle. Therefore, the image values will not be either.
(3) Use clim.
(4) If the graph is showing a perfect circle, then your data is a perfect circle.

Sign in to comment.

More Answers (0)

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!