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
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
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
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');
Jacob
Jacob 2023-11-30
Awesome Thank you! It works and I don't hear the tone anymore which is what I needed! One more thing the end of the file is still a little noisy but I can hear the file is there a way to clean the file up or is it what it is? I know there is only so much that can be done cleaning up an audio file so I am happy with what I have if not.

请先登录,再进行评论。

更多回答(0 个)

类别

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

标签

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by