MATLAB Answers

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

조회 수: 8(최근 30일)
Duy Dang
Duy Dang 2020년 10월 27일
답변: Star Strider 2020년 10월 27일
Hi, I'm new to matlab since I try to plot this signal as complex exponential form with 5 terms but I got stuck
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


Star Strider
Star Strider 2020년 10월 27일
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
hold on
hold off
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);
fplot(real(a), [-2 2])
hold on
fplot(imag(a), [-2 2])
fplot(abs(a), [-2 2], '--k')
hold off
legend('\Re(a)','\Im(a)', '|a|')

Community Treasure Hunt

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

Start Hunting!

Translated by