Find the closest freq in a filterbank
5 Kommentare
Hi @S,
After reading your comments second time, “ This is using filter number as an input, where I do not want it to necessarily use the same filter every time.” It helped me to clarify my thoughts little better, so to achieve frequency-based filtering without being constrained to a fixed filter number, you can modify the code to calculate the closest filter number for each input frequency. Instead of using a fixed filter_number, you can iterate over all available filters and choose the one that minimizes the difference between its frequency response and the desired input frequency. I have modified code above to demonstrate this approach:
% Generate or load the 'output_signal' variable
output_signal = your_output_signal_generation_function(); % Replace with actual signal generation code
% Define input frequency
input_frequency = 0.3; % Example input frequency
% Initialize variables for closest filter selection
min_difference = Inf;
closest_filter_number = 1;
% Iterate over all filters to find the closest one
for filter_number = 1:num_filters % num_filters is the total number of filters
% Obtain frequency response for the current filter
[h, f] = freqz(output_signal(:, filter_number));
% Calculate the difference between current filter response and input frequency
difference = abs(f - input_frequency);
% Update closest filter if the current one is closer
if min(difference) < min_difference
min_difference = min(difference);
closest_filter_number = filter_number;
end
end
% Obtain the frequency response for the closest filter
[h_closest, ~] = freqz(output_signal(:, closest_filter_number));
% Apply frequency filtering using the closest filter
filtered_output_closest = filter(h_closest, 1, output_signal);
Hope, this will help to achieve your task now, let me know if this is what you’re looking for.
Antworten (1)
- Get the center frequencies of all the filters in the filter bank using the getCenterFrequencies function.
- Calculate the absolute difference of center frequency and center frequencies from 1st step.
- Get the sorted indices of the difference and select the 1st 3 indices. These are the filter numbers which have closest center frequencies.
- Use these filter numbers to get the desired output.
2 Kommentare
Siehe auch
Kategorien
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!