The cutoff frequencies must be within the interval of (0,1).

99 次查看(过去 30 天)
I have the following code with the error that I do not understand
Error using butter>butterImpl (line 85)
The cutoff frequencies must be within the interval of (0,1).
Error in butter (line 59)
[varargout{1:nargout}] = butterImpl(n,Wn,varargin{:});
Error in Ambosdisenosversion1 (line 14)
[b, a] = butter(5, [fp fs], 'bandpass'); % Design IIR filter
fp = 500/4000; % Cutoff frequency in terms of Nyquist frequency
fs = 1000/4000; % Stop frequency in terms of Nyquist frequency
n = 64; % Number of taps
b = fir1(n, [fp fs], 'bandpass'); % Design FIR filter
%To process the audio signal with the FIR filter, you can use the filter function in Matlab. First, you need to load the audio signal into a vector. You can do this using the audioread function. For example:
[y, fs] = audioread('Domini_Fil.wav'); % Load audio signal
Error using audioread>readaudio
The filename specified was not found in the MATLAB path.

Error in audioread (line 160)
[y, Fs] = readaudio (filename, range, datatype);
y = y(:,1); % Use only the left channel
%Then, you can process the signal with the filter using the following code:
filtered_y = filter(b, 1, y); % Apply FIR filter
%To design a bandpass filter with the same cutoff frequencies in its IIR version of order 5, you can use the butter function in Matlab. The following code will design the filter:
[b, a] = butter(5, [fp fs], 'bandpass'); % Design IIR filter
%To process the signal with the IIR filter, you can use the filter function in the same way as before. For example:
filtered_y = filter(b, a, y); % Apply IIR filter
%To compare the frequency spectrum of the output signal with the frequency spectrum of the input signal, you can use the fft function in Matlab to compute the Fast Fourier Transform (FFT) of the signals. For example:
N = length(y); % Length of signal
Y = fft(y, N); % FFT of input signal
filtered_Y = fft(filtered_y, N); % FFT of filtered signal
f = (0:N-1)*fs/N; % Frequency axis
plot(f, abs(Y), 'b', f, abs(filtered_Y), 'r'); % Plot FFTs
legend('Input', 'Filtered');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
  2 个评论
the cyclist
the cyclist 2022-12-17
I edited your post, to format your code. Then I ran it here.
Because we do not have your input file, we cannot run your code. This makes it more difficult to help you debug. You can upload the file using the paperclip icon in the INSERT section of the toolbar.
Also, please tell us the complete error message you got, including the specific line number that gave the error.

请先登录,再进行评论。

回答(2 个)

Torsten
Torsten 2022-12-17
编辑:Torsten 2022-12-17
You overwrite your prescribed fs by the call to "audioread":
[y, fs] = audioread('Domini_Fil.wav'); % Load audio signal
Check whether it is still the input to "butter" you wanted to set. My guess is that it is < 0 or > 1 now.

Star Strider
Star Strider 2022-12-17
The cutoff frequencies must be within the interval of (0,1).
Divide ‘fp’ and ‘fs’ by the Nyquist frequency ‘fn’, one-half the sampling frequency of the signal you want to filter. That applies to both the butter and fir1 functions.
So:
[fp fs]/fn
Use the freqz function to be certain the filter is designed to do what you want it to do.
.
  3 个评论
Star Strider
Star Strider 2022-12-19
Use freqz to be certain that the filter is doing what you designed it to do, so after designing the filter. See the documentation I linked to for details.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Filter Design 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by