help defining a square wave

21 ビュー (過去 30 日間)
Joe Koning
Joe Koning 2013 年 4 月 30 日
回答済み: Wharengaro Ruha 2019 年 10 月 2 日
Im trying to define a square wave that starts only after 0.01 milliseconds. The code is below. The amplitude and frequency are both correct from the code below but it starts immediately from time 0 rather than from time 0.01, as if the if statement below is always true. what is going wrong?
t= linspace(0,0.03,1000);
i_block = 0;
for k = 1:1000
t(k)
if t(k) >= 0.01
i_block = mod(t/period, 1) > 0.5;
i_block = -2*I*i_block + I;
end;
end;
  2 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 4 月 30 日
What is I?
Joe Koning
Joe Koning 2013 年 4 月 30 日
ah sorry, I is the required amplitude, in this case I = 20000; period = 1/2000

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

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 4 月 30 日
編集済み: Azzi Abdelmalek 2013 年 4 月 30 日
t= linspace(0,0.03,1000);
period=0.03/10
I=10
i_block = 0;
for k = 1:1000
t(k)
if t(k) >= 0.01
i_block(k) = mod(t(k)/period, 1) > 0.5;
i_block(k) = -2*I*i_block(k) + I;
end;
end;
plot(t, i_block,'r')
  2 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 4 月 30 日
or
t= linspace(0,0.03,1000);
period=0.03/10
I=10
idx=find(t>=0.01)
i_block(1:idx(1)-1)=0
i_block(idx) = mod(t(idx)/period, 1) > 0.5
i_block(idx) = -2*I*i_block(idx) + I
plot(t, i_block,'r')
Joe Koning
Joe Koning 2013 年 4 月 30 日
ahhh of course, thankyou

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

その他の回答 (1 件)

Wharengaro Ruha
Wharengaro Ruha 2019 年 10 月 2 日
I need to make a square wave
at 1v for 2000s
then -1v for 2000s
then 1v for 4000s
then -1v for 6000s
then 1v for 2000s

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by