Untitled

 avatar
unknown
plain_text
a month ago
2.1 kB
3
Indexable
% Step 1: Load data from Excel
filename = 'your_file.xlsx'; % Replace with your actual file name
data = readtable(filename, 'VariableNamingRule', 'preserve'); % Preserve original column names

% Step 2: Assign correct column names
time = data.('Time (s)'); % Replace with the actual name of the time column
abs_accel = data.('Absolute Acceleration (m/s^2)'); % 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: Generate or Load Displacement Data
time = linspace(0, 10, 1000); % Time in seconds
displacement = 10 * exp(-0.1 * time) .* cos(2 * pi * 1 * time); % Example damped oscillation

% Step 5: Find Peaks and Period
[peaks, peak_times_indices] = findpeaks(displacement); % Identify peaks
peak_times = time(peak_times_indices); % Get the times of the peaks

% Calculate the period (T) assuming the data is evenly spaced
T = mean(diff(peak_times)); % Average time difference between consecutive peaks

% Step 6: Calculate Logarithmic Decrement Using the Formula
num_cycles = length(peaks) - 1; % Number of complete cycles
log_dec = zeros(num_cycles, 1); % Preallocate array for log decrement

for i = 1:num_cycles
    % Using the formula δ = (1/n) * ln(x(t) / x(t + nT))
    n = 1; % Number of cycles (can be adjusted for larger intervals)
    if i + n <= length(peaks) % Ensure indices are within range
        log_dec(i) = (1/n) * log(peaks(i) / peaks(i + n));
    end
end

% Step 5: Plot the Results
figure;

% Plot displacement vs. time
subplot(2, 1, 1);
plot(time, displacement, '-b', 'LineWidth', 1.5);
hold on;
plot(peak_times, peaks, 'ro');
xlabel('Time (s)');
ylabel('Displacement (m)');
title('Displacement vs. Time');
grid on;

% Plot logarithmic decrement vs. cycle number
subplot(2, 1, 2);
cycle_numbers = 1:num_cycles;
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 the calculated values
disp('Logarithmic Decrement for each cycle:');
disp(log_dec);
Leave a Comment