during resampling, border issues may arise due to chunking. This experiment is to study those and try to correct them
import os, sys
nb_dir = os.path.split(os.getcwd())[0]
if nb_dir not in sys.path:
sys.path.append(nb_dir)
%matplotlib inline
%load_ext autoreload
%autoreload 2
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
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)
[ 0 4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88 92 96] [ 0. 4. 8. 10. 14. 18. 20. 24. 28. 30. 34. 38. 40. 44. 48. 50. 54. 58. 60. 64. 68. 70. 74. 78. 80. 84. 88. 90. 94. 98.]
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.
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))
[ 0 4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88 92 96] [ 0. 4. 8. 12. 16. 20. 24. 28. 32. 36. 40. 44. 48. 52. 56. 60. 64. 68. 72. 76. 80. 84. 88. 92. 96.] [ True True True True True True True True True True True True True True True True True True True True True True True True True]
The problem was solved, by using the chunker object to retain some memory.