How to generate a square periodic wave?

12 ビュー (過去 30 日間)
Joe Koning
Joe Koning 2013 年 4 月 25 日
コメント済み: winkmal 2018 年 3 月 26 日
I need to create a continuous wave, however, the following method will not work for what i intend to do. ie
fs = 10000;
t = 0:1/fs:1.5;
x2 = square(2*pi*50*t);
This is because, as the wave is being called inside of a function, which generates derivitves for the solutions to a ODE, the equation needs to call on specific times of t at that point in the function, rather than just from a t-array as shown above. Is there any other way i could create this square wave, using the same frequency?

回答 (1 件)

Wayne King
Wayne King 2013 年 4 月 25 日
編集済み: Wayne King 2013 年 4 月 25 日
Perhaps I don't understand your post, but if you create the square wave as shown above, then why can't you obtain the value of the resulting vector (function) at specific times?
fs = 10000;
t = 0:1/fs:1.5;
x2 = square(2*pi*50*t);
Now you know the interval between every value in the waveform. If I want the value of the waveform at 0.02 seconds, you know that corresponds to
x(201)
and so on.
  2 件のコメント
Joe Koning
Joe Koning 2013 年 4 月 25 日
hmmm well im using ode15s to solve a differential equation which is affected by this square wave, so as far as im aware, the intervals in the equations shown above wouldnt match up to the time vector that is output by ode15s which corresponds to the solution array?
winkmal
winkmal 2018 年 3 月 26 日
A bit late, but how about an anonymous function?
x2 = @(t) square(2*pi*50*t);
If you use this in your RHS function, Matlab should be able to evaluate it at any value of t.

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

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by