Repeating x-axis for rectangular signal
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
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 件のコメント
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
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
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
Star Strider
2019 年 1 月 25 日
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
2019 年 1 月 25 日
islocalmax sounds interesting. How can I use this to find my pos and neg flanks?
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
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
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 件)
カテゴリ
ヘルプ センター および File Exchange で Descriptive Statistics についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
