How to generate a wave form

4 ビュー (過去 30 日間)
Peeyush
Peeyush 2011 年 2 月 8 日
I wrote this code for generating a square wave for (t = -5.5 to 4.5) and a triangular wave in the same time domain. The code does produce the desired waveform but I think I am using a very elementary technique. Is there a more efficient way to generate wave forms without using the Wave Generation Toolbox in Signals and Systems. The code is pasted here:
%************************************************************ clear all; close all; % Generating Square Wave [u,t] = gensig('square',2,10,0.01); t = t-5.5; for n = 1:length(t) if or(t(n) < -4, t(n) > 4) u(n) = 0; end end plot(t,u); ylim([-2 2]); grid on;
% Generating triangular wave t = -5.5:0.01:4.5; h(1:length(t)) = 0; for n = 1:length(t) if t(n) == 0 pos1 = n; end end pos2 = pos1 + 1/0.01; i = 1; for n = pos1:pos2 h(n) = 1 - i*0.01; i = i+1; end figure(); plot(t,h); ylim([-2 2]); grid on; %************************************************************ Thanks.

採用された回答

Paulo Silva
Paulo Silva 2011 年 2 月 8 日
Just create the first period of the wave and use the repmat function to make the entire wave.
Example:
x=[0 1]
y=repmat(x,1,10)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePulse and Transition Metrics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by