Repeating x-axis for rectangular signal
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
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
2019년 1월 24일
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
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
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.)
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))
islocalmax sounds interesting. How can I use this to find my pos and neg flanks?
I would use the 'FlatSelection' (link),'first' and 'last' name-value pair arguments. You may have to use 'MinSeparation' (link) as well.
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.
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개)
카테고리
도움말 센터 및 File Exchange에서 Descriptive Statistics에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
