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