Q:

A median filter on a vector has a size, for example, a size of 3 means calculating the median of every three values in the vector. The first and last elements are left alone

0

A median filter on a vector has a size, for example, a size of 3 means calculating the median of every three values in the vector. The first and last elements are left alone. Starting from the second element to the next-to-last element, every element of a vector vec(i) is replaced by the median of [vec(i-1) vec(i) vec(i+1)]. For example, if the signal vector is signal = [5 11 4 2 6 8 5 9] the median filter with a size of 3 is medianFilter3 = [5 5 4 4 6 6 8 9] Write a function to receive the original signal vector and return the median filtered vector. 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

medianFilter3.m

function outvec = medianFilter3(vec)

% Computes a median filter with a size of 3

% Format of call: medianFilter3(vector)

% Returns a median filter with size 3

outvec = vec;

for i = 2:length(vec) - 1

 outvec(i) = median([vec(i-1) vec(i) vec(i+1)]);

end

end

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now