フィルターのクリア

issues with making a matlab firfilter

4 ビュー (過去 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 Center および File ExchangeDigital Filter Analysis についてさらに検索

タグ

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by