Envelope function of a signal

8 views (last 30 days)
vani
vani on 29 Oct 2022
Commented: Star Strider on 29 Oct 2022
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

Star Strider
Star Strider on 29 Oct 2022
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
vani
vani on 29 Oct 2022
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)
Star Strider
Star Strider on 29 Oct 2022
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)

Tags

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!