Skip to content

Instantly share code, notes, and snippets.

@unalfaruk
Created February 4, 2022 12:22
Show Gist options
  • Save unalfaruk/8580133ecb989740abf720620503842a to your computer and use it in GitHub Desktop.
Save unalfaruk/8580133ecb989740abf720620503842a to your computer and use it in GitHub Desktop.
It is an example of "interpolation" in Python using NumPy.
# -*- coding: utf-8 -*-
"""
Created on Fri Feb 4 15:20:49 2022
@author: unalf
"""
import numpy as np
import matplotlib.pyplot as plt
device1 = np.random.rand(96) #Random data 1
time1 = np.linspace(0,60,96)
device2 = np.random.rand(43) #Random data 2
time2 = np.linspace(0,60,43)
int_device2 = np.interp(time1,time2,device2) #Interpolate
# PLOTTING
plt.subplot(3, 1, 1)
plt.title("Device 1")
plt.ylabel("Value")
plt.plot(time1,device1, marker ='o')
plt.subplot(3, 1, 2)
plt.title("Device 2")
plt.ylabel("Value")
plt.plot(time2,device2, marker = "o")
plt.subplot(3, 1, 3)
plt.title("Interpolated Device 2")
plt.xlabel("time (sec)")
plt.ylabel("Value")
plt.plot(time1,int_device2, marker = "o")
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment