trouble making a firfilter to remove a tone out of a wavefile
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Walter Roberson
il 29 Nov 2023
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.
Risposta accettata
Walter Roberson
il 29 Nov 2023
Modificato: Walter Roberson
il 29 Nov 2023
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 Commenti
Walter Roberson
il 30 Nov 2023
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');
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Audio I/O and Waveform Generation in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!