1
$\begingroup$

I am using the following code in Matlab, from some source (sadly I cant remember).
The code is used for smoothing signals using a low pas filter.

 function y = fftSmooth(resp,srateCorrectedSmoothedWindow)
    L      = length(resp);
    window = zeros(1,L);
    window(floor((L-srateCorrectedSmoothedWindow+1)/2)...
    :floor((L+srateCorrectedSmoothedWindow)/2))=1;

    % zero phase low pass filtering
    tmp = ifft(fft(resp).*fft(window)/srateCorrectedSmoothedWindow);      
    y=-1*ifft(fft(-1*tmp).*fft(window)/srateCorrectedSmoothedWindow);

I have removed some unnecessary parts to shorten the code.

My question: how exactly is the filter designed (the last two lines)? Shouldn't it be in the time domain?

$\endgroup$
3
  • 1
    $\begingroup$ I think what you mean is "how is the filtering implemented" (which is different from how the filter is designed). The answer to that is it's implemented in the frequency domain, which is perfectly fine. I wouldn't have implemented it as such though, but that's a different topic. $\endgroup$
    – Jdip
    Oct 18, 2022 at 18:10
  • 1
    $\begingroup$ See also: this $\endgroup$
    – Jdip
    Oct 18, 2022 at 18:13
  • $\begingroup$ @Jdip, thanks, its was very useful. $\endgroup$ Oct 18, 2022 at 19:40

1 Answer 1

2
$\begingroup$

The code apparently originate from BreathMetrics (Matlab toolbox for analyzing respiratory recordings): breathmetrics/fftsmooth.m. It is descripted in Automated analysis of breathing waveforms using BreathMetrics: A respiratory signal processing toolbox, Chemical Senses, 2018. A draft is here.

Below, the function is visualyy decomposed into frequency/time steps. As @Jdip wrote, that is a filter implementation in the frequency domain.

%%% function y = fftSmooth(resp,srateCorrectedSmoothedWindow)

%Set inputs
lResp = 2048;
resp = randn(1,lResp)+10*exp(-(((1:lResp)-lResp/2)/(0.01*lResp)).^2);
srateCorrectedSmoothedWindow = 16;

    L      = length(resp);
    window = zeros(1,L);
    window(floor((L-srateCorrectedSmoothedWindow+1)/2)...
    :floor((L+srateCorrectedSmoothedWindow)/2))=1;

    % zero phase low pass filtering
    tmp = ifft(fft(resp).*fft(window)/srateCorrectedSmoothedWindow);      
    y=-1*ifft(fft(-1*tmp).*fft(window)/srateCorrectedSmoothedWindow);
  
    figure(1);clf
    subplot(2,1,2)
plot([resp;y]')  
axis tight;legend('Time Signal','Time Signal filtered')
    subplot(2,1,1)
yyaxis left
plot(abs(fft(resp)))
yyaxis right
plot(abs(fft(window)))
axis tight;legend('Spectrum','Window')

Decomposition of algorithm

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.