Skip to content

Instantly share code, notes, and snippets.

@sergeyprokudin
Last active August 17, 2018 13:29
Show Gist options
  • Save sergeyprokudin/febdb301d1c935d5bac3a8d7a600034a to your computer and use it in GitHub Desktop.
Save sergeyprokudin/febdb301d1c935d5bac3a8d7a600034a to your computer and use it in GitHub Desktop.
Inverse Discrete Cosine Transform
#http://www.svcl.ucsd.edu/courses/ece161c/handouts/DCT.pdf
import numpy as np
import matplotlib.pyplot as plt
pi = np.pi
N = 50 # timesteps
k = 10 # n basis functions
coefs = np.random.rand(k) #generate random coeficients
ns = np.tile(np.arange(0, N, 1).reshape([N, 1]), [1, k])
coefs = np.tile(coefs.reshape([1, k]), [N, 1])
ks = np.tile(np.arange(0, k), [N, 1])
out = 1/N * np.sum(coefs *np.cos( (pi * ks * (2*ns + 1)) / (2*N)), axis=1)
plt.plot(ns[:, 0], out)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment