Generating a Signal in MATLAB | MATLAB Tutorial

byIti Tripathi

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)&lt;=0 &amp;&amp; t(i)&gt;-T
x(i)=t(i)+T;
elseif t(i)&gt;0 &amp;&amp; t(i)
```

RESULT:

Recommended Posts

Test Post

17 Feb 2018 - Tutorial

Counters using conditionally executed subsystems | Simulink Tutorial

16 Feb 2018 - Simulink, Tutorial