What code to implement to create a non-causal moving average filter that would use future values as input?

I am quite confused as I am able to write a code for a simple causal moving average filter but do not know that what would differ if it's a non causal one. Please provide me the code for non-causal moving average filter for any number of M values.

回答 (2 件)

See https://en.wikipedia.org/wiki/Causal_filter "In signal processing, a causal filter is a linear and time-invariant causal system. The word causal indicates that the filter output depends only on past and present inputs. A filter whose output also depends on future inputs is non-causal, whereas a filter whose output depends only on future inputs is anti-causal. "
If your signal is time, with early times on the left and later times on the right, then I guess a non-causal filter would be a window that had an odd number of elements and didn't have any on the past/left side of it, like
kernel = [0,0,0,0,1,1,1,1,1] / 5;
out = imfilter(signal, 1, kernel);
or something like that.

3 件のコメント

3011
3011 2015 年 10 月 24 日
I am trying to create a function that carries out moving average using the equation y[n] = 1/M Σx[n − k] lower limit:k=−(M −1)/ 2 upper limit:(M −1)/ 2 while the data I use is from a text file, does the code you have provided perform a moving average and could you explain what this code is doing as I am new to matlab.
No, it only averages over half the filter window. To do a moving average over the whole window, which is what you're asking now, you'd use all 1's.
y = conv(x, ones(1, M)/M, 'full');
Nalini
Nalini 2017 年 2 月 21 日
編集済み: Nalini 2017 年 2 月 21 日
Generally for noise reduction,which is better, a causal filter or a non-causal filter?
Also, which function can I use to perform moving average of array (samples of a sensor signal)?
What's the difference between 'movmean' and 'tsmovavg'
thank you very much!

サインインしてコメントする。

hawi aboma
hawi aboma 2021 年 3 月 27 日
編集済み: hawi aboma 2021 年 3 月 27 日
I'm confused how to write the matlab code for and design filter for cousal and non cousal system, and how to check real time filtert?

1 件のコメント

What's confusing? For a sliding window filter, half of it should be zeroed out - the half that refers to the "future".

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

質問済み:

2015 年 10 月 24 日

コメント済み:

2021 年 3 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by