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
load CFDvsABAQUS_TC.mat

%% 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-&gt;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] -&gt; 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.
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.