Read values from fvtool graph
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
Hi all,
I have this script, for IIR filter.
I would like to get to know the points where the graph reaches the -6dB points at the Magnitude Response.
Any help and solution is appreciated.
Bests, Gabor
clc; clear; close all;
% Parameters
Fs = 44100; % Sampling frequency (Hz)
Fc1 = 15.75; % Lower cutoff frequency (Hz)
Fc2 = 47.25; % Upper cutoff frequency (Hz)
Q = 1; % Quality factor
% IIR Biquad bandpass filter design
d = designfilt('bandpassiir', ...
'FilterOrder', 2, ... % Second-order (biquad)
'HalfPowerFrequency1', Fc1, ...
'HalfPowerFrequency2', Fc2, ...
'SampleRate', Fs);
% Frequency response visualization
fvtool(d)
% Test signal generation (sine waves at different frequencies)
t = 0:1/Fs:1;
x = sin(2*pi*50*t) + sin(2*pi*200*t) + sin(2*pi*400*t); % 50 Hz, 200 Hz, and 400 Hz
% Apply filtering
y = filter(d, x);
% Time-domain display
figure;
subplot(2,1,1);
plot(t, x);
title('Input signal');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(2,1,2);
plot(t, y);
title('Filtered signal');
xlabel('Time (s)');
ylabel('Amplitude');
採用された回答
Mathieu NOE
2025 年 3 月 25 日
hello
I am not sure you can retrieve the data (mag,phase) from fvtool object , but you can use freqz instead
now both code below and the fvtool plot seems to indicate different cut off frequencies vs what you asked for in designfilt (I rarelly use it so there might be an explanantion I am not aware off)
plot from fvtool :

try this
% Parameters
Fs = 44100; % Sampling frequency (Hz)
Fc1 = 15.75; % Lower cutoff frequency (Hz)
Fc2 = 47.25; % Upper cutoff frequency (Hz)
Q = 1; % Quality factor
% IIR Biquad bandpass filter design
d = designfilt('bandpassiir', ...
'FilterOrder', 2, ... % Second-order (biquad)
'HalfPowerFrequency1', Fc1, ...
'HalfPowerFrequency2', Fc2, ...
'SampleRate', Fs);
% Frequency response visualization
freq = logspace(0,3,1000);
h =freqz(d.Numerator,d.Denominator,freq,Fs);
mag_dB = 20*log10(abs(h));
[f_6db_low,f_6db_up] = find_zc(freq,mag_dB,-6) % find both -6 dB cut off frequencies
f_6db_low = 11.3250
f_6db_up = 65.7123
figure,
semilogx(freq,mag_dB)
hold on
plot(f_6db_low,-6,'r+');
plot(f_6db_up,-6,'b+');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [ZxP,ZxN] = find_zc(x,y,threshold)
% put data in rows
x = x(:);
y = y(:);
% positive slope "zero" crossing detection, using linear interpolation
y = y - threshold;
zci = @(data) find(diff(sign(data))>0); %define function: returns indices of +ZCs
ix=zci(y); %find indices of + zero crossings of x
ZeroX = @(x0,y0,x1,y1) x0 - (y0.*(x0 - x1))./(y0 - y1); % Interpolated x value for Zero-Crossing
ZxP = ZeroX(x(ix),y(ix),x(ix+1),y(ix+1));
% negative slope "zero" crossing detection, using linear interpolation
zci = @(data) find(diff(sign(data))<0); %define function: returns indices of +ZCs
ix=zci(y); %find indices of + zero crossings of x
ZeroX = @(x0,y0,x1,y1) x0 - (y0.*(x0 - x1))./(y0 - y1); % Interpolated x value for Zero-Crossing
ZxN = ZeroX(x(ix),y(ix),x(ix+1),y(ix+1));
end
8 件のコメント
Mathieu NOE
2025 年 3 月 25 日
編集済み: Mathieu NOE
2025 年 3 月 26 日
% % Alternative code :
% Parameters
Fs = 44100; % Sampling frequency (Hz)
Fc1 = 15.75; % Lower cutoff frequency (Hz)
Fc2 = 47.25; % Upper cutoff frequency (Hz)
% IIR Butterworth bandpass filter design
%It is best not to use the transfer function implementation of discrete (digital) filters,
%because those are frequently unstable.
%Use zero-pole-gain and second-order-section implementation instead.
%Example :
[z,p,k] = butter(2,[Fc1 Fc2]/(Fs/2));
[sos1] = zp2sos(z,p,k);
% Frequency response visualization
freq = logspace(0,3,1000);
h =freqz(sos1,freq,Fs);
mag_dB = 20*log10(abs(h));
[f_6db_low,f_6db_up] = find_zc(freq,mag_dB,-6) % find both -6 dB cut off frequencies
f_6db_low = 13.5462
f_6db_up = 54.9371
figure,
semilogx(freq,mag_dB)
hold on
plot(f_6db_low,-6,'r+','markersize',15);
plot(f_6db_up,-6,'b+','markersize',15);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [ZxP,ZxN] = find_zc(x,y,threshold)
% put data in rows
x = x(:);
y = y(:);
% positive slope "zero" crossing detection, using linear interpolation
y = y - threshold;
zci = @(data) find(diff(sign(data))>0); %define function: returns indices of +ZCs
ix=zci(y); %find indices of + zero crossings of x
ZeroX = @(x0,y0,x1,y1) x0 - (y0.*(x0 - x1))./(y0 - y1); % Interpolated x value for Zero-Crossing
ZxP = ZeroX(x(ix),y(ix),x(ix+1),y(ix+1));
% negative slope "zero" crossing detection, using linear interpolation
zci = @(data) find(diff(sign(data))<0); %define function: returns indices of +ZCs
ix=zci(y); %find indices of + zero crossings of x
ZeroX = @(x0,y0,x1,y1) x0 - (y0.*(x0 - x1))./(y0 - y1); % Interpolated x value for Zero-Crossing
ZxN = ZeroX(x(ix),y(ix),x(ix+1),y(ix+1));
end
Mathieu NOE
2025 年 3 月 26 日
well , I just remember this morning that "half power" cut off frequency correspond to -3dB magnitude points - so there is in fact no surprise that -6dB and -3dB cut off frequencies are not equal !
so I have already given you the method for the -6 dB frequencies , but just for my own fun let's verify the -3dB frequencies (results should match the specified cut off freqs) :
(and fortunately it's matching !!!)
% Parameters
Fs = 44100; % Sampling frequency (Hz)
Fc1 = 15.75; % Lower cutoff frequency (Hz)
Fc2 = 47.25; % Upper cutoff frequency (Hz)
Q = 1; % Quality factor
% IIR Biquad bandpass filter design
d = designfilt('bandpassiir', ...
'FilterOrder', 2, ... % Second-order (biquad)
'HalfPowerFrequency1', Fc1, ...
'HalfPowerFrequency2', Fc2, ...
'SampleRate', Fs);
% Frequency response visualization
freq = logspace(0,3,1000);
h =freqz(d.Numerator,d.Denominator,freq,Fs);
mag_dB = 20*log10(abs(h));
[f_3db_low,f_3db_up] = find_zc(freq,mag_dB,-3) % find both -3 dB cut off frequencies
f_3db_low = 15.7688
f_3db_up = 47.1941
figure,
semilogx(freq,mag_dB)
hold on
plot(f_3db_low,-3,'r+');
plot(f_3db_up,-3,'b+');

●
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [ZxP,ZxN] = find_zc(x,y,threshold)
% put data in rows
x = x(:);
y = y(:);
% positive slope "zero" crossing detection, using linear interpolation
y = y - threshold;
zci = @(data) find(diff(sign(data))>0); %define function: returns indices of +ZCs
ix=zci(y); %find indices of + zero crossings of x
ZeroX = @(x0,y0,x1,y1) x0 - (y0.*(x0 - x1))./(y0 - y1); % Interpolated x value for Zero-Crossing
ZxP = ZeroX(x(ix),y(ix),x(ix+1),y(ix+1));
% negative slope "zero" crossing detection, using linear interpolation
zci = @(data) find(diff(sign(data))<0); %define function: returns indices of +ZCs
ix=zci(y); %find indices of + zero crossings of x
ZeroX = @(x0,y0,x1,y1) x0 - (y0.*(x0 - x1))./(y0 - y1); % Interpolated x value for Zero-Crossing
ZxN = ZeroX(x(ix),y(ix),x(ix+1),y(ix+1));
end
Mathieu NOE
2025 年 3 月 26 日
same test for the second code :
% Parameters
Fs = 44100; % Sampling frequency (Hz)
Fc1 = 15.75; % Lower cutoff frequency (Hz)
Fc2 = 47.25; % Upper cutoff frequency (Hz)
% IIR Butterworth bandpass filter design
%It is best not to use the transfer function implementation of discrete (digital) filters,
%because those are frequently unstable.
%Use zero-pole-gain and second-order-section implementation instead.
%Example :
[z,p,k] = butter(2,[Fc1 Fc2]/(Fs/2));
[sos1] = zp2sos(z,p,k);
% Frequency response visualization
freq = logspace(0,3,1000);
h =freqz(sos1,freq,Fs);
mag_dB = 20*log10(abs(h));
[f_3db_low,f_3db_up] = find_zc(freq,mag_dB,-3) % find both -3 dB cut off frequencies
f_3db_low = 15.7596
f_3db_up = 47.2215
figure,
semilogx(freq,mag_dB)
hold on
plot(f_3db_low,-3,'r+');
plot(f_3db_up,-3,'b+');

●
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [ZxP,ZxN] = find_zc(x,y,threshold)
% put data in rows
x = x(:);
y = y(:);
% positive slope "zero" crossing detection, using linear interpolation
y = y - threshold;
zci = @(data) find(diff(sign(data))>0); %define function: returns indices of +ZCs
ix=zci(y); %find indices of + zero crossings of x
ZeroX = @(x0,y0,x1,y1) x0 - (y0.*(x0 - x1))./(y0 - y1); % Interpolated x value for Zero-Crossing
ZxP = ZeroX(x(ix),y(ix),x(ix+1),y(ix+1));
% negative slope "zero" crossing detection, using linear interpolation
zci = @(data) find(diff(sign(data))<0); %define function: returns indices of +ZCs
ix=zci(y); %find indices of + zero crossings of x
ZeroX = @(x0,y0,x1,y1) x0 - (y0.*(x0 - x1))./(y0 - y1); % Interpolated x value for Zero-Crossing
ZxN = ZeroX(x(ix),y(ix),x(ix+1),y(ix+1));
end
Mathieu NOE
2025 年 4 月 2 日
hello again
problem solved ?
Gabor
2025 年 4 月 3 日
Hi, thanks for the help.
It solved my issue!
Mathieu NOE
2025 年 4 月 4 日
hello
glad it helped
do you mind accepting my answer ? thanks !
Gabor
2025 年 4 月 5 日
I did, thanks for the notification.
Mathieu NOE
2025 年 4 月 7 日
thank you
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Filter Analysis についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
