filtfilt problem when trying to compensate for delay

8 views (last 30 days)
For a school project i have to analyse AE data with matlab.
using the filtfilt function i want to zero phase the IIR filteroutput, but i get an error and i cant see why.
data = readtable('coupon 18 peak 1'); %load signal
signal = data.Value; %
Fs = 50000; % samplefreq
sig = signal * 100 ;
dt = 1/Fs;
[samples,channels] = size(sig);
t = (0:dt:(samples-1)*dt);
t = t';
df = Fs/samples;
Hd = HdIIR;
%%%%%% Filter add %%%%%%
FilteredSignal = filter(Hd,sig);
FilteredSignalD = filtfilt(Hd,sig);
%%% where sig is my signal and Hd is the IIR filter constructed by the filterdesigntool.
figure(2)
plot(t,sig,t,FilteredSignalD);
xlabel('tijd (s)')
ylabel('amplitude(mg)')
title('standaard signaal met gefilterd signaal zonder delay')
this is the part of the script where i try to filter my signal. I am using a IIR because for a FIR i get a minimum order above 400 (btw i managed to correct the delay for the FIR with grpdelay)

Accepted Answer

Mathieu NOE
Mathieu NOE on 11 Jan 2022
hello
the Hd filter was not supplied so I suggest here some standard filter (butterworth lowpass or bandpass) or smoothing techniques using smoothdata (which acts as a zero phase lag lowpass filter)
you can easily change the code to fit your needs
I supposed that the reason for filtering was to smooth out the data , but this can be in contradiction to keep the transient trace accurate as possible
data = readtable('coupon 18 peak 1'); %load signal
signal = data.Value; %
Fs = 50000; % samplefreq
sig = signal * 100 ;
dt = 1/Fs;
[samples,channels] = size(sig);
t = (0:dt:(samples-1)*dt);
t = t';
df = Fs/samples;
% Hd = HdIIR;
%%%%%% Filter add %%%%%%
f_low = 100;
f_high = 5000;
N = 2;
% [B,A] = butter(N,[f_low f_high]*2/Fs, 'bandpass'); % bandpass
[B,A] = butter(N,f_high*2/Fs); % lowpass
FilteredSignalD = filtfilt(B,A,sig);
SmoothedSignalD = smoothdata(sig,'gaussian',25);
%%% where sig is my signal and Hd is the IIR filter constructed by the filterdesigntool.
figure(2)
plot(t,sig,t,FilteredSignalD,t,SmoothedSignalD);
xlabel('tijd (s)')
ylabel('amplitude(mg)')
title('standaard signaal met gefilterd signaal zonder delay')
legend('raw','IIR filter','smoothed');
  6 Comments
Peter Darrouj
Peter Darrouj on 11 Jan 2022
thank you for your help. that is quite the script sir, i am not so educated in matlab so i will have to study it. i would like to understand how you created it, maybe you have a link to some in depth explanation.
could you explain what the overlap stands for. i see that it plays a role in the resolution of the spectrogram but how do u determine what to use? i dont find significant differences between 0.70 - 0.95 and how does it affect the computing time/power needed?
i believe the NFFT is for zero padding so the resolution is higher if there are not enough data points, right?
i undestand that i am asking too much in this threat so no hard feelings if you would like to stop the conversation here :).
Mathieu NOE
Mathieu NOE on 11 Jan 2022
hehe
no problem at all
when you do the time / frequency analaysis with a spectrogram function , there are several factors that will play a role for frequency and time axis resolution
  • frequency resolution df is driven by your sampling frequency Fs and the fft buffer length NFFT : df = Fs/NFFT. so large NFFT will increase the frequency resolution but for a gievn overlap , it will reduce the number of frequency spectra , so you loose time accuracy by the same amount
  • you can increase your time accuracy if you increase your overlap, so the spectrogram looks better (smoother) with overlap compared to no overlap. but this increases the computation load as your asking for more fft spectra computation
NFFT & overlap : those are the two major parameters you can play with when you do short time fourier analysis
see for example :

Sign in to comment.

More Answers (0)

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!