필터 지우기
필터 지우기

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

조회 수: 54 (최근 30일)
Sonia
Sonia 2022년 12월 17일
댓글: Star Strider 2022년 12월 19일
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
Sonia
Sonia 2022년 12월 19일
yes is in terms of the nyquist frequency
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