# Applying estimated transfer function to a signal

This is the simple code to find transfer function between sigout and sigin signals and then are the filter coefficients estimated by invfreqz function.

%% load simlated data

%% simulated data preprocessing (grid orientation B)
time = TCb(:,1);
sigin = TCb(:,2);           % inlet temperature (TC signal by Abaqus)
sigout = TCb(:,3);          % outlet temperature (by cfd FENIX)
Fs = 1/mean(diff(time));    % sampling frequency

%% Transfer Function Estimate outlet->inlet
[toi,foi]=tfestimate(sigout,sigin,2^13,[],[],Fs);

%% filter design by known transfer function
w = linspace(0,pi,length(fio)); % angular frequency f=[0,fs/2] -> w=[0,pi]
m = 500; % b coeffs
n = 500; % a coeffs
[boi,aoi] = invfreqz(toi,w,n,m);

%% final Digital filtering
esigin = filter(boi,aoi,sigout);


The input data are available at this dropbox link.

The final filter function produce completely wrong results (the result should be similar to original sigin signal). I have no idea what is wrong.

Any help will be very useful for me.

• Probably all problems comes from extremely high order m=n=500 at invfreqz function... Some numerical instabilities??? But I need high order estimation to fit properly estimated transfer function. – michalkvasnicka Apr 28 '17 at 15:04

Your values for m and n are way too big. Matlab starts getting numerical problems for those values above 30, sometimes.
Try reducing them to more reasonable numbers (e.g. 10) and slowly increase them until invfreqz generates bogus outputs.