Band-Pass Filter butter problem

조회 수: 14 (최근 30일)
Matt
Matt 2023년 12월 14일
댓글: MarKf 2023년 12월 15일
filter_order_bpf = 10; % filter order, larger number makes the filter
% response sharper but increases the cost
f_low_bpf = f_carrier - f_stop_lpf; % low cut-off frecuency of band-pass filter
f_high_bpf = 31e3; % high cut-off frecuency of band-pass filter
wn_bpf = [f_low_bpf, f_high_bpf]/(Fs/2); % this parameter is used by MATLAB, defines it based
% on your cut-off frequencies and your signal sampling frequency
[b_bpf, a_bpf] = butter(filter_order_bpf, wn_bpf, 'bandpass'); % creates a Butterworth band-pass filter
filt_received = filter(b_bpf, a_bpf, y_mod_am_received); % apply the filter to received signal
filt_rec_sig_FD = fft(filt_received); % calculate frequency domain of audio
filt_rec_sig_FD_amp = abs(filt_rec_sig_FD)/no_of_pnts; % calculate the amplitude of frequency domain
filt_rec_sig_FD_amp_adj = fftshift(filt_rec_sig_FD_amp); % adjust the frequency sides
figure;
semilogy(freq, rec_sig_FD_amp_adj, 'b');
hold on;
semilogy(freq, filt_rec_sig_FD_amp_adj, 'r');
xlim([10, freq_max]);
grid minor;
box on;
xlabel('Frequency (Hz)');
ylabel('Amplitude');
legend('Received', 'Filtered Received');
title('Frequency Domain of Received and Filtered Received Signals');
The error is Error using butter>butterImpl
The cutoff frequencies must be within the interval of (0,1).
Error in butter (line 59)
[varargout{1:nargout}] = butterImpl(n,Wn,varargin{:});
How do I fix this?
  댓글 수: 1
Star Strider
Star Strider 2023년 12월 14일
NOTE — The transfer function implementation is generally not recommended because of potential stability problems. See the butter documentation section on Limitations for details. (This applies to all discrete filter designs, not only butter.)
Also, filtfilt is generally recommended because it produces a phase-neutral result.

댓글을 달려면 로그인하십시오.

채택된 답변

MarKf
MarKf 2023년 12월 14일
Something something Nyquist frequency.... If you provide the missing data to your example you could get a better answer
f_stop_lpf = 4500; %e.g.
Fs = 100000; %e.g.
f_carrier = 10000; %e.g.
no_of_pnts = 20000;
y_mod_am_received = randn(no_of_pnts, 1); %inputsignal
freq = linspace(1,f_carrier,no_of_pnts);
filter_order_bpf = 10; % filter order, larger number makes the filter% response sharper but increases the cost % maybe use buttord to lower this?
f_low_bpf = f_carrier - f_stop_lpf; % low cut-off frecuency of band-pass filter
f_high_bpf = 31e3; % high cut-off frecuency of band-pass filter
wn_bpf = [f_low_bpf, f_high_bpf]/(Fs/2); % this parameter is used by MATLAB, defines it based % on your cut-off frequencies and your signal sampling frequency
[b_bpf, a_bpf] = butter(filter_order_bpf, wn_bpf, 'bandpass'); % creates a Butterworth band-pass filter
filt_received = filter(b_bpf, a_bpf, y_mod_am_received); % apply the filter to received signal
filt_rec_sig_FD = fft(filt_received); % calculate frequency domain of audio
filt_rec_sig_FD_amp = abs(filt_rec_sig_FD)/no_of_pnts; % calculate the amplitude of frequency domain
filt_rec_sig_FD_amp_adj = fftshift(filt_rec_sig_FD_amp); % adjust the frequency sides
figure;
% % semilogy(freq, rec_sig_FD_amp_adj, 'b'); rec_sig_FD_amp_adj absent
% hold on;
semilogy(freq, filt_rec_sig_FD_amp_adj, 'r');
% xlim([10, freq_max]);
grid minor;
box on;
xlabel('Frequency (Hz)');
ylabel('Amplitude');
legend( 'Filtered Received'); %'Received',
title('Frequency Domain of Received and Filtered Received Signals');
  댓글 수: 2
Matt
Matt 2023년 12월 14일
Brilliant, thank you ever so much.
MarKf
MarKf 2023년 12월 15일
Thank you for accepting the answer. Once again, I made up the missing data on the spot. The frequency space is definetely wrong.
But indeed the issue was likely the Nyquist frequency, so the cutoff should be less than half the sampling frequency (in butterImpl the cutoff/sampling frequency ratio should be between 0 and 1/2). So maybe that's all you needed. Still, take heed, also of what @Star Strider said above, maybe also use freqz to look at the filter response.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Digital Filter Analysis에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by