Read values from fvtool graph

7 Ansichten (letzte 30 Tage)
Gabor
Gabor am 24 Mär. 2025
Kommentiert: Mathieu NOE am 7 Apr. 2025
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');

Akzeptierte Antwort

Mathieu NOE
Mathieu NOE am 25 Mär. 2025
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 Kommentare
Gabor
Gabor am 5 Apr. 2025
I did, thanks for the notification.
Mathieu NOE
Mathieu NOE am 7 Apr. 2025
thank you

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by