Can anyone please, help me with the 1D median filter algorithm?

2 件のコメント

David Barry
David Barry 2016 年 12 月 13 日
Help you do what exactly? You need to be clear. Why can't you use the built-in MATLAB function? It seems strange to build your own when one already exists for you to use straight out of the box.
dunklevision
dunklevision 2016 年 12 月 17 日
well it's a task so I have to build that function...

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

 採用された回答

Image Analyst
Image Analyst 2016 年 12 月 13 日

0 投票

M = movmedian(A,k) returns an array of local k-point median values, where each median is calculated over a sliding window of length k across neighboring elements of A. When k is odd, the window is centered about the element in the current position. When k is even, the window is centered about the current and previous elements. The window size is automatically truncated at the endpoints when there are not enough elements to fill the window. When the window is truncated, the median is taken over only the elements that fill the window. M is the same size as A.
I supposed you don't want to use that either? Well at least movmedian() is built into base MATLAB, unlike medfilt1() which is in the Signal Processing Toolbox.

8 件のコメント

dunklevision
dunklevision 2016 年 12 月 17 日
thank you very much for this new info but still need that function, I mean the algorithm that does the same thing as the "movmedian"
Image Analyst
Image Analyst 2016 年 12 月 17 日
It's rather obvious. Just slide a window across the vector and extract the values and send them into median(). The only slightly tricky part is that in that function the window width shrinks as it bumps against either end. Basically it's like this
for k = 1 : length(vec)
filteredVec = median(vec(k:(k+windowWidth-1)));
end
Now that won't quite work because I haven't done the edge effects yet, but that's not hard. See if you can figure it out.
If you really can't figure it out, and maybe later if I get time I'll do it for you, but give it a shot yourself first.
Image Analyst
Image Analyst 2016 年 12 月 18 日
Since you asked someone who posted a question over 5 and a half years ago here, I guess that you were unable to figure it out. So here it is:
numElements = 21;
signal = randi(9, 1, numElements)
windowSize = 7;
halfWidth = floor(windowSize/2)
for windowCenter = 1 : length(signal)
% Get the left index
i1 = max([1, windowCenter - halfWidth]);
% Get the right index
i2 = min([numElements, windowCenter + halfWidth]);
if i1 < 1 || i2 < 1 || i1 > numElements || i2 > numElements
continue;
end
fprintf('Examining indexes %d to %d.\n', i1, i2);
filteredSignal2(windowCenter) = median(signal(i1:i2));
end
% Now do it via the built-in movmedian():
filteredSignal = movmedian(signal, windowSize)
% Prove it's the same as using movmedian() by showing all the differences are 0
differences = filteredSignal - filteredSignal2
dunklevision
dunklevision 2016 年 12 月 19 日
Thank you very much. I'm going to try to figure out these steps and apply them on my signal. Thank you for your help once again.
Image Analyst
Image Analyst 2016 年 12 月 20 日
Did my suggestions work?
dunklevision
dunklevision 2017 年 1 月 2 日
yes ! thank you very much
Image Analyst
Image Analyst 2017 年 1 月 3 日
Well, can you then go ahead and "Accept this Answer"? Thanks in advance.
dunklevision
dunklevision 2017 年 1 月 13 日
sure! I'm the one to thank you.

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

その他の回答 (0 件)

カテゴリ

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by