Hey guys,
i have an rectangular signal i want to plot.
On the Y axis is the voltage from 0 to 3.3 V (24945x1 single) and on the X axis is the position of the motor (circle) from 0-360°. (24945x1 double)
I have both signals but like I exprected it when I do
plot(Angle, Voltage)
it is not working like i wish. How can i let the X axis repeat it self and not overlapping the other datapoints.

 채택된 답변

Star Strider
Star Strider 2019년 1월 24일

0 개 추천

Try something like this:
Angle = reshape(([1; 1; 1]*(0:359))', 1, []); % Create Data;
Voltage = reshape(sind([1; 10; 20]*(0:359))', 1, []); % Create Data;
figure
plot(Angle, Voltage) % Original Plot
contAngle = unwrap(Angle*pi/180)*180/pi; % Use ‘unwrap’ To Recover Serial Vector
figure
plot(contAngle, Voltage) % ‘Unwrapped’ Plot
xt = get(gca, 'XTick');
xtn = min(xt) : 90 : max(xt);
set(gca, 'Xtick',xtn, 'XTickLabel',ceil(rem(xtn,360.1)))
xlim([min(contAngle) max(contAngle)])

댓글 수: 8

youjarr
youjarr 2019년 1월 25일
Hey,
thanks for your fast response. This is exactly what i wanted but now I see that i maybe did a mistake somewhere.
To tell you the whole story:
The x-axis was for the time in seconds but i needed to change it into angles to see the rotation/position of the movement.
so i wrote this small algorithm to convert my time in seconds to angle in degree u see here.
t = rot90(t);
t = flipud(t);
t_start = t(1,1);
%Calculation of the dt of 1 cycle (0°-360°)
dt360_H1 = abs(PosNeg_Hall_1(1,2)-PosNeg_Hall_1(5,2));
dt360_H2 = abs(PosNeg_Hall_2(1,2)-PosNeg_Hall_2(5,2));
dt360_H3 = abs(PosNeg_Hall_3(1,2)-PosNeg_Hall_3(5,2));
%Take the mean value of this three dt´s
dt360 = (dt360_H1+dt360_H2+dt360_H3)/3;
for ii = 1:length(t_90)
calc = abs((360*(t_start-t_90(ii,1)))/dt360);
if(calc > 359.95 && calc <= 360)
app.sek2degp(ii,1) = 0;
t_start = t_90(ii,1);
else
app.sek2degp(ii,1) = calc;
end
end
To explain it a little bit more... one cycle starts at positive flank and ends at the fith positive flank this is equal to 0°-360°.
You think it is correct or logical what i have done here?
sek2deg will then be put in your written code as ContAngle
Star Strider
Star Strider 2019년 1월 25일
From the 2 plot images you posted, it appears that your time-to-angle conversions do what you want, so I assume they are correct.
(I cannot follow your code because I do not know what your data are. So I cannot comment on the logic.)
youjarr
youjarr 2019년 1월 25일
Thanks for your fast response. I hope now it is more readable. Im not sure about the if condition
%t = time vector
t = rot90(t);
t = flipud(t);
t_start = t(1,1); %My assumed start point for the time
%Calculation of the dt of 1 cycle (0°-360°) between
%the first pos. flank and the fifth pos. flank of all three Hall Signals
dt360_H1 = abs(PosNeg_Hall_1(1,2)-PosNeg_Hall_1(5,2));
dt360_H2 = abs(PosNeg_Hall_2(1,2)-PosNeg_Hall_2(5,2));
dt360_H3 = abs(PosNeg_Hall_3(1,2)-PosNeg_Hall_3(5,2));
%Take the mean value of this three dt´s
dt360 = (dt360_H1+dt360_H2+dt360_H3)/3;
for ii = 1:length(t_90)
%here I calculate the angle out of the time
calc = abs((360*(t_start-t_90(ii,1)))/dt360);
%This works like a "%" (modulo) but i am not reaching exactly the value
%360° so i can´t use modulo
if(calc > 359.95 && calc <= 360)
app.sek2degp(ii,1) = 0;
%if the "modulo" condition is true i save a new start/zero point
t_start = t_90(ii,1);
else
%Just save the converted value
app.sek2degp(ii,1) = calc;
end
end
As always, my pleasure.
I cannot test your code. The plot images you posted appear to be correct, so I assume your code is correct as well.
Note that if you have R2017b or later, you can use several functions, such as islocalmax (link) and ischange (link) to find the changes in your signal. You can also use the Signal Processing Toolbox findpeaks (link) function (R2007b and later versions).
Also, you can ‘tweak’ mod or rem, depending on the result you want:
x = linspace(0, 720);
x360 = ceil(rem(x,360.1))
youjarr
youjarr 2019년 1월 25일
islocalmax sounds interesting. How can I use this to find my pos and neg flanks?
Star Strider
Star Strider 2019년 1월 25일
I would use the 'FlatSelection' (link),'first' and 'last' name-value pair arguments. You may have to use 'MinSeparation' (link) as well.
youjarr
youjarr 2019년 1월 26일
I´m not understanding the option 'MinSeparation'?! Separation between what because i can type in what i want it seems the the plots always looks the same?
And How can I use islocalmax to identify Positive nd negative flanks?
It seems that it can work much better than im doing now with diff.
But i dont understand it perfectly and I think the noise is maby to difficult for that function.
Star Strider
Star Strider 2019년 1월 26일
From the documentation on islocalmax:
‘Minimum separation between local maxima, specified as the comma-separated pair consisting of 'MinSeparation' and a nonnegative scalar. ’
Another option is the ischange (link) function. That might be more applicalbe to what you want to do.
Please understand that without a representative sample of your data, I cannot specifically answer your questions. I can only suggest solutions, not knowing if they are appropriate.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

질문:

2019년 1월 24일

댓글:

2019년 1월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by