Spatial filtering from FFT results

17 views (last 30 days)
Wookie
Wookie on 11 Mar 2022
Answered: Mathieu NOE on 21 Mar 2022
I have a spatial signal that has frequencies that I'd like to filter out, the signal is seen below. I need some advice in removing those valleys and leaving just the top portion. I still need the large valley seen around 700.
My code to filter it has been:
dx=0.2; %mm
Fs=1/dx; %1/mm
L = length(metrology_s1); % Length of signal
t = (0:L-1)*Fs;
Y = fft(metrology_s1);
P2 = abs(Y/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = Fs*(0:(L/2))/L;
plot(f,P1)
title('Single-Sided Amplitude Spectrum of X(t)')
xlabel('f (Hz)')
ylabel('|P1(f)|')
From here I am not applying filters correctly:
% Second attempt
wo = 0.012207/(.2); %
bw = wo/.5;
[b,a] = iirnotch(wo,bw);
fil = filtfilt(b,a,metrology_s1);
Any advice?

Answers (1)

Mathieu NOE
Mathieu NOE on 21 Mar 2022
hello
my suggestion below
look at the yellow trace
y = readmatrix('metrology_s1.csv');
samples = numel(y);
% create x vector
dx = 0.2;
Fs = 1/dx;
x = (0:samples-1)*dx;
% smooth data
ys = smoothdata(y,'rloess',300);
% add min (max negative) point
[y_min,ind] = min(y);
x_min = x(ind);
%create an exponential window centered on the negative peak and use that to
%"blend" the smoothed data with the raw data
blend_ratio = exp(-(x-x_min).^4/1000);
% plot(x,blend_ratio); % debug / test only
y_blended = ys.*(1-blend_ratio)+ y.*(blend_ratio);
plot(x,y,x,ys,x,y_blended)
legend('raw','smoothed','blended');

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!