필터 지우기
필터 지우기

how can i plot positive magnitude only of a sine wave

조회 수: 33 (최근 30일)
ALI DRIDI
ALI DRIDI 2020년 8월 4일
댓글: ALI DRIDI 2020년 8월 10일
i have been trying to plot the half positive of the sine wave without displaying the negative i couldnt find a way for it this is the function of the sine wave.
DC_Voltage = ((A) * sin((2)*(pi*F)*(T)+(Phase)));

채택된 답변

KSSV
KSSV 2020년 8월 4일
% get the index of only positive values
idx = DC_Voltage>=0 ;
plot(DC_Voltage(idx))

추가 답변 (1개)

Sriram Tadavarty
Sriram Tadavarty 2020년 8월 4일
Hi Ali,
From next time, please post the code you tried and where you have struck. So, that if one wants to try out the things, it helps to provide proper answer. Though you ask for plot of it, you haven't shown what is tried to plot for it.
I did take some possible values and tried to code what you are looking for.
A = 0.5;
F = 1000;
T = 0:1/(20*F):2/F;
Phase = 0;
DC_Voltage = ((A) * sin((2)*(pi*F).*(T)+(Phase)));
figure
plot(T,DC_Voltage)
% time stamps of DC_Voltage
DC_Voltage_Negative_Idx = DC_Voltage < 0;
DC_Voltage(DC_Voltage_Negative_Idx) = 0;
figure
plot(T,DC_Voltage)
% If you are not after the plot with T, then you can directly use plot(DC_Voltage(DC_Voltage >= 0))
Hope this helps.
Regards,
Sriram
  댓글 수: 1
ALI DRIDI
ALI DRIDI 2020년 8월 10일
for this coding it displays the positive mgnitude without the negative and i wanted to reverse the negative magnitude not = 0, but the plot(DC_Voltage(DC_Voltage >= 0)) is giving the plot of half time stamps of the original sine wave, when i add the 'T' for X axis it gives error message (error using plot vectors are not the same length. below is the output of plot(DC_Voltage(DC_Voltage >= 0)) without time stamp.

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

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by