trouble making a firfilter to remove a tone out of a wavefile
1 回表示 (過去 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 で Audio I/O and Waveform Generation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!