0

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.

Cris Luengo
  • 55,762
  • 10
  • 62
  • 120

2 Answers2

1

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]
Cris Luengo
  • 55,762
  • 10
  • 62
  • 120
AlASAD WAIL
  • 775
  • 4
  • 18
0

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
ThomasIsCoding
  • 96,636
  • 9
  • 24
  • 81
  • I don't want only this signal, I want this signal to repeat itself. The signal "x" you are getting is over one period. I want to get something like this- x={1 , 2 , 1 , 2 , 3 , 1 , 2 , 3 , 4, 1 , 2 , 1 , 2 , 3 , 1 , 2 , 3 , 4, ......} – Señora Penn May 02 '21 at 05:46
  • @SeñoraPenn See my update, which have two repetitions for example, and you can have more according to your needs. – ThomasIsCoding May 02 '21 at 14:24