Untitled
% Step 1: Load data from Excel filename = 'example.xlsx'; % Replace with your file name data = readtable(filename); % Read the Excel file % Step 2: Assign correct column names (update these based on your data) time = data.Time_s_; % Replace with the actual name of the time column abs_accel = data.Absolute_Acceleration_m_s2_; % Replace with the actual name of the absolute acceleration column % Step 3: Find peaks in the absolute acceleration data [peaks, peak_times] = findpeaks(abs_accel, time); % Step 4: Calculate logarithmic decrement num_cycles = length(peaks) - 1; % Number of cycles log_dec = zeros(num_cycles, 1); % Preallocate array for log decrement for i = 1:num_cycles log_dec(i) = log(peaks(i) / peaks(i+1)); end % Step 5: Plot the results figure; % Plot absolute acceleration vs. time subplot(2, 1, 1); plot(time, abs_accel, '-b', 'DisplayName', 'Absolute Acceleration'); hold on; plot(peak_times, peaks, 'ro', 'DisplayName', 'Peaks'); xlabel('Time (s)'); ylabel('Absolute Acceleration (m/s^2)'); title('Absolute Acceleration vs. Time'); legend show; grid on; % Plot logarithmic decrement vs. cycle number subplot(2, 1, 2); cycle_numbers = 1:num_cycles; % Cycle numbers plot(cycle_numbers, log_dec, '-k', 'LineWidth', 1.5); xlabel('Cycle Number'); ylabel('Logarithmic Decrement (\delta)'); title('Logarithmic Decrement vs. Cycle Number'); grid on; % Display calculated values disp('Logarithmic Decrement for each cycle:'); disp(log_dec); % Optional: Save the figure saveas(gcf, 'logarithmic_decrement_analysis.png');
Leave a Comment