# How can i get a growing sinusoid in matlab?(by incorporating real part into exp command besides imaginary part which is already there)

I am trying to display a growing sinusoid in MATLAB and i know that imaginary part corresponds to oscillations but i am confused how can i incorporate real part in exp argument? I have also attached my current code and current out put and desired output

clc;clear;close all
% Generate a sine wave using exponential function
Fs = 50;      % Sampling frequency
f = 5;        % Frequency of the sine wave
t = 0:1/Fs:1;   % Time vector
x = exp(1j*2*pi*f*t);
% here in above line j is causing oscillation but i am confused how to change this whole argument

% Plot the result
plot(t, real(x));  % Plot the real part of the signal
xlabel('Time (s)');
ylabel('Amplitude');
title('Sine Wave Generated using Exponential Function');


• You don't control the real and the imaginary part of the harmonic exponent independently. The Euler formula always holds: $e^{ix} = \cos x + i\sin x$. So what you have in the exponent is both for the imaginary and the real and both are oscillating.
– Royi
Mar 29, 2023 at 7:41

Here is an alternative: you can pass a complex (not just an imaginary) exponent. The real part of the exponent controls the amplitude, the imaginary part the frequency.

The resulting signal is also complex: real part is a rising cosine, imaginary part is a rising sine.

%% exp rising sine
fs = 48000; % sample rate
nx = 24000;% half a second of data
f0 = 20; % 10 Hz frequency
timeConstant = .15; % 150 ms
t = (0:nx-1)'/fs; % time axis
k = (1/timeConstant+1i*2*pi*f0); % complex exponent
xc = exp(k.*t); % exponential function
xlabel('time in seconds');
clf;
plot(t,imag(xc));
xlabel('time in s');
grid('on');


• Yes it is some way near what i was looking for , but still there seems room for improvement. In your code "k = (1/timeConstant+1i*2*pif0); " when i remove "1/timeConstant" from"k"i get a sinusoidal wave without any damping but when i remove "1i*2*pif0" and only "1/timeConstant" remains in "k" we get a straight line but i was expecting a rising exponential Mar 30, 2023 at 4:30
• @engr: If you make the exponent real, the whole expression becomes real and plotting the imaginary part is pointless (it's zero). Plot the real part instead. Mar 31, 2023 at 8:54
• @Hilmar, Wouldn't that be just like scaling the cosine with exp((1/timeConstant) * t)?
– Royi
Apr 2, 2023 at 8:46
• @Royi: yes, of course. If $a,b \in\mathbb{R}$ then $e^{a+jb} = e^a\cdot e^{jb} = e^a \cdot [\cos(b) + j\cdot \sin(b)]$ Apr 2, 2023 at 19:45
• @Hilmar, it was half rhetoric :-). See my answer where I wrote that to the OP.
– Royi
Apr 3, 2023 at 4:52

You may use $$\log \left( \cdot \right)$$ or $$\exp \left( \cdot \right)$$ to build up the amplitude of the signal.

Basically create an AM Signal:

clear();
close();
clc();

% Generate a sine wave using exponential function
Fs = 500;      % Sampling frequency
f = 5;        % Frequency of the sine wave
t = 0:1/Fs:5;   % Time vector
x = sin(2 * pi * f * t);
finalAmp = 5; % Exp
d = 5 * (1 - exp(-0.5 * t)); % Exp
d = log(0.1 * t + 1);
% here in above line j is causing oscillation but i am confused how to change this whole argument

% Plot the result
plot(t, d .* x);  % Plot the real part of the signal
xlabel('Time (s)');
ylabel('Amplitude');
title('Sine Wave Generated using Exponential Function');


This yields:

• Thank you so much for your time and effort but actually i was looking for a way that imaginary part of expoential term corresposnds to oscillations and i was looking how can real part be added in the argument beside imaginary part(without using the approach of log) Mar 29, 2023 at 6:02
• I am not sure what you mean. The real part is a cosine and the imaginary part is the sine of the argument of the complex harmonic exponent. Replace what I did with your code (Just multiply your complex exponent by d) and the result will be the same.
– Royi
Mar 29, 2023 at 6:08