Facebook
From Mustard Butterfly, 5 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 238
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Thu May 10 10:11:06 2018
  4.  
  5. @author: Student
  6. """
  7. from pylab import *
  8. from numpy import *
  9. from matplotlib import *
  10. from scipy import *
  11.  
  12.  
  13. def cosinus(a,b,n):
  14.         t=linspace(a,b,n)
  15.         y=20+sin(2*pi*50*t)
  16.         return y
  17.        
  18.        
  19.  
  20. funkcja = cosinus(0,0.1,200)
  21. print(funkcja)
  22. t=linspace(0,0.1,200)
  23. subplot(311)
  24. plt.plot(t,funkcja,'r')
  25.  
  26. def dct(x):
  27.         N=x.shape[0]
  28.         y=empty(N)
  29.         for k in range (0,N-1):
  30.             y[k]=0
  31.             for n in range(0,N-1):
  32.                 y[k]+=x[n]*cos(pi/N*(n+0.5)*float(k))
  33.         return y
  34.        
  35. funkcja1=dct(funkcja)
  36. print(funkcja1)
  37. subplot(312)
  38. plt.plot(t,funkcja1,'r')
  39.  
  40. def idct(x):
  41.         N=x.shape[0]
  42.         y=empty(N)
  43.         for k in range (0,N-1):
  44.             y[k]=0.5*x[0]
  45.             for n in range(0,N-1):
  46.                 y[k]+=x[n]*cos(pi/N*(n+0.5)*float(k))
  47.                
  48.         return y
  49.        
  50. funkcja2=idct(funkcja)
  51. print(funkcja2)
  52. subplot(313)
  53. plt.plot(t,funkcja2,'r')