Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % Design 10 filters with center frequencies and a common quality factor
- center_frequencies = [31.5, 63, 125, 250, 500, 1000, 2000, 4000, 8000, 16000];
- quality_factor = 10;
- % Sample rate (you may adjust this based on your specific application)
- Fs = 44100;
- % Normalize center frequencies
- normalized_center_frequencies = center_frequencies / (Fs / 2);
- % Calculate cutoff frequencies for each filter
- cutoff_frequencies = normalized_center_frequencies / quality_factor;
- % Initialize figure for plotting
- figure;
- % Design and plot each filter
- for i = 1:length(center_frequencies)
- % Design filter using fir1
- filter_order = 50; % Adjust as needed
- b = fir1(filter_order, [cutoff_frequencies(i) cutoff_frequencies(i) + 2/quality_factor], 'bandpass');
- % Get frequency response using freqz
- [H, F] = freqz(b, 1, 1024, Fs);
- % Plot individual filter response
- subplot(2, 1, 1);
- plot(F, abs(H), 'DisplayName', sprintf('Center Frequency = %d Hz', center_frequencies(i)));
- hold on;
- % Plot cumulative frequency response
- subplot(2, 1, 2);
- plot(F, abs(H), 'DisplayName', sprintf('Center Frequency = %d Hz', center_frequencies(i)));
- hold on;
- end
- % Finish plotting individual filter response
- subplot(2, 1, 1);
- title('Individual Filter Responses');
- xlabel('Frequency (Hz)');
- ylabel('Magnitude');
- legend;
- grid on;
- % Finish plotting cumulative frequency response
- subplot(2, 1, 2);
- title('Sum of Filter Responses');
- xlabel('Frequency (Hz)');
- ylabel('Magnitude');
- legend;
- grid on;
- % Display final figure
- hold off;
- % Save the figure if needed
- saveas(gcf, 'filter_responses.png');
- % Optionally, you can write the filter coefficients to a file for later use
- % dlmwrite('filter_coefficients.txt', b);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement