How to create a square wave signal
17 ビュー (過去 30 日間)
古いコメントを表示
Benedetta Bonini
2021 年 5 月 9 日
コメント済み: Benedetta Bonini
2021 年 5 月 11 日
I have to create a square wave of amplitude 0.19 and period 495 samples and I don't know how to do. I just have understood that in Matlab there is the command x=square(t) but I really don't know how to represent my period and my amplitude. Could someone help me please?
5 件のコメント
Jonas
2021 年 5 月 10 日
yes and no. samples per period refers to sampling frequency. normally you want a frequency e.g. of 2 Hz, which means 2 per second. during that second the signal is sampled several times which refers to the sampling frequency
Adam Danz
2021 年 5 月 10 日
This answer demonstrates a parameterized step function but you need to know the period and what you're describing is the number of samples within a period.
採用された回答
Scott MacKenzie
2021 年 5 月 10 日
編集済み: Scott MacKenzie
2021 年 5 月 11 日
Here's a brute-force solution. It's a bit odd, but it does create a square wave according to your specs (with one extra sample to round out the math):
amplitude = 0.19;
samples = 496;
y = [ones(1,samples/2)*amplitude/2, ones(1,samples/2)*amplitude/2*-1];
plot(y);

Just having a bit of fun with this. The code below adds a variable cycles to output >1 cycle, if desired.
amplitude = 0.19;
samples = 496; % per cycle
cycles = 5;
y = [ones(1,samples/2)*amplitude/2, ones(1,samples/2)*amplitude/2*-1];
y = repmat(y, 1, cycles);
plot(y);

Here's a more compact and concise approach... (same output as above)
amplitude = 0.19;
samples = 496;
cycles = 5;
y = repmat([amplitude/2 -amplitude/2], samples/2, cycles);
y = y(:);
plot(y);
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Spectral Measurements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!