{"id":894,"date":"2014-05-01T16:52:15","date_gmt":"2014-05-01T14:52:15","guid":{"rendered":"http:\/\/darksun190.cn\/?p=894"},"modified":"2014-05-01T16:52:15","modified_gmt":"2014-05-01T14:52:15","slug":"%e4%bd%bf%e7%94%a8python%e6%a8%a1%e6%8b%9f%e9%ab%98%e6%96%af%e6%bb%a4%e6%b3%a2%e8%bf%87%e7%a8%8b%e5%b9%b6%e7%94%9f%e6%88%90%e8%a7%86%e9%a2%91","status":"publish","type":"post","link":"http:\/\/darksun190.cn\/blog\/?p=894","title":{"rendered":"\u4f7f\u7528Python\u6a21\u62df\u9ad8\u65af\u6ee4\u6ce2\u8fc7\u7a0b\u5e76\u751f\u6210\u89c6\u9891"},"content":{"rendered":"<p>Python\u5728\u8fd9\u7c7b\u5de5\u4f5c\u4e0a\u7684\u65b9\u4fbf\u7a0b\u5ea6\u771f\u7684\u662f\u2014\u2014\u723d\u3002<\/p>\n<p>\u8fd9\u91cc\u6a21\u62df\u7684\u662f\u4f4e\u901a\u9ad8\u65af\u6ee4\u6ce2\u7684\u8fc7\u7a0b\u3002<br \/>\n<iframe loading=\"lazy\" width=\"420\" height=\"315\" src=\"\/\/www.youtube.com\/embed\/5lPK9jPLkss\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<p>\u4ee3\u7801\u5982\u4e0b\uff1a\u9700\u8981numpy \u548cmatplotlib\uff0c\u5982\u679c\u60f3\u4fdd\u5b58\u6210\u89c6\u9891\u6587\u4ef6\u8fd8\u9700\u8981\u4e0b\u8f7dffmpeg<\/p>\n<pre class=\"lang:python decode:true\"># encoding: utf-8\n'''\nCreated on 2014\u5e745\u67081\u65e5\n\n@author: zcxsun\n'''\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom matplotlib import animation\nplt.rcParams['animation.ffmpeg_path'] = r'C:\\sunxin\\ffmpeg_x64\\bin\\ffmpeg.exe'\n\n# First set up the figure, the axis, and the plot element we want to animate\nfig = plt.figure()\n\nspeed = 1\nsize = 360\na = np.arange(size) *np.pi\/180\nb = np.zeros(size)\nx = -0.1\nfor i in range(1,14,2):\n    x = x*(i-2)\/i\n    b += x * np.sin(a*i)\nb+= 0.02 * np.sin(a*50) + 0.01 * np.sin(a*150)\nfix_signal = b\n\nhamonic = 15\n\nlen = max(1, size\/hamonic\/2)\nprint len\nscale = 0.3*len+0.8;\nscale2x = -0.5\/scale\/scale\nwin =  np.exp( pow(np.arange(2*len+1)-len,2)*scale2x)\nwin\/=sum(win)\nmove_gauss = win\nprint win.size\nfiltered_data = np.convolve(b, win, 'same')\n\n\n#set the axis arrange\ny_max = 0.4\nax = plt.axes(xlim=(0, 360), ylim=(-0.2, y_max))\nline_gauss, = ax.plot([], [], lw=2)\nline_filtered, = ax.plot([],[],lw=2)\n\nplt.plot(fix_signal)\n\n# initialization function: plot the background of each frame\ndef init():\n    line_gauss.set_data([],[])\n    line_filtered.set_data([],[])\n    return line_gauss,line_filtered,\n# animation function.  This is called sequentially\ndef animate(i):\n    n = np.floor(i*speed)\n    line_gauss.set_data(n+np.arange(0,win.size),win + (y_max-0.03-win.max()))\n    line_filtered.set_data(np.arange(0,n),filtered_data[0:n])\n    return line_gauss,line_filtered,\nanim = animation.FuncAnimation(fig, animate, init_func=init,\n                               frames=int(np.floor(size\/speed)), interval=10, blit=True)\n\nFFwriter = animation.FFMpegWriter(fps = 15)\npath = r\"C:\\Users\\Public\\Documents\\filter_show_hamonic_\" + str(hamonic) + \".mp4\"\nanim.save(path, writer = FFwriter)\n#\n# plt.show()\nprint 'finish'<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python\u5728\u8fd9\u7c7b\u5de5\u4f5c\u4e0a\u7684\u65b9\u4fbf\u7a0b\u5ea6\u771f\u7684\u662f\u2014\u2014\u723d\u3002 \u8fd9\u91cc\u6a21\u62df\u7684\u662f\u4f4e\u901a\u9ad8\u65af\u6ee4\u6ce2\u7684\u8fc7\u7a0b\u3002 \u4ee3\u7801\u5982\u4e0b\uff1a\u9700\u8981numpy  &hellip; <a href=\"http:\/\/darksun190.cn\/blog\/?p=894\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201c\u4f7f\u7528Python\u6a21\u62df\u9ad8\u65af\u6ee4\u6ce2\u8fc7\u7a0b\u5e76\u751f\u6210\u89c6\u9891\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"video","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[8],"tags":[],"class_list":["post-894","post","type-post","status-publish","format-video","hentry","category-geo","post_format-post-format-video"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/darksun190.cn\/blog\/index.php?rest_route=\/wp\/v2\/posts\/894","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/darksun190.cn\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/darksun190.cn\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/darksun190.cn\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/darksun190.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=894"}],"version-history":[{"count":0,"href":"http:\/\/darksun190.cn\/blog\/index.php?rest_route=\/wp\/v2\/posts\/894\/revisions"}],"wp:attachment":[{"href":"http:\/\/darksun190.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=894"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/darksun190.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=894"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/darksun190.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=894"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}