Hi, I am calculating ground motion duration based on threshold level and it is frequency dependent. I roughly developed a code but don't understand what will be filter order?
3 次查看(过去 30 天)
显示 更早的评论
I try to calculate frequency dependent ground motion duration along with 12 Ormsby bandpass filter. I also using threshold level on total energy. I really don't understand whether I am right track or wrong and what will be filter order for Ormsby filter to deal with seismic signal? Do i need to use fft and ifft function to calculate ground motion duration or not? For 13 bandpass filter, Do i need to use 13 different filter order? I really need help, i am suffering for this question from last 1 month.
This is my code
clear all
% Load your seismic data (time and acceleration)
t = xlsread('San_Fernando_records', 'sheet1', 'A2:A5952'); % time vector
N_s = xlsread('San_Fernando_records', 'sheet1', 'B2:B5952'); % North_south Acceleration
% Determine the sampling frequency (Fs)
Fs = 1 / (t(2) - t(1));
% Define the frequency bands for the 13 bandpass filters
f11 = [0.15, 0.05, 0.08, 0.15, 0.27, 0.45, 0.80, 1.30, 1.90, 2.80, 5.00, 8.75, 16.00]; % Lower cutoff frequencies for each band
f12 = [0.2, 0.07, 0.10, 0.17, 0.30, 0.50, 0.90, 1.50, 2.20, 3.50, 6.00, 10.25, 18.00]; % Lower rolloff frequencies for each band
f13 = [25.0, 0.08, 0.15, 0.27, 0.45, 0.80, 1.30, 1.90, 2.80, 5.00, 8.75, 16.00, 25.00]; % Upper rolloff frequencies for each band
f14 = [27.0, 0.10, 0.17, 0.30, 0.50, 0.90, 1.50, 2.20, 3.50, 6.00, 10.25, 18.00, 27.00]; % Upper cutoff frequencies for each band
% Initialize variables to store bandpass filtered signals and durations
num_filters = 13; % Number of bandpass filters
bandpass_filtered_signals = cell(1, num_filters);
bandpass_durations = zeros(1, num_filters);
bandpass_energies = zeros(1, num_filters);
% Define filter orders, upper, and lower threshold levels for each band
filter_orders = [1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120];
threshold_lower_levels = [0.02, 0.03, 0.04, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.04];
threshold_upper_levels = [0.95, 0.95, 0.95, 0.95, 0.95, 0.95, 0.95, 0.95, 0.95, 0.95, 0.95, 0.97, 0.97];
% Process each bandpass filter
for i = 1:num_filters
% Compute the bandpass filter coefficients for the current band
filterCoeffs = fir1(filter_orders(i), [f11(i), f12(i), f13(i), f14(i)] / (Fs / 2), 'bandpass');
% Apply the bandpass filter for the i-th band
bandpass_filtered_signals{i} = filtfilt(filterCoeffs, 1, N_s);
% Calculate the energy for the bandpass signal
squared_data = bandpass_filtered_signals{i}.^2;
energy = cumsum(squared_data);
bandpass_energies(i) = max(energy); % Store the maximum energy
% Calculate the threshold levels based on energy
threshold_lower = threshold_lower_levels(i) * max(energy); % Set your lower threshold level here
threshold_upper = threshold_upper_levels(i) * max(energy); % Set your upper threshold level here
% Find indices where energy crosses the lower and upper thresholds
start_index = find(energy > threshold_lower, 1);
end_index = find(energy > threshold_upper, 1);
% Calculate the duration for the bandpass filter
if ~isempty(start_index) && ~isempty(end_index)
bandpass_duration_seconds = t(end_index) - t(start_index);
bandpass_durations(i) = bandpass_duration_seconds;
fprintf('Band %d - Ground Motion Duration: %.2f seconds\n', i, bandpass_duration_seconds);
else
fprintf('No duration found for Band %d.\n', i);
bandpass_durations(i) = 0; % Set duration to 0
end
% Plot original acceleration, integration, and derivative
figure;
subplot(3, 1, 1);
plot(t, bandpass_filtered_signals{i});
title(['Original Acceleration - Band ' num2str(i)]);
xlabel('Time (seconds)');
ylabel('Acceleration');
grid on;
subplot(3, 1, 2);
plot(t, energy);
title(['Integration - Band ' num2str(i)]);
xlabel('Time (seconds)');
ylabel('Integration');
grid on;
% Plot threshold levels on the integration plot
hold on;
line([t(start_index), t(start_index)], [0, max(energy)], 'Color', 'r', 'LineStyle', '--');
line([t(end_index), t(end_index)], [0, max(energy)], 'Color', 'g', 'LineStyle', '--');
% Add horizontal indication lines at threshold levels
line([t(1), t(end)], [threshold_lower, threshold_lower], 'Color', 'r', 'LineStyle', '--');
line([t(1), t(end)], [threshold_upper, threshold_upper], 'Color', 'g', 'LineStyle', '--');
legend('Integration', ['Lower Threshold: ' num2str(threshold_lower_levels(i) * 100) '%'], ['Upper Threshold: ' num2str(threshold_upper_levels(i) * 100) '%']);
hold off;
subplot(3, 1, 3);
derivative = gradient(bandpass_filtered_signals{i}) ./ gradient(t);
plot(t, derivative);
title(['Derivative - Band ' num2str(i)]);
xlabel('Time (seconds)');
ylabel('Derivative');
grid on;
end
sorry for my poor English.
0 个评论
回答(1 个)
Namnendra
2024-11-3,14:54
Hi,
Your code attempts to calculate frequency-dependent ground motion duration using Ormsby bandpass filters, which is an approach used in seismology to analyze seismic signals. Let's address some of the key aspects and potential improvements for your implementation:
Key Considerations
1. Filter Design:
- Ormsby Filter: Typically, Ormsby filters are defined by four frequencies: two for the passband and two for the stopband. Your current approach uses `fir1`, which is more suited for designing FIR filters with a specific order. If you want to use an Ormsby filter, you might consider using a different approach for Ormsby filters.
- Filter Order: The choice of filter order should be based on the desired sharpness of the filter's frequency response. Higher orders yield sharper transitions but can introduce more artifacts. You might not need different orders for each band; instead, choose a consistent order based on your specific needs and experimentation.
2. FFT and IFFT Usage:
- For calculating ground motion duration, FFT and IFFT are not strictly necessary unless you are analyzing the frequency content or performing spectral manipulations. Your approach of using time-domain filtering and energy calculation is valid for determining durations based on energy thresholds.
3. Energy Thresholds:
- Ensure that your energy threshold levels are appropriate for your data. The thresholds should be set based on the typical energy levels in your signals, and you may need to adjust them based on empirical observations.
4. Bandpass Frequencies:
- Double-check that your frequency bands are correctly defined and aligned with your goals. Ensure that the frequencies are specified correctly in terms of their Nyquist-normalized values (i.e., divided by half the sampling rate).
Suggested Improvements
1. Filter Design:
- Consider using a function that supports Ormsby filters if that's your requirement. Alternatively, continue using `fir1` but ensure the bandpass frequencies are correctly normalized.
- If using `fir1`, make sure the bandpass frequencies are specified as pairs [low, high] normalized by the Nyquist frequency.
2. Energy Calculation:
- Make sure the cumulative energy calculation (`cumsum`) is correctly capturing the energy over time. If necessary, visualize the energy plot to ensure it behaves as expected.
3. Threshold Index Calculation:
- Verify that the indices for energy thresholds are correctly calculated. If the `find` function is not returning expected results, check the energy plot to ensure that the thresholds are reasonable.
4. Code Efficiency:
- Consider vectorizing parts of your code or using MATLAB's built-in functions to enhance performance, especially if processing large datasets.
5. Visualization:
- Ensure the plots are correctly labeled and provide meaningful insights into the signal processing steps. This can help in debugging and understanding the results.
Conclusion
Your approach is generally on the right track, but ensure that the filter design and energy thresholding are correctly implemented and aligned with your research objectives. Experiment with different filter orders and threshold levels to see what best suits your data.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!