How to plot a trapezoidal pulse in Matlab?

I want to plot a trapezoidal pulse that has user defined rise time and fall time i.e. slope of the edges of the trapezoid can be set by me.

6 件のコメント

Jasmine
Jasmine 2014 年 7 月 16 日
Have you already started to write any code for this? If so could you upload it please.
Jasmine
Jasmine 2014 年 7 月 16 日
編集済み: Jasmine 2014 年 7 月 16 日
function [] = trapezoidal_pulse (rise_time, fall_time, height, length)
pulse = zeros (2, 4);
pulse(1,2)=height;
pulse(2,2)=rise_time;
pulse(1,3)=height;
pulse(2,3)=pulse(2,2)+length;
pulse(2,4)=pulse(2,3)+fall_time;
plot(pulse(2,:),pulse(1,:))
Was this the sort of thing you were looking for? You could still improve this further by asking the user for a start time for the pulse (this currently assumes the pulse starts at t=0) and an end time if this wants to be after the pulse finishes. Also you could implement a GUI as a nice way to ask the user for inputs. Of course the plot can be improved with a title and axis labels. Hope this helps.
ANWESHA
ANWESHA 2014 年 7 月 16 日
編集済み: ANWESHA 2014 年 7 月 16 日
Yes..this is what i exactly wanted. Thank u so much. Can you please explain me how is it working??
Jasmine
Jasmine 2014 年 7 月 16 日
You're welcome. If you need any help on adding any of the extras I mentioned just let me know by commenting here again. I'll re-write my comment as an answer so that you can accept it :)
ANWESHA
ANWESHA 2014 年 7 月 16 日
Can you please explain me how it is working, so that I can modify it according to my need. Actually i have to plot it with respect to time and continuous pulse so that it is the reverse in the next period of time like in the image given below
Nur Izzati Aliah
Nur Izzati Aliah 2022 年 6 月 29 日
Name = 'Pizza_Hut_Service';
Type = 'Mamdani';
Version = 2.0;
NumInputs = 2;
NumOutputs = 0;
NumRules = 0;
AndMethod = 'min';
OrMethod = 'max';
ImpMethod = 'min';
AggMethod = 'max';
DefuzzMethod = 'centroid';
Name = 'Arrival_Rate';
Range = [0 1];
x = [1 3 4 6];
NumMFs = 1;
MF1 = 'MF':'trapmf';[1 3 4 6]
MF1 = trapmf(x,[1 3 4 6]);
Can someone help with this to get the graph in trapezoidal graph? This is very urgent I really need help from all of you

サインインしてコメントする。

 採用された回答

Jasmine
Jasmine 2014 年 7 月 16 日

3 投票

function [] = trapezoidal_pulse (rise_time, fall_time, height, length)
pulse = zeros (2, 4);
pulse(1,2)=height;
pulse(2,2)=rise_time;
pulse(1,3)=height;
pulse(2,3)=pulse(2,2)+length;
pulse(2,4)=pulse(2,3)+fall_time;
plot(pulse(2,:),pulse(1,:))

3 件のコメント

ANWESHA
ANWESHA 2014 年 7 月 16 日
or may be like this one.
Jasmine
Jasmine 2014 年 7 月 17 日
I have managed to make it work for up to 2 cycles...
function [] = trapezoidal_pulse (initial_height, on_height, delay_time, rise_time, fall_time, time_on, period, cycles)
pulse(:,1) = [initial_height,0];
pulse(:,2) = [initial_height,delay_time];
pulse(:,3) = [on_height,pulse(2,2)+rise_time];
pulse(:,4) = [on_height,pulse(2,3)+time_on];
pulse(:,5) = [initial_height,pulse(2,4)+fall_time];
pulse(:,6) = [initial_height,period];
for i=2:cycles
pulse(:,3+(2*i)) = [initial_height,period*(i-1)];
pulse(:,4+(2*i)) = [initial_height,pulse(2,3+(2*i))+delay_time];
pulse(:,5+(2*i)) = [on_height,pulse(2,4+(2*i))+rise_time];
pulse(:,6+(2*i)) = [on_height,pulse(2,5+(2*i))+time_on];
pulse(:,7+(2*i)) = [initial_height,pulse(2,6+(2*i))+fall_time];
pulse(:,8+(2*i)) = [initial_height,period*i];
end
plot(pulse(2,:),pulse(1,:))
ANWESHA
ANWESHA 2014 年 7 月 18 日
thank u so much

サインインしてコメントする。

その他の回答 (4 件)

ANWESHA
ANWESHA 2014 年 7 月 17 日

1 投票

Can please anyone help me to draw the pulse in matlab as given in the figure above?
vartan
vartan 2014 年 10 月 23 日
編集済み: vartan 2014 年 10 月 23 日

1 投票

This code should work for more than 2 cycles..
function [] = trap (initial_height, on_height, delay_time, rise_time, fall_time, time_on, period, cycles)
pulse(:,1) = [initial_height,0];
pulse(:,2) = [initial_height,delay_time];
pulse(:,3) = [on_height,pulse(2,2)+rise_time];
pulse(:,4) = [on_height,pulse(2,3)+time_on];
pulse(:,5) = [initial_height,pulse(2,4)+fall_time];
pulse(:,6) = [initial_height,period];
for i=2:cycles
pulse(:,1+(6*(i-1))) = [initial_height,period*(i-1)];
pulse(:,2+(6*(i-1))) = [initial_height,pulse(2,1+(6*(i-1)))+delay_time];
pulse(:,3+(6*(i-1))) = [on_height,pulse(2,2+(6*(i-1)))+rise_time];
pulse(:,4+(6*(i-1))) = [on_height,pulse(2,3+6*(i-1))+time_on];
pulse(:,5+(6*(i-1))) = [initial_height,pulse(2,4+6*(i-1))+fall_time];
pulse(:,6+(6*(i-1))) = [initial_height,period*i];
end
plot(pulse(2,:),pulse(1,:))
example:
trap (0, 1, 0, 1e-1, 1e-1,1 , 2, 5)
Jhon Lasso
Jhon Lasso 2017 年 11 月 2 日

0 投票

buen dia necesito hacer un trapezoide en matlab en 2d como lo hago?
Seungmin Lee
Seungmin Lee 2018 年 7 月 5 日
編集済み: Seungmin Lee 2018 年 7 月 5 日

0 投票

i try to above same code...but the function code is error.
how to solve the problem...
function []= trap (0, 1, 0, 1e-1, 1e-1,1 , 2, 5,4)
pulse(:,1) = [initial_height,0];
pulse(:,2) = [initial_height,delay_time];
pulse(:,3) = [on_height,pulse(2,2)+rise_time];
pulse(:,4) = [on_height,pulse(2,3)+time_on];
pulse(:,5) = [initial_height,pulse(2,4)+fall_time];
pulse(:,6) = [initial_height,period];
for i=2:cycles
pulse(:,1+(6*(i-1))) = [initial_height,period*(i-1)];
pulse(:,2+(6*(i-1))) = [initial_height,pulse(2,1+(6*(i-1)))+delay_time];
pulse(:,3+(6*(i-1))) = [on_height,pulse(2,2+(6*(i-1)))+rise_time];
pulse(:,4+(6*(i-1))) = [on_height,pulse(2,3+6*(i-1))+time_on];
pulse(:,5+(6*(i-1))) = [initial_height,pulse(2,4+6*(i-1))+fall_time];
pulse(:,6+(6*(i-1))) = [initial_height,period*i];
end
plot(pulse(2,:),pulse(1,:))

カテゴリ

ヘルプ センター および File ExchangeProgramming についてさらに検索

質問済み:

2014 年 7 月 16 日

コメント済み:

2022 年 6 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by