{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "-"
}
},
"source": [
"# 信號與系統實習\n",
"\n",
"\n",
"\n",
"若想要在家中電腦執行以下程式,請前往 https://store.continuum.io/cshop/anaconda/ 下載Anaconda Python 軟體\n",
"\n",
"實驗開始步驟:\n",
"\n",
"(1)前往 https://github.com/htygithub/SS_EXP 點選右下角按鈕 \"Download Zip\"\n",
"\n",
"(2)將 Zip 檔解壓縮至\"我的文件\"\n",
"\n",
"(3)按下開始工具列->附屬應用程式->命令提示字元 來開啟命令列視窗\n",
"\n",
"(4)於命令列鍵入 jupyter notebook 指令來開啟 Jupyter 視窗\n",
"\n",
"(5)開啟Lesson_0_Scipy_intro.ipynb 開始以下實驗作答\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 實驗一: Numpy , Matplotlib 初見面 \n",
"\n",
"用滑鼠點選以下程式碼,並按下\"Play\"鈕執行看看結果
"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#coding: utf-8\n",
"%matplotlib inline\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
"x=np.array([0,0,0,0,1,1,1,1,0,0,0,0])\n",
"plt.plot(x,'ro-')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 問題一\n",
"(1)按加號新增一個\"Markdown\"區塊,描述你看到了什麼。
\n",
"(2)再按加號新增一個\"code\"區塊,嘗試畫出 \"三個帽子\"的波形
\n",
"(按加號後,點選 'Cell Toolbar' 左方是下拉式選單,選擇 CODE)\n",
"****************************************************************************************"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 實驗二: Python 之資料顯示以及np 陣列\n",
"用滑鼠點選以下程式碼,並按下\"Play\"鈕執行看看結果
"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#coding: utf-8\n",
"import numpy as np\n",
"\n",
"t=np.arange(0,1,0.1)\n",
"print (t)\n",
"print (\"這是 np.arange(0,1,0.1)的結果:\" + str(t))\n",
"print (\"加上一些換行字元\\n\\n\\n\" + \"換行的結果是這樣\\n\")\n",
"t=np.arange(0,1,0.01)\n",
"print (\"這是 np.arange(0,1,0.01)的結果:\")\n",
"print (t)\n",
"sumt=sum(np.arange(0,10,1))\n",
"print (\"\\n\\n\\n這是 sum(np.arange(0,10,1))的結果:\" +str(sumt))"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "-"
}
},
"source": [
"# 問題二\n",
"新增一個\"Markdown\"區塊,將以下問題之答案寫下來。
\n",
"(1)請推論 np.arange 這個函數的用處,以及三個輸入值的意義。
\n",
"(2)新增一個\"code\"區塊,利用python 程式碼,計算100以下偶數之總合。\n",
"****************************************************************************************\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "-"
}
},
"source": [
"# 實驗三 : 弦波的頻率以及繪圖\n",
"用滑鼠點選以下程式碼,並按下\"Play\"鈕執行看看結果
"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#coding: utf-8\n",
"%matplotlib inline\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
"t=np.arange(0,1,0.01)\n",
"pi=np.pi\n",
"curve=np.sin(2*pi*10*t)\n",
"curve2=np.sin(2*pi*5*t)\n",
"plt.plot(t,curve,'b',t,curve2,'r')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 問題三\n",
"\n",
"(1)假設橫軸時間單位為秒,請問curve及curve2各為幾Hz弦波(也就是在一秒內走了幾個週期)?
\n",
"(新增一個\"Markdown\"區塊,回答此問題)
\n",
"(2)又我們如何改變指令,畫出一個 3 Hz的Cosine波呢?
\n",
"(新增一個\"CODE\"區塊,回答此問題)\n",
"****************************************************************************************"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 實驗四 : 影像以及RGB色彩\n",
"用滑鼠點選以下程式碼,並按下\"Play\"鈕執行看看結果
"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#coding: utf-8\n",
"%matplotlib inline\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
"x=np.array([0,0,0,1,1,1,1,0,0,0])\n",
"y=np.array([x,x,x,x,x,x,x,x,x,x])\n",
"print(y)\n",
"print(y.shape)\n",
"plt.figure(1)\n",
"plt.imshow(y,cmap='gray',interpolation='nearest')\n",
"y=np.array([x/5.,x/4.,x/3.,x/2.,x/1.,x,x,x,x,x])\n",
"plt.figure(2)\n",
"plt.imshow(y,cmap='gray',interpolation='nearest')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 問題四\n",
"(1)請問y 矩陣的大小為何?
\n",
"(2)試完成一個10x10的矩陣,顯示一個白色十字。\n",
"(新增一個\"CODE\"區塊,回答此問題)\n",
"****************************************************************************************"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 實驗五 :RGB色彩\n",
"用滑鼠點選以下程式碼,並按下\"Play\"鈕執行看看結果
"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#coding: utf-8\n",
"%matplotlib inline\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
"x=np.array([0,0,0,1,1,1,1,0,0,0])\n",
"y=np.array([x,x,x,x,x,x,x,x,x,x])\n",
"z=np.zeros([10,10,3])\n",
"z[:,:,0]=y \n",
"plt.figure(figsize=[15,5])\n",
"plt.subplot(1,4,1)\n",
"plt.imshow(z,interpolation='nearest')\n",
"#######################################\n",
"z=np.zeros([10,10,3])\n",
"z[:,:,1]=y\n",
"plt.subplot(1,4,2)\n",
"plt.imshow(z,interpolation='nearest')\n",
"#######################################\n",
"z=np.zeros([10,10,3])\n",
"z[:,:,2]=y\n",
"plt.subplot(1,4,3)\n",
"plt.imshow(z,interpolation='nearest')\n",
"#######################################\n",
"z=np.zeros([10,10,3])\n",
"z[:,:,0]=y\n",
"z[:,:,1]=y\n",
"plt.subplot(1,4,4)\n",
"plt.imshow(z,interpolation='nearest')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 問題五\n",
"以上範例是將紅光、綠光、藍光分別開至最大亮度 (數值1)
\n",
"若是將紅、綠、藍分別以1, 0.5, 0 來表示, 試著新增一組程式碼完成配色,並說明合成的顏色為?\n",
"\n",
"****************************************************************************************"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.10"
}
},
"nbformat": 4,
"nbformat_minor": 1
}