Generating discrete time periodic signal in matlab

561 views Asked by At

x[t] is a discrete time periodic signal defined as follows over one period

x[t] = {1 , 2 , 1 , 2 , 3 , 1 , 2 , 3 , 4.....}

I want to generate this as a periodic signal in the interval [0,100] in Matlab. But, I am unable to write a code for this.

2

There are 2 answers

2
ThomasIsCoding On BEST ANSWER

Maybe you can try arrayfun like below

X = arrayfun(@(k) 1:k, 2:4, "UniformOutput",false);
x = repmat([X{:}],1,2);

which gives

x =

   1   2   1   2   3   1   2   3   4   1   2   1   2   3   1   2   3   4
7
AlASAD WAIL On

In matlab if you want to generate a periodic signal there many methods one of them is :

%x is array that represent discrete time signal.
%y is generated periodic signal 
%n the number of periods

temp=x'*ones(1,n);
y=temp(:);
% where x' is transpose of x.
% if we suppose x=[1,2,3]
% if we want to repeat it five times we can say n = 5
% then temp will equal [ 1 1 1 1 1
%                        2 2 2 2 2
%                        3 3 3 3 3]
%fianlly y will equal [1 2 3 1 2 3 1 2 3 1 2 3 1 2 3]