Filtering code- unknown filter

1 回表示 (過去 30 日間)
Coo Boo
Coo Boo 2012 年 8 月 17 日
Hi to all,
I have a code which filters the signal 'x' with length of N, but I don't know what kind of filtering that is? The code is:
%Filtering.
fL=5; % Setting fL
if fL>1
for i=fL+1:N
x(i-fL)=0;
for j=1:fL
x(i-fL) = x(i-fL)+(1/fL)*x(i-j+1);
end
end
end
Can you help me to know that? thanks,
  2 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2012 年 8 月 17 日
you should specify what is N?
Coo Boo
Coo Boo 2012 年 8 月 17 日
N stands for the length of signal

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

採用された回答

Matt Fig
Matt Fig 2012 年 8 月 17 日
編集済み: Matt Fig 2012 年 8 月 17 日
It is a forward moving average. That is, the value at index I is the average of the fL values I+1:I+fL. Like other moving averages, it can be considered a low-pass filter.
Here is a simplification of the code that makes this more clear:
y = x; % Compare final x with final y after both loops.
for jj = 1:length(y)-fL
y(jj) = sum(y(jj+1:jj+fL)/fL)
end
What is interesting is that it stops short of carrying to the end of the vector. Most moving averages carry through with less terms as necessary, like this:
for jj = 1:length(y)-1
y(jj) = sum(y(jj+1:min(jj+fL,length(y)))/fL) ;
end
Also y above to compare:
MA = fliplr(filter(ones(1,5)/5,1,fliplr(y)));
only the first and the last elements differ because of the way MAs work.
  1 件のコメント
Coo Boo
Coo Boo 2012 年 8 月 17 日
Thanks

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

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 8 月 17 日
編集済み: Azzi Abdelmalek 2012 年 8 月 17 日
x=rand(104,1);y=x
N=size(x,1);
fL=5; % Setting fL
if fL>1
for i=fL+1:N
x(i-fL)=0;
for j=1:fL
x(i-fL) = x(i-fL)+(1/fL)*x(i-j+1);
end
end
end
cla;plot(abs(fft(x)));hold on ;plot(abs(fft(y)),'r')
it seems to be a low pass filter, comparing the Fourier transform of x and y
your original: red
your filtred signal: blue
  3 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2012 年 8 月 17 日
just look at the half of the plot (from 0 to 52), because froù 53 to 104 it's just a symetric
Coo Boo
Coo Boo 2012 年 8 月 17 日
編集済み: Coo Boo 2012 年 8 月 17 日
I think, this will show better for bigger value of fL,e.g. fL=20
plot(abs(fft(x(1:N-fL))));hold on ;plot(abs(fft(y)),'r')

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

カテゴリ

Help Center および File ExchangeSingle-Rate Filters についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by