Master Computers and Technology with Fun Quizzes & Brain Teasers!
Assume a list of measurements (x), recorded at different times (t). Since the measurements may grow over time or may have been recorded at a high-frequency, we would like to 'downsample' (or 'compress'/'aggregate') the data, that is, reducing the frequency of the original signal. One way to do so is to assume a fixed 'window' of time, and aggregate the data recorded within that window.Example: Given x = [1., 2., 3., 4.], t = [10, 11, 14, 15] and a window size of 2, we may want to get the average of the signal within that period of time. downsampled_t = [10, 14] - downsampled_x = [1.5, 3.5] # 1.5 = (1+2)/2; 3.5 = (3+4)/2Q1 - Downsampler classWrite a class Downsampler with methods to: * i) downsample a signal; * ii) iterate through the compressed signal; * iii) get the downsampled value(s) at a given timeAssumptions: - x is a list of floating numbers. - t is a list of integers (e.g 'Unix time' - Wikipedia) - You can assume the mean, max, min and number of data points of the signal within a time window are the quantities of interest.Example:# Define classdownsampler = Downsample(window_size=2)# Define signal>>> x = [1., 2., 3., 4.]; t = [10, 11, 14, 15]# Downsample>>> downsampler.downsample(t, x)# Get downsampled values>>> results = downsampler[10.5]>>> print(results)(10: {'mean': 1.5, 'max': 2, 'min': 1, 'n_points': 2})# Iterate through the compressed signal>>> for ds_t, ds_x in downsampler:... print(ds_t, ds_x)10, {'mean': 1.5, 'max': 2, 'min': 1, 'n_points': 2}14, {'mean': 3.5, 'max': 4, 'min': 3, 'n_points': 2}Notes: - Your implementation should not use any data processing library (for instance - pandas). - Libraries used for array manipulation are accepted (for instance - numpy). - Your implementation may differ from the example below, which is given for illustration purposes.