plot a damped sine wave in matlab

To plot a damped sine wave in Matlab, you can use the following equation:

main.m
y = A*exp(-B*t).*sin(C*t + D);
31 chars
2 lines

where A, B, C, and D are constants that define the amplitude, decay rate, frequency, and phase shift of the wave, respectively, and t is the time domain vector.

To plot the wave, you can use the plot function:

main.m
% Define the constants
A = 1;      % Amplitude
B = 0.1;    % Decay rate
C = 2*pi;   % Frequency
D = pi/2;   % Phase shift

% Create the time domain vector
t = 0:0.01:10;

% Calculate the damped sine wave
y = A*exp(-B*t).*sin(C*t + D);

% Plot the wave
plot(t, y);
xlabel('Time');
ylabel('Amplitude');
title('Damped Sine Wave');
328 chars
18 lines

This code will generate a graph of the damped sine wave with the specified amplitude, decay rate, frequency, and phase shift.

gistlibby LogSnag