How to plot the real and imaginary parts of a signal using subplot function.

I am new to Matlab and my Signals and Systems teach threw a tough lab at us that involves plotting the real and imaginary parts of a signal on the same plot but only using the subplot function, anything helps.

2 Comments

What have you tried? Provide some example code
t = 0:0.1:10;
a = cos(pi./6*t);
subplot (2,1,1);
plot(a);
b = sin(pi./6*t);
subplot (2,1,2);
plot(b);
MatHelpFig.PNG

Sign in to comment.

 Accepted Answer

Ok, you're pretty much there already. Just a few things:
  • plot t on the x-axes
  • title the plots
t = 0:0.1:10;
a = cos(pi./6*t);
subplot (2,1,1);
plot(t,a);
% \pi appears as the symbol
title('cos(\pi/6*t)')
% similar for b
Additionally, you could use the real/imag functions to define a and b:
% I use 1i as the imaginary number. That way, if you redefine i (e.g., in a loop), it will error
x=exp(1i*pi./6*t);
a=real(x);
b=imag(x);

More Answers (2)

Thank you so much, from what I gathered from the write-up we weren't supposed to use real and imag, but I will keep it in mind.

1 Comment

I believe the problem is saying that you can't use real/imag to create the titles, but that it is ok to use it for the data

Sign in to comment.

Write MATLAB code to plot the magnitude and phase of the following complex exponential function. Also plot the real and imaginary parts of the given signal using subplot command.
z=300 ej(4ᴨt-0.75)

1 Comment

In the future, please don't ask additional questions as an Answer. But:
  • abs(z) will give you the magnitude
  • angle(z) will give you the phase
  • everything else as in my answer above

Sign in to comment.

Categories

Find more on MATLAB in Help Center and File Exchange

Products

Asked:

on 21 Jan 2020

Commented:

on 27 Jul 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!