0
$\begingroup$

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');

enter image description here

enter image description here

$\endgroup$
1
  • $\begingroup$ 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. $\endgroup$
    – Royi
    Mar 29, 2023 at 7:41

2 Answers 2

6
$\begingroup$

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');

enter image description here

$\endgroup$
5
  • $\begingroup$ 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 $\endgroup$
    – DSP_CS
    Mar 30, 2023 at 4:30
  • $\begingroup$ @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. $\endgroup$
    – Hilmar
    Mar 31, 2023 at 8:54
  • $\begingroup$ @Hilmar, Wouldn't that be just like scaling the cosine with exp((1/timeConstant) * t)? $\endgroup$
    – Royi
    Apr 2, 2023 at 8:46
  • $\begingroup$ @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)]$ $\endgroup$
    – Hilmar
    Apr 2, 2023 at 19:45
  • $\begingroup$ @Hilmar, it was half rhetoric :-). See my answer where I wrote that to the OP. $\endgroup$
    – Royi
    Apr 3, 2023 at 4:52
1
$\begingroup$

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:

enter image description here

$\endgroup$
2
  • $\begingroup$ 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) $\endgroup$
    – DSP_CS
    Mar 29, 2023 at 6:02
  • $\begingroup$ 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. $\endgroup$
    – Royi
    Mar 29, 2023 at 6:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.