MATLAB Answers

How to plot both real and imaginary part of complex exponential?

22 views (last 30 days)
Duy Dang
Duy Dang on 27 Oct 2020 at 7:10
Answered: Star Strider on 27 Oct 2020 at 12:20
Hi, I'm new to matlab since I try to plot this signal as complex exponential form with 5 terms but I got stuck
clc;
clear all;
close all;
t0 = 0;
T = 10;
k = 1:6
w = 2*pi/T
syms t
x = t^2 +(j*2*pi*t)
x1 = real(x)
y = imag(x)
k1 = -2: 2; %%% 5 terms
a = (1/T)*int(x*exp(-j*k1*w*t),t,t0,t0+T);
%%% i dont know how to plot it please help

  0 Comments

Sign in to comment.

Answers (1)

Star Strider
Star Strider on 27 Oct 2020 at 12:20
For best results, replace ‘j’ with ‘1j’, then convert the result to double to use plot (since fplot is likely to be more difficult with discrete values of ‘k1’):
a = (1/T)*int(x*exp(-1j*k1*w*t),t,t0,t0+T);
num_a = double(a); % Convert To ‘double’ To Plot
figure
plot(k1,real(num_a))
hold on
plot(k1,imag(num_a))
plot(k1,abs(num_a),'--k')
hold off
grid
legend('\Re(a)','\Im(a)', '|a|')
That should do what you want.
Otherwise, I would have suggested:
syms k2
a(k2) = (1/T)*int(x*exp(-1j*k2*w*t),t,t0,t0+T);
figure
fplot(real(a), [-2 2])
hold on
fplot(imag(a), [-2 2])
fplot(abs(a), [-2 2], '--k')
hold off
grid
legend('\Re(a)','\Im(a)', '|a|')
.

  0 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by