Generating a Signal in MATLAB | MATLAB Tutorial

Generating a Signal in MATLAB | MATLAB Tutorial

Generating signal: Matlab Tutorial

Generating signal is a very basic step for solving digital signal processing problems in MATLAB. In this video tutorial, generating a given signal is explained.

So the question is,

First of all, we initialize T = 5. Then we create a ‘t’ vector varying from –T to T. Now, we first initialize the output signal with an array of zeros. By zeros(size(t)), an array of size equal to that of t-vector is created. Then, a for loop is run from 1 to length(t), if t(i) lies between 0 and –T, the signal is equated to t(i)+T, else if t(i) lies between 0 and T, the signal is equated to T–t(i). Then both, if condition and the for loop is ended and the signal is plotted with respect to time using plot function.

FUNCTIONS USED:

  1. size(A) returns a row vector whose elements contain the length of the corresponding dimension of A.
  2. zeros(x)returns an array of zeros where size vector x defines size(X).
  3. length(A)returns the length of the largest array dimension in A.

 





MATLAB CODE:

T = 5;
t = -T:T;
x = zeros(size(t));
for i=1:length(t)
   if t(i)<=0 && t(i)>-T
      x(i)=t(i)+T;
   elseif t(i)>0 && t(i)

RESULT: