Clear Filters
Clear Filters

I have created a code to graph a function, but I want to repeat 10 times that signal every 3 sec in time in the graph, so it looks like a periodic signal, any ideas how?

4 views (last 30 days)
This is the code I have so far
A = 2
t = linspace(-2, 2, 1000);
a = exp(-0.5*t)
y = A*a.*(sin(2*pi*3*t)) .* (ustep(t+1)-ustep(t-1))
plot(t, y, 'LineWidth', 2)
xlabel('t');
ylabel('y');
title('L2E1');
grid on;

Accepted Answer

Star Strider
Star Strider on 24 Mar 2022
I do not understand the units if ‘t’ so I have no idea how this corresponds to the ‘10 times every 3 sec’ requirement. I will defer to you to determine that.
This should get you started —
ustep = @(t) t>0;
A = 2;
t = linspace(-2, 2, 1000);
a = exp(-0.5*t);
y = A*a.*(sin(2*pi*3*t)) .* (ustep(t+1)-ustep(t-1));
figure
plot(t, y, 'LineWidth', 2)
xlabel('t');
ylabel('y');
title('L2E1');
grid on;
env = envelope(y, 21, 'analytic'); % Signal Envelope
Lv = env > min(env); % Extract Signal Boundaries
repeats = 10;
yv = repmat(y(Lv), 1, repeats); % Replicate Signal
tv = (0:numel(yv)-1) * (t(2)-t(1)); % Create Corresponding Time Vector
figure
plot(tv, yv)
grid
xlim([min(tv) max(tv)])
title(sprintf('Repeats = %d, Time interval: %.0f to %.1f Units', repeats, min(tv), max(tv)))
.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!