Envelope function of a signal

I have two sine signal with me and I wanted to find an envelope of both the signal. Could anyone tell me how to do that?

 Accepted Answer

Use the envelope function.
t = linspace(0, 1, 1E+3);
s = sin(2*pi*t*5) .* sin(2*pi*t*100);
[senvu,senvl] = envelope(s, 10, 'peak');
figure
plot(t, s, 'DisplayName','Signal')
hold on
plot(t, senvu, '-m', 'LineWidth',2, 'DisplayName','Upper Envelope')
plot(t, senvl, '-c', 'LineWidth',2, 'DisplayName','Lower Envelope')
hold off
grid
.

2 Comments

Its showing error like below
Index in position 1 is invalid. Array indices must be positive integers or logical values.
Error in myenvelope>envelope (line 159)
t=linespace(0,1,1E+3); (for this line)
This is misspelled:
t=linespace(0,1,1E+3); % (for this line)
Because of that, MATLAB does not recognise it as a function, and considers it a variable, throwing the error.
If you copy and paste my code exactly as I wrote it (perhaps using your own ‘s’ function instead), it should run without error.
.

Sign in to comment.

More Answers (0)

Products

Release

R2022a

Tags

Asked:

on 29 Oct 2022

Commented:

on 29 Oct 2022

Community Treasure Hunt

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

Start Hunting!