How can i generate coefficients (Num, Deno) for allpass filter?

9 views (last 30 days)
I want to add to different signals wich come from filters ( 1 High pass filter , and the other from low pass filter). Both signals have phase shift. Before adding both signals, i need to correct the phase to get same phase on each signal. For this i decided to use allpass filters.
On simulink there is an object : Allpass . To make it runs for your specific application, you need to set coefficients : Which matlab function do i have to use to generate : Num_coef and Deno_coef for the allpass filter from my datas :backward phase, forward phase, cutoff frequency, filter order. An example of code will be very usefull for me. Thanks a lot.

Answers (1)

Mathieu NOE
Mathieu NOE on 20 Jan 2022
hello
try this :
function [b,a]=allpass(n,Fst,Fed,mag,Fs)
%Creates an allpass filter
%
%Syntax:
% >>[b,a]=allpass(n,Fst,Fed,mag,Fs) or
% >>allpass(n,Fst,Fed,mag,Fs)
%
%where
% n = number of pole/zero pairs
% Fst = Start frequency of pole/zero pairs in Hz
% Fed = End frequency of pole/zero pairs in Hz
% mag = Magnitude of pole (should be less than 1)
% Fs = Sample frequency in Hz
% b = coefficients of the allpass filter numerator
% a = coefficients of the allpass filter denominator
%
%**** Inputs ***********************************************************
if nargin ~= 5
fprintf('\nNot enough input arguments for ALLPASS\n');
return
else
end
if Fed<Fst
fprintf('\nEnd frequency must be greater than start frequency for ALLPASS\n');
return
else
end
f(1)=Fst;
if n~=1
fdiv=(Fed-Fst)/(n-1);
for k=2:n
f(k)=(k-1)*fdiv+Fst;
end
else
end
r=mag; %magnitude
%**** Computation of poles and zeros ************************************
for k=1:length(f)
p(k)=r.*exp(i*2*pi*(f(k)/Fs));
end
a=1; %initializing den
b=1; %initializing num
for k=1:length(f)
if imag(p(k))< 1*10^(-10) %if p(k) is purely real
p(k)=real(p(k)); %create only one pole/zero
a=conv(a,[1 -p(k)]);
b=conv(b,[-p(k) 1]);
else
a=conv(conv([1 -p(k)],[1 -conj(p(k))]),a);
b=conv(conv([-p(k) 1],[-conj(p(k)) 1]),b);
end
end
%**** Display Z Plane and Freq. Response ********************************
if nargout ~=2
zplane(b,a);
title('Z Plane of Allpass Filter');
figure
freqz(b,a,256,Fs);
title('Frequency Response of Allpass Filter');
else
end

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!