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

57 views (last 30 days)
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.

Accepted Answer

Sindar
Sindar on 21 Jan 2020
Edited: Sindar on 21 Jan 2020
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)

Hayden Bingham
Hayden Bingham on 21 Jan 2020
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
Sindar
Sindar on 21 Jan 2020
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.


Tabraiz Khan
Tabraiz Khan on 26 Jul 2020
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
Sindar
Sindar on 27 Jul 2020
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

Community Treasure Hunt

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

Start Hunting!