trouble making a firfilter to remove a tone out of a wavefile
조회 수: 2 (최근 30일)
이전 댓글 표시
I am trying to write a matlab code to design a firfilter to filter a tone out of a wav.file but I am having trouble getting the filter to work this code below is supposed to determine the frequencies of the audio in the wav.file and filter the tone out of the sunshinesquare.wav file. however when I go to run the program matlab tells me there is an error with the notchfilter line but I can't figure out what is wrong with it any suggestions/help is greatly appreciated.
My code is below
[x, fs] = audioread('SunshineSquare.wav');
X = fft(x);
f = linspace(0, fs/2, length(X)/2);
[~, f0] = max(abs(X(1:length(X)/2)));
notchFilter = fdesign.notch('N,Fc', 100, f0, fs);
b = firpm(notchFilter);
y = filter(b, 1, x);
sound(x, fs);
댓글 수: 3
Walter Roberson
2023년 11월 29일
Error using fdesign.abstractpeaknotch/set.Specification
Expected Specification to match one of these values:
'N,F0,Q', 'N,F0,Q,Ap', 'N,F0,Q,Ast', 'N,F0,Q,Ap,Ast', 'N,F0,BW', 'N,F0,BW,Ap', 'N,F0,BW,Ast', 'N,F0,BW,Ap,Ast'
The input, 'N,Fc', did not match any of the valid values.
채택된 답변
Walter Roberson
2023년 11월 29일
편집: Walter Roberson
2023년 11월 29일
The error is correct, in that the documentation lists specific filter specifications, none of which include Fc
I do not promise that I calculated f0 correctly.
[x, fs] = audioread('SunshineSquare.wav');
X = fft(x);
L = floor(length(X)/2);
f = linspace(0, fs/2, L);
[~, f0idx] = max(abs(X(1:L)));
f0 = (f0idx-1)/L;
Q = 80;
notchFilter = fdesign.notch('N,F0,Q', 100, f0, Q);
Hd = design(notchFilter, 'SystemObject', true);
y = Hd(x);
sound(y, fs)
댓글 수: 18
Walter Roberson
2023년 11월 30일
The audiofile has a primary frequency and two further peaks at 2 and 3 times the primary. Removing those three leaves only low level information.
X = fft(x);
L = floor(length(X)/2);
f = linspace(0, fs/2, L);
[~, f0idx] = max(abs(X(1:L)));
f0 = (f0idx-1)/L;
Q = 2.5;
notchFilter1 = fdesign.notch('N,F0,Q', 6, f0, Q);
notchFilter2 = fdesign.notch('N,F0,Q', 6, f0*2, Q);
notchFilter3 = fdesign.notch('N,F0,Q', 6, f0*3, Q);
Hd1 = design(notchFilter1, 'SystemObject', true);
Hd2 = design(notchFilter2, 'SystemObject', true);
Hd3 = design(notchFilter3, 'SystemObject', true);
y = Hd3(Hd2(Hd1(x)));
tiledlayout('flow');
nexttile
plot(f, abs(X(1:L))); title('original spectrum');
nexttile
Y = fft(y);
plot(f, abs(Y1(1:L))); title('filtered spectrum');
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Digital Filter Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!