2014-05-19 08:03:38 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
Created on Sun May 18 11:09:23 2014
|
|
|
|
|
|
|
|
@author: rlabbe
|
|
|
|
"""
|
|
|
|
|
|
|
|
from __future__ import division
|
|
|
|
import numpy as np
|
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
|
|
|
|
|
2015-02-16 16:10:01 +01:00
|
|
|
def plot_transfer_func(data, f, lims, num_bins=1000):
|
2014-05-19 08:03:38 +02:00
|
|
|
ys = f(data)
|
2015-02-16 16:10:01 +01:00
|
|
|
|
|
|
|
|
|
|
|
h = np.histogram(ys, num_bins, density=False)
|
|
|
|
|
2014-05-19 08:03:38 +02:00
|
|
|
#plot output
|
|
|
|
plt.subplot(2,2,1)
|
2015-02-16 16:10:01 +01:00
|
|
|
plt.plot(h[0], h[1][1:], lw=4)
|
2014-05-19 08:03:38 +02:00
|
|
|
plt.ylim(lims)
|
|
|
|
plt.gca().xaxis.set_ticklabels([])
|
|
|
|
plt.title('output')
|
|
|
|
|
2015-02-14 05:41:38 +01:00
|
|
|
plt.axhline(np.mean(ys), ls='--', lw=2)
|
|
|
|
|
2014-05-19 08:03:38 +02:00
|
|
|
# plot transfer function
|
|
|
|
plt.subplot(2,2,2)
|
|
|
|
x = np.arange(lims[0], lims[1],0.1)
|
|
|
|
y = f(x)
|
|
|
|
plt.plot (x,y)
|
|
|
|
isct = f(0)
|
|
|
|
plt.plot([0,0,lims[0]],[lims[0],isct,isct],c='r')
|
|
|
|
plt.xlim(lims)
|
|
|
|
plt.ylim(lims)
|
2014-05-19 23:34:47 +02:00
|
|
|
plt.title('transfer function')
|
2014-05-19 08:03:38 +02:00
|
|
|
|
|
|
|
# plot input
|
2015-02-16 16:10:01 +01:00
|
|
|
h = np.histogram(data, num_bins, density=True)
|
|
|
|
|
2014-05-19 08:03:38 +02:00
|
|
|
plt.subplot(2,2,4)
|
2015-02-16 16:10:01 +01:00
|
|
|
plt.plot(h[1][1:], h[0], lw=4)
|
2014-05-19 08:03:38 +02:00
|
|
|
plt.xlim(lims)
|
|
|
|
plt.gca().yaxis.set_ticklabels([])
|
|
|
|
plt.title('input')
|
|
|
|
|
|
|
|
plt.show()
|
2015-02-14 05:41:38 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
from numpy.random import normal
|
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
data = normal(loc=0.0, scale=1, size=500000)
|
|
|
|
|
|
|
|
def g(x):
|
|
|
|
return (np.cos(4*(x/2+0.7)))*np.sin(0.3*x)-1.6*x
|
|
|
|
|
|
|
|
|
2015-02-16 16:10:01 +01:00
|
|
|
plot_transfer_func (data, g, lims=(-3,3), num_bins=100)
|