generating/plotting aperiodic functions

Hey guyssss,
Can someone explain to me how I can define an aperiodic square function in MATLAB? This is the code I have for time:
TimeStep = 0.0001*2*pi; %time increment
Time.Start = 0; %time interval starting time
Time.End = 10*2*pi; %time interval ending time
Time = Time.Start:TimeStep:Time.End;
I want to be able to change the width and amplitude of the function. Any help would be greatly appreciated :)

回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2011 年 11 月 11 日

0 投票

f below will be your function.
f=@(t,StartTime,EndTime,Amplitude) Amplitude*and(StartTime<t,t<EndTime);
To test it out:
t=-1:0.1:5;
y=f(t,0.3,3.6,1.3);
plot(t,y);grid on;

6 件のコメント

Sarah
Sarah 2011 年 11 月 11 日
Thanks for the feedback!
I have an additional question...
Based on the coding for time that I provided above, could I modify your code to simply make it:
f = @(Time,Amplitude); %function defined
TimeStep = 0.0001*2*pi; %time increment
Time.Start = 0; %time interval starting time
Time.End = 10*2*pi; %time interval ending time
Time = Time.Start:TimeStep:Time.End;
Amplitude = 1;
y = f(Time,Amplitude)
plot(Time,y); grid on;
Fangjun Jiang
Fangjun Jiang 2011 年 11 月 11 日
I guess I need your clarification. What are Time.Start and Time.End, the start/end time of your signal or the square? What is the "square function" that you are looking for? PWM?
Sarah
Sarah 2011 年 11 月 11 日
Time.Start represents the beginning of my sinusoidal signal. Time.End represents the end of my sinusoidal signal.
I want to add the aperiodic square, so just one square, to that sinusoidal signal. So essentially, at some point in the sinusoidal signal, you will see a jump to a different amplitude as a result of the square being added.
Fangjun Jiang
Fangjun Jiang 2011 年 11 月 11 日
Okay, then what is the start/end time of the square?
Sarah
Sarah 2011 年 11 月 11 日
It can be anywhere within the duration of the sinusoidal signal. I can change those parameters later, i just want the square to occur within the time duration of the signal.
Fangjun Jiang
Fangjun Jiang 2011 年 11 月 11 日
In the f() defined in my code, the StartTime and EndTime refer to the start/end time of the square. You can put the start/end time of your signal in the time vector.
t=(0:0.0001:10)*2*pi;
y=f(t,30,50,1.3);

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

カテゴリ

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

質問済み:

2011 年 11 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by