Programmer
Programmer

Reputation: 8687

Plotting a Continuous signal

I am trying to exactly print a continuous signal as per image below:

enter image description here

Below is my code:

x=[0 0 0 1 1 1 1 1 1 -1 -1 0 0];
n=[6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 ];
subplot(2,2,2);
axis([min(n)-10,max(n)+10,min(x)-10,max(x)+10]);
plot(n,x); 
grid on;
xlabel('Time');
ylabel('x2(t)');
title('Continous Signal');

But the output plot figure is not the same as per expectations:

enter image description here

Is it that in MATLAB we cannot display continuous signal properly? If yes what changes I need to make in my code.

Why do the signal values are not connected via a straight line - it makes a curve (or slanted straight line)?

Upvotes: 2

Views: 312

Answers (1)

Robert Seifert
Robert Seifert

Reputation: 25232

You're looking for the stairs function:

x = [0 0 0 1 1 1 1 1 1 -1 -1 0 0];
n = [-6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 ];

stairs(n,x); 

enter image description here

Upvotes: 6

Related Questions