issues with making a matlab firfilter

5 次查看(过去 30 天)
Jacob
Jacob 2023-11-27
回答: Chunru 2023-11-27
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);

回答(1 个)

Chunru
Chunru 2023-11-27
%[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)

类别

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

标签

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by