Skip to main content

How to plot a Continuous Time Sequence and Discrete Time Sequence in Matlab

1. For Continuous Time Sequence:

       Use the function:  plot(X-axis, Y-axis)

         For example to plot a parabolic function p(t)=  At^2 for t>=0

                                                                                   0        for t<0

          Code:

         %UNIT PARABOLIC FUNCTION

t=linspace(-20,20,20);      %range of X-asis

A=1;                  %amplitude of the function for A=1 it is called unit parabolic function

p=[t>=0].*(A.*t.^2)/2;     %parabola equation as defined above

subplot(1,2,1);                  %the graph occupies 1st position in 1x2 grid

plot(t,p); %plot(X-axis is represented here as t, Y-axis is represented by p here)

xlabel('t---->')                 %naming the x-axis in the graph

ylabel('p(t)---->');           %naming the y-axis in the graph

title('Unit parabolic Signal'); %title of the graph

grid on; 

 The output graph is shown below:

 

2. For Discrete Time Sequence:

       Use the function:  stem(X-axis, Y-axis)

         For example to plot a parabolic function p(t)=  At^2 for t>=0

                                                                                    0       for t<0

          Code:

%UNIT PARABOLIC FUNCTION

t=linspace(-20,20,20);      %range of X-asis

A=1;        %amplitude of the function for A=1 it is called unit parabolic function

p=[t>=0].*(A.*t.^2)/2;     %parabola equation as defined above

subplot(1,2,1);                  %the graph occupies 2nd position in 1x2 grid

stem(t,p); %stem(X-axis is represented here as t, Y-axis is represented by p here)

xlabel('t---->')                 %naming the x-axis in the graph

ylabel('p(t)---->');           %naming the y-axis in the graph

title('Unit parabolic Signal'); %title of the graph

grid on; 

 The output graph is shown below: 



So from the above two examples it is clear that we can generate the continuous time graph using plot function and discrete time graph using stem function for the same function keeping all other lines of code same.

Comments

Popular posts from this blog

Arduino Code to connect a flame sensor and gas sensor

The code below is uded to interface arduino with a flame sensor and a gas sensor together: int redLed = 12; int greenLed = 13; int smokeA0 = A0; int flamePin = 11; int Flame = HIGH; int sensorThres=100; void setup()  {   pinMode(redLed, OUTPUT);   pinMode(greenLed,OUTPUT);   pinMode(flamePin, INPUT);   pinMode(smokeA0,INPUT);   Serial.begin(9600); } void loop()  {   int analogSensor = analogRead(smokeA0);   Flame = digitalRead(flamePin);   if (Flame== LOW)   {     Serial.println("Fire!!!");     digitalWrite(redLed, HIGH);   }   else   {     Serial.println("No worries");     digitalWrite(redLed, LOW);   }   Serial.print("Pin A0: ");   Serial.println(analogSensor);   // Checks if it has reached the threshold value   if (analogSensor > sensorThres)   {     digitalWrite(greenLed, HIGH);   }   else   {     digitalWri...

Narrate a story from your own life experience which reflects kindness to the self or kindness to others or kindness to the environment.

As Shakespeare quoted ‘ Beauty lives with kindness’, kindness is a noble act of gentleness to others, to environment or to one’s own self.   It gives inner happiness and makes one feel good about oneself. I did not know the gift of kindness until I experienced it myself. In my first year in college I went on a trip to Dehradun along with my family. We were heading towards Haridwar. On our way through the jungles of the Garhwal Himalayas amidst the lust green forest, we saw a young girl suddenly appear from behind the trees and jump in front of our car. Our driver stopped the car just on time. There I saw a girl of about ten years old whimpering. Her dress was torn, her hands and feet were bruised and she looked starved. We gave her some food and water and asked about her whereabouts. By now we could understand that she was blind. She told us that she lived in Chidderwala and that she was out with her brother to fetch some fire woods, when it started to rain and she slipped and fe...