Question: Python 3.0: Write a new filter, called mean filter in filters.py that replaces each sensor reading with the mean of itself and the readings on

Python 3.0:

Write a new filter, called mean filter in filters.py that replaces each sensor reading with the mean of itself and the readings on either side of itself. For example, if you have these measurements in the middle of the list

10 13 13

then the middle reading would be replaced by 12 (since (10 + 13 + 13) / 3 = 12). Write code to generate two files, and plot the data in these files, showing the effect of applying your mean filter. We should be able to call your filter using l2 = mean filter(l):

 def mean_filter(list): return sum(list) / len(list) 

  • Modify your code to have a variable filter width. Instead of a width of 3, add a parameter to the filter function that specifies the filter width. This parameter must be positive and odd. Test this with a variety of widths, and see what it does to the data. We should be able to call your code with l2 = mean filter(l, 5). We should also be able to call the code with l2 = mean filter(l), in which case the width should default to 3.

  • Note that for both parts 1 and 2, observations where the window extends off the list should not be included. E.g. if we have a list of length 8 and our window size is 3, then the resulting list should be length 6.

  • Make sure your code throws a ValueError if the user passes in a window size which is not positive and odd.

  • Input/Output Example:

    mean filter([1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1]) returns [2, 2.333, 2, 1.667, 2, 2.333, 2, 1.667, 2, 2.333, 2]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!