Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Download sensor.py and amp_filter.py. Read the code in these files, and make sure you understand what they're doing. Do not modify these files ; all

  1. Download sensor.py and amp_filter.py. Read the code in these files, and make sure you understand what they're doing. Do not modify these files; all of your code should go in test_filter.py.

_____________________________________________________________________________________________________________________________________________________

sensor.py

#!/usr/bin/env python3 from math import sin from random import gauss def generate_sensor_data(n, sigma=0.01): """ Generate data from a fake sensor. These data are generated according to a sine function, with zero-mean Gaussian noise, with standard deviation sigma. """ data = [] for i in range(n): data.append(sin(i * 0.01) + gauss(0.0, sigma)) return data if __name__ == '__main__': # Print out a few of the numbers for d in generate_sensor_data(10): print(d) 

_____________________________________________________________________________________________________________________________________________________

amp_filter.py

#!/usr/bin/env python3 def apply_amp_filter(data, cutoff=0.8): """ Apply an amplitude filter to an iterable, returning a list. """ # Make an empty list filtered = [] # Add one element at a time to the list. There are a lot of ways to do this; this is just one of them. for datum in data: datum = min(datum, cutoff) filtered.append(datum) # Return the new list return filtered

_____________________________________________________________________________________________________________________________________________________

2. Write some code in test_filter.py to generate a single CSV file, where the first column has 1000 points of (simulated) sensor data (generated using the function in sensor.py), and the second column has the same data after you pass it through the amplitude filter (from amp_filter.py).

Note that there are many modules in Python that work with CSVs. You can use any standard library modules you wish (but no Numpy/Pandas/etc.), but for this assignment, you may also find that writing each line manually is the easiest. Each line should look something like 1.2411,0.8921, with a comma separating each number (hence the name comma separated values).

3. Open up your CSV in any standard spreadsheet program and plot the two columns on the same graph. Paste the plot into this document. Note: You are not expected to plot in Python for this assignment. We will cover a Python plotting library matplotlib in a future assignment.

Note that:

  1. You should write tests for all of the functions you write for this lab. Write the tests before you write the code, and put them after the if __name__ == '__main__': line. We're going to import the functions from your files for testing and, if you don't put your tests after this line (and indented to the if block), then it might confuse our testing code. Also, this if good programming practice.
  2. There are likely to be built-in functions for a number of the things we're asking you to do for this lab. Please don't use them. If you do, you'll get zero points for that part of the assignment, since we want you to write them from scratch (this time).
  3. The amplitude filter only affects sensor readings beyond a certain threshold. These sensor readings get clipped to the maximum allowed amplitude.
  4. When you write the variable-width mean filter, you might find array slicing useful. Also, the filtered arrays will be shorter than the input arrays. For a filter with width 3, the filtered lists will be 2 elements shorter than the original list. For a width of 5, it will be 4 shorter, and so on.
  5. Use Python 3.8

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Linked Data A Geographic Perspective

Authors: Glen Hart, Catherine Dolbear

1st Edition

1000218910, 9781000218916

More Books

Students also viewed these Databases questions

Question

What is the basis for Security Concerns in Cloud Computing?

Answered: 1 week ago

Question

Describe the three main Cloud Computing Environments.

Answered: 1 week ago