How to apply bandpass filter

Illustration
Katherine - 2021-01-15T09:46:19+00:00
Question: How to apply bandpass filter

The  signal file is of 20Hz sampling rate. Each row is a signal, i needed to to apply bandpass filter to each row and convert it in the frequency range 0.34 - 1 Hz.

Expert Answer

Profile picture of Kshitij Singh Kshitij Singh answered . 2025-11-20

To apply a bandpass filter to each row of a signal matrix and convert it to the frequency range 0.34 - 1 Hz in MATLAB, you can use the designfilt function to create the filter and then apply it to each row. Here's a step-by-step guide:

  1. Load the Signal: Load your signal matrix, where each row is a signal.

  2. Design the Bandpass Filter: Use the designfilt function to create a bandpass filter.

  3. Apply the Filter: Use the filtfilt function to apply the filter to each row.

Example:

matlab
% Load your signal matrix
% Assuming 'signalMatrix' is your matrix where each row is a signal
% Example: signalMatrix = rand(100, 1000); % 100 rows (signals) and 1000 columns (samples)

% Sampling frequency (Hz)
Fs = 20;

% Design a bandpass filter with a passband of 0.34 to 1 Hz
bpFilt = designfilt('bandpassiir', 'FilterOrder', 4, ...
                    'HalfPowerFrequency1', 0.34, ...
                    'HalfPowerFrequency2', 1, ...
                    'SampleRate', Fs);

% Initialize the filtered signal matrix
filteredSignalMatrix = zeros(size(signalMatrix));

% Apply the filter to each row
for k = 1:size(signalMatrix, 1)
    filteredSignalMatrix(k, :) = filtfilt(bpFilt, signalMatrix(k, :));
end

% Plot the original and filtered signals (for a selected row)
selectedRow = 1; % Choose a row to plot
figure;
subplot(2, 1, 1);
plot(signalMatrix(selectedRow, :));
title('Original Signal');
xlabel('Time (samples)');
ylabel('Amplitude');

subplot(2, 1, 2);
plot(filteredSignalMatrix(selectedRow, :));
title('Filtered Signal (Bandpass 0.34 - 1 Hz)');
xlabel('Time (samples)');
ylabel('Amplitude');

Explanation:

  • Load the Signal: Replace signalMatrix with your actual signal matrix.

  • Design the Bandpass Filter: The designfilt function creates a bandpass filter with the specified frequency range and sampling rate.

  • Apply the Filter: The filtfilt function applies the filter to each row of the signal matrix, ensuring zero-phase distortion.

  • Plotting: The original and filtered signals for a selected row are plotted for comparison.


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!