issues with making a matlab firfilter

7 vues (au cours des 30 derniers jours)
Jacob
Jacob le 27 Nov 2023
Réponse apportée : Chunru le 27 Nov 2023
I am trying to write a matlab code to design a firfilter but I am having trouble getting the filter to work this code below is supposed to determine the frequencies and filter them 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);

Réponses (1)

Chunru
Chunru le 27 Nov 2023
%[x, fs] = audioread('SunshineSquare.wav');
load handel.mat
audiowrite("handel.wav", y, Fs);
[x, fs] = audioread('handel.wav');
X = fft(x);
f = linspace(0, fs/2, length(X)/2);
[~, f0] = max(abs(X(1:length(X)/2)));
Warning: Integer operands are required for colon operator when used as index.
f = (f0-1)/fs; % the corresponding freq for index f0
notchFilter_spec = fdesign.notch('N,F0,Q', 100, f, 10, fs/2); %
notchFilter = design(notchFilter_spec, 'Systemobject', true)
notchFilter =
dsp.SOSFilter with properties: Structure: 'Direct form II' CoefficientSource: 'Property' Numerator: [50×3 double] Denominator: [50×3 double] HasScaleValues: true ScaleValues: [1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 … ] (1×51 double) Use get to show all properties
% fvtool(notchFilter)
y = notchFilter(x);
%y = filter(b, 1, x);
% sound(x, fs);
subplot(211); plot(x);
subplot(212); plot(y)

Tags

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by