Read values from fvtool graph
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
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
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
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
hello again
problem solved ?
Gabor
2025년 4월 3일
Hi, thanks for the help.
It solved my issue!
hello
glad it helped
do you mind accepting my answer ? thanks !
Gabor
2025년 4월 5일
I did, thanks for the notification.
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!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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)
