#!/usr/bin/env python # coding: utf-8 # ## Experiment 6 - Resampling and chunking # during resampling, border issues may arise due to chunking. This experiment is to study those and try to correct them # In[2]: import os, sys nb_dir = os.path.split(os.getcwd())[0] if nb_dir not in sys.path: sys.path.append(nb_dir) get_ipython().run_line_magic('matplotlib', 'inline') get_ipython().run_line_magic('load_ext', 'autoreload') get_ipython().run_line_magic('autoreload', '2') # In[28]: from directdemod import chunker, comm import numpy as np # Let us try to see if a problem arises. Let us try to resample a given array 'a', downsampling by factor of 4 # In[29]: sigOrig = comm.commSignal(40, range(100)) sigOrig.bwLim(10) print(sigOrig.signal) sigTest = comm.commSignal(40, range(100)) chunkerObj = chunker.chunker(sigTest, 10) sigTestOut = comm.commSignal(10) for i in chunkerObj.getChunks: sig = comm.commSignal(40, sigTest.signal[i[0]:i[1]]).bwLim(10) sigTestOut.extend(sig) print(sigTestOut.signal) # Clearly they are not the same. In order to correct this, we use the chunker obj. Chunker obj will then store some memory that will help in correcting these border issues. # In[39]: sigOrig = comm.commSignal(40, range(100)) sigOrig.bwLim(10) print(sigOrig.signal) sigTest = comm.commSignal(40, range(100)) chunkerObj = chunker.chunker(sigTest, 10) sigTestOut = comm.commSignal(10) for i in chunkerObj.getChunks: sig = comm.commSignal(40, sigTest.signal[i[0]:i[1]], chunkerObj).bwLim(10) sigTestOut.extend(sig) print(sigTestOut.signal) print(np.array(sigOrig.signal) == np.array(sigTestOut.signal)) # ### Conclusion # # The problem was solved, by using the chunker object to retain some memory.