filtfilt problem when trying to compensate for delay
5 views (last 30 days)
Show older comments
Peter Darrouj
on 11 Jan 2022
Commented: Mathieu NOE
on 11 Jan 2022
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)
0 Comments
Accepted Answer
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
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 :
More Answers (0)
See Also
Categories
Find more on Digital Filter Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!