concept-collection / sample-4
sample-4 / waves.m
23 lines · 547 BBlameHistoryRaw
3% Damped harmonic oscillation — press the run button (▶) above.
4f = 2.5; % frequency (Hz)
5tau = 0.8; % decay time constant (s)
7t = linspace(0, 3, 600);
8y = damped_wave(t, f, tau);
10fprintf('samples: %d\n', numel(t));
11fprintf('peak amplitude: %.4f\n', max(abs(y)));
12fprintf('rms amplitude: %.4f\n', sqrt(mean(y.^2)));
14figure;
15plot(t, y);
16hold on;
17plot(t, exp(-t / tau), '--');
18plot(t, -exp(-t / tau), '--');
19hold off;
20title('Damped oscillation');
21xlabel('t (s)');
22ylabel('amplitude');
23legend('signal', 'envelope', '-envelope');