How to add the signals according to time?

3 views (last 30 days)
Hello,
  1. I want to add the 3 decaying exponential sinusoids according to the timwe in one graph. I used hold on & hold off. But that is not the correct way.
  2. I want the pattern(1 complete cycle(combination of 3 exp signals)) to be repetitive.
clc;
close all;
clear all;
t=0:0.001:0.3;
a=-7.4*exp(-t/0.01).*sin(2*pi*(10)*t);
t1=0.3:0.001:0.4;
b=10^7*exp(-t1/0.02).*sin(2*pi*(10)*t1);
b1=flip(b);
t2=0.4:0.001:0.75;
c=-8.5^10*exp(-t2/0.02).*sin(2*pi*(10)*t2);
c1=flip(c);
t3=0:0.001:0.1;
d=sin(2*pi*50*t3);
figure(1)
plot(t/38,a,'b');
hold on
plot(t1/38,b1,'b');
hold on
plot(t2/38,c1,'b');
hold on
plot(t3,d);
hold off
  2 Comments
Reji G
Reji G on 21 Apr 2022
Edited: Reji G on 21 Apr 2022
In one x axis, from 0 to 0.3 seconds, signal 'a' should be plotted. In the same axis, from 0.3 to 0.4 signal b1 should be plotted. From 0.4 to 0.75 signal c1 should be plotted.
After 0.75 second the entire plot should repeat.

Sign in to comment.

Accepted Answer

Mathieu NOE
Mathieu NOE on 21 Apr 2022
Edited: Mathieu NOE on 21 Apr 2022
hello
try this (i made a few mods , see the comments)
clc;
close all;
clear all;
% In one x axis, from 0 to 0.3 seconds, signal 'a' should be plotted.
% In the same axis, from 0.3 to 0.4 signal b1 should be plotted.
% From 0.4 to 0.75 signal c1 should be plotted.
% After 0.75 second the entire plot should repeat.
dt = 0.001;
t1=0:dt:0.3-dt; % remove one sample at the end ( dt) to avoid duplicate with next segment first point
a=-7.4*exp(-t1/0.01).*sin(2*pi*(10)*t1);
t2=0.3:dt:0.4-dt; % remove one sample at the end ( dt) to avoid duplicate with next segment first point
b=10^7*exp(-t2/0.02).*sin(2*pi*(10)*t2);
b1=flip(b);
t3=0.4:dt:0.75;
c= + 8.5^10*exp(-t3/0.02).*sin(2*pi*(10)*t3); % changed sign from - to + here because it looked weird to me
c1=flip(c);
t=[t1 t2 t3];
y = [a b1 c1];
figure(1)
plot(t/38,y,'b');
% create repetitions of the signal
rep = 10; % repetitions
y_rep = repmat(y,[1 rep]);
t_rep = (0:numel(y_rep)-1)*dt;
figure(2)
plot(t_rep/38,y_rep,'b');

More Answers (0)

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!