2017/10/25

filter 濾波器

low-pass 低通
high-pass 高通
band-pass 帶通
band-stop 帶止/帶阻

passband 通帶/通頻帶
stopband 止帶/阻帶/抑制帶
transition band 過度帶/過渡頻帶

cutoff frequency 截止頻率

ripple 漣波

Matlab Filter Tools:

filterDesigner, sptool

2017/10/23

Matlab: Play an audio file with a directory

To play a sound file e.g. a wav file in a folder, type the following commands:

>> [y,Fs]= audioread('MyFolder/song.wav'); %Use slash for both Windows and Mac. Backslash works with Windows only.
>> sound(y,Fs);

2017/10/21

Matlab: Save and load variables/matrices in MAT file

To store and then read variables/matrices with Matlab, use the save and load commands with a *.mat file.
Example:

>> var1 = 1;
>> var2 = 2;
>> save var.mat var1 var2
>> clear
>> load var.mat


Related Information:

Matlab: Clear Commands (Study EECC)

2017/10/12

Fundamental Frequency, Harmonic and Overtone 基頻、諧波、泛音

Fundamental Frequency 基本頻率/基頻
Fundamental Tone 基音/根音
Harmonic 諧波/諧音
Harmonic series 諧波列/泛音列
Overtone 泛音

Standing Wave 駐波
Periodic Tone 週期音
Pure Tone 純音
Complex Tone 複合音/複音
Higher Harmonics 高次諧波 (f×2, f×3...)

Partial 分音 - 出現於complex tone中,不一定是F0的integer multiple的sine wave

Example of a harmonic series:

f = fundamental frequency / fundamental tone / 1st harmonic 第一諧音/波
f×2 = 1st overtone 第一泛音 / 2nd harmonic 第二諧音/波
f×3 = 2nd overtone 第二泛音 / 3rd harmonic 第三諧音/波

參考資料

Harmonic (Wikipedia)
駐波(standing waves)(小小整理網站)
Harmonics (諧波)、Overtones (泛音)、Partials (分音)
Fourier Analysis Terms 傅立葉分析相關名詞

2017/10/04

Matlab: Unit Impulse δ[n] 單位脈衝函數

The unit impulse, or the Dirac delta function, has zero values for all input values except a value of one at zero.

To plot the unit impulse function δ[n], type the Matlab code below:

>> t = -10:10;
>> s = (t==0); %s is one only when t equals 0
>> stem(t,s)

Result:



For δ[n-2], the Matlab code is

>> t = -10:10;
>> s2 = (t==2); %s is one when t equals 2
>> stem(t,s2)

Result:


Reference:

2017/09/30

Matlab: Plot multiple curves with legend

Example 1: Draw sin(x), sin(x/2) and sin(x)+sin(x/2)

>> x = 0:360;
>> y1 = sind(x);
>> y2 = sind(x/2);
>> y3 = y1+y2;
>> plot(x, y1, x, y2, x, y3);
>> legend('sin(x)','sin(x/2)','sin(x)+sin(x/2)')

Result:



Example 2: Draw log(x), log2(x), log10(x)

>> x = 0:0.01:5;
>> y1 = log(x);
>> y2 = log2(x);
>> y3 = log10(x);
>> plot(x, y1, x, y2, x, y3)
>> legend('log(x)','log2(x)','log10(x)')

Result:


Example 3: 3e-0.25*tsin(5t)

>> t = 0:0.01:30;
>> x1 = 3*exp(-0.25*t).*sin(5*t);
>> x2 = 0.2*cos(2*t);
>> x3 = 3*exp(-0.25*t).*sin(5*t)+0.2*cos(2*t);
>> plot(t,x1,t,x2,t,x3);
>> legend('x1','x2','x3');

Result:



Related Information:

Draw an Exponential Function with exp() with a custom Y-axis at x = 0
Exponential Function & Natural Logarithm 指數函數與自然對數

2017/09/28

Matlab: Hello GUI with guide

To draw a window or the graphical user interface (GUI) with Matlab, type:

>> guide

Select Blank GUI (Default):


A window for GUI design is displayed:



Draw something such as a "Hello World!" static text and some buttons.


Save the design figure as your preferred name, e.g. gui_layout.fig



A corresponding m file such as gui_layout.m is automatically created.


In the Command Window, type the name of the m-file e.g. type gui_layout and the window designed previously is displayed.








2017/09/02

OSI Model 開放式系統互聯通訊參考模型

OSI - Open System Interconnection
Open System Interconnection reference model 開放式系統互聯通訊參考模型 (Wikipedia/維基百科)

Layer 7 - Application 應用層

Layer 6 - Presentation 表達層/展示層

Layer 5 - Session 會議層/交談層

Layer 4 - Transport 傳輸層
Example: TCP (Transmission Control Protocol). Connection-oriented links for conveying segments of data.
Example: UDP (User Datagram Protocol). Connectionless transmission model. For Multimedia traffic.

Layer 3 - Network 網路層 Example: IP (Internet Protocol). Data transported as packets.

Layer 2 - Data Link 資料鏈結層
Logical Link Control (LLC) sublayer
Media Access Control (MAC) sublayer - e.g. CSMA/CD (802.3), CSMA/CA (802.11)

Layer 1 - Physical 實體層

References:

Communication Systems (4th Edition) by Simon Haykin, Wiley 2001, p11-12.
What is the difference between TCP and IP protocols?
Transmission Control Protocol(Wikipedia)
User Datagram Protocol(Wikipedia)
OSI七層簡介

2017/08/23

Tensor 張量

Array of numbers that may have
- scalar 純量
- vector 向量
- matrix 矩陣
- more dimensions.

Refernces

Lecture slides for Chapter 2 of Deep Learning, Ian Goodfellow
張量 (Tensor) - 金門大學陳鍾誠的網站

2017/08/19

Data Center Locations - Google, Akamai, CloudFlare, Amazon CloudFront

Below data are recorded on August 19, 2017

Google - https://www.google.com/about/datacenters/inside/locations/index.html

  • USA x 7
  • Asia x 2 (Taiwan, Singapore)
  • Europe x 4

      Taiwan 台灣 - Chunghua County 彰化縣

Akamai - https://www.akamai.com/us/en/locations.jsp

      Taiwan 台灣 - Taipei 台北市

CloudFlare - https://www.cloudflare.com/network/

  • 116 data centers

      Taiwan 台灣 - Taipei 台北(亞洲第28個/全球第77個data center)

Amazon CloudFront Edge InfraStructure - https://aws.amazon.com/cloudfront/details/


  • 22 edge locations / 11 regional edge caches


      Taiwan 台灣 - Taipei 台北

2017/07/31

Rectifiers 整流器

rectifiers 整流器

half-wave rectifiers 半波整流器
full-wave rectifiers 全波整流器

diode rectifier 二極體整流器

2017/07/24

Matlab: Play Demo Sounds

It is very easy to play some demo sounds with Matlab commands using the sound function.

To play a female speaker saying 'Matlab' type:

>> load mtlb
>> sound(mtlb,Fs)

Note that the workspace contains mtlb and Fs, so sound(mtlb,Fs) is called.

You may clear the workspace with the the clear command:

>> clear

To play a snippet of Handel's Hallelujah Chorus, type:

>> load handel
>> sound(y,Fs)

There are also other sounds you may load:

load chirp
load gong
load laughter
load train

References:

Formant Estimation with LPC Coefficients
Record and Play Audio
Sound + FFT

2017/06/13

Vectors 向量

dot product / scalar product / inner product / projection product 點積/內積/純量積 a·b
A·B = |A| |B| cos(θ)
AB = |A| cos(θ)

For vectors a = (a1, a2, ..., an) and b = (b1, b2, ..., bn) ,

a·b = a1b1 + a2b2 + ... + anbn

For example, vectors a = (1, 2, 3) and b = (0, 4, 5),

a·b = 1×0 + 2×4 + 3×5 = 23

Matlab code:

>> a = [1 2 3];
>> b = [0 4 5];
>> dot(a,b)

ans =

    23

cross product/vector product 點積/向量積 a×b

參考資料

內積與外積

2017/05/13

Cent and Semitone 音分和半音

cent 音分
semitone/half step/half tone 半音
whole tone 全音
accidental 變音記號

1 semitone = 100 cents

octave 八度音

一個八度音 = 12個半音 = 5個全音 + 2個半音
Twelve-tone equal temperament (十二平均律)
- divide an octave into 12 equal parts

Number of Semitones between Two Frequencies (兩個頻率間相差的半音數):

n = abs(log2(f1/f2)/log2(2(1/12))) = abs(12log2(f1/f2))

Reference

How to find the number of semitones between two frequencies?

2017/04/06

Matlab: Draw a grayscale

>> a = [0 40 80 120 160 200 220 255];
>> b = [a;a;a;a;a;a;a;a];
>> colormap('gray');
>> imagesc(b)


Result:


2017/04/03

Modulation terms 調變相關名詞

modulation 調變

modulator 調變器
demodulator 解調器/解調變器

amplitude modulation (AM) 振幅調變/調幅

angle modulation 角度調變
- frequency modulation (FM) 頻率調變/調頻
- phase modulation (PM) 相位調變/調相

modulation index 調變指數

Reference

S. Haykin, Communication Systems, 4th Edition, Wiley, pp106
國家教育研究院雙語詞彙、學術名詞暨辭書資訊網

2017/03/18

樂器的ADSR模型

A sound produced by a musical instrument can be explained using the ADSR model, which involves 4 stages:

attack
decay
sustain
release

2017/03/13

Matlab: Length and Size of a Vector/Matrix

Given that

>> a = [1 2 3;4 5 6]
>> b = 1:5

Length

>> length(a)

ans =

     3

>> length(b)

ans =

     5

Size

>> size(a)

ans =

     2     3

>> size(b)

ans =

     1     5

Matlab: How to use Quantiz with partition and codebook

The Quantiz function requires the Communications System Toolbox.
This quantization function requires at least an input signal and a partition vector.

Partition

The example below shows an input signal between 1 and 10. The partition vector equals [2 5 7]. When the signal is quantized, values become:

y = 0 if x <= 2
y = 1 if x <= 5
y = 2 if x <= 7
y = 3 if x > 7

>> x = 1:10

x =

     1     2     3     4     5     6     7     8     9    10

>> partition = [2 5 7]

partition =

     2     5     7

>> y = quantiz(x, partition)

y =

     0     0     1     1     1     2     2     3     3     3


Codebook

Using the same input signal x and partition above, add a codebook as:

>> codebook = [-4 0 2 4]

Insert the codebook as the third parameter in the Quantiz function. The index and quantized value quants are output:

>> [index,quants] = quantiz(x,partition,codebook)

index =

     0     0     1     1     1     2     2     3     3     3


quants =

    -4    -4     0     0     0     2     2     4     4     4



Reference

Quantization (MathWorks)

2017/03/12

PCM, DPCM, ADPCM

PCM is for audio applications

Pulse Code Modulation (PCM) 脈衝碼調變 (Wikipedia)

- μ-law PCM - USA/Japan
- A-law PCM - Europe

- Linear PCM (LPCM)
- Standard of compact discs and WAV files.

Differential PCM (DPCM) 差值脈衝編碼調變 (Wikipedia)

Adaptive DPCM (ADPCM) 適應性差值脈衝編碼調變 (Wikipedia)


2017/02/13

Sampling 取樣

Discrete-time signal x[n] is obtained by sampling a continuous-time signal xc(t):
x[n] = xc(nT) ,   -∞ < n < ∞

Fourier Transform:

xc(t) <--F--> X(jΩ)
x[n] <--F--> X(e)

ω = ΩT

Time Shift:
x(t-t0) <--F--> e-jΩt0 X(jΩ)
x[n-n0] <--F--> e-jωn0 X(e)

Frequency Shift:
e0x(t) <--F--> X(j(Ω-Ω0))
e0x[n] <--F--> X(ej(ω-ω0))

sampling period 取樣周期 T

sampling frequency 取樣頻率 fs or Ωs
With respect to different units:
Samples/second: fs = 1/T
Radians/second: Ωs = 2π/T = 2πfs

Nyquist Theorem
Nyquist Frequency ΩN
Nyquist Rate 2ΩN

aliasing 頻疊、摺疊效應

To avoid aliasing, Ωs >= 2ΩN

Foldover 反摺、混疊
- when the sampling rate is too low

Reference

Discrete-Time Signal Processing (2nd edition), A. Oppenheim & R. Schafer:
Fourier transform and inverse Fourier transform - p28
Time shift & frequency shift - Table 2.2, p59
Proof for time shift in z-transform - 3.4.2, p120

2017/02/12

Partial Fraction 部分分式

Partial fraction decomposition may be required for dealing with z-transform.

partial fraction decomposition 部分分式分解
partial fraction expansion 部分分式展開

Solution:

Let X/( 1 )( 2 ) = A/( 1 ) + B/( 2 )

Multiply ( 1 ) and ( 2 ) at both sides and get

X = A ( 2 ) + B ( 1 )

Let ( 1 ) = 0 to get A:
A = X / ( 2 ) | ( 1 ) = 0

Let ( 2 ) = 0 to get B:
B = X / ( 1 ) | ( 2 ) = 0

2017/02/09

Base and Exponent 底數與指數

For xn

中文讀法:x的n次方
英文讀法:x to the power of n

where

x:
base 底數

n:
index/exponent 指數
power 次方

2017/02/08

Linear, Time-Invariant, Causality, Stability 線性、非時變、因果性、穩定性

linear system 線性系統
time-invariant system 非時變系統
causality 因果性
stability 穩定性

For stability,
bounded-input bounded-output (BIBO) 有界輸入有界輸出

unit circle 單位圓
region of convergence 收斂域

When the ROC of z-transform X(z) includes the unit circle, x[n] is:

stable 穩定
absolutely summable 絕對可加

2017/02/07

Eigendecomposition, Eigenvalue, Eigenvector, Eigenfunction 特徵分解、特徵值、特徵向量、特徵函數/固有值、固有向量、固有函數

Eigendecomposition 特徵分解
Spectral decomposition 譜分解

scalar 純量
vector 向量

For n×n matrix A,

if Ax = λx

where
λ is a scalar.

x is a non-zero vector with dimension N.

Then

Av = λv
Eigenvalue 特徵值/固有值 λ
Eigenvector 特徵向量/固有向量 v

Af = λf
Eigenfunction 特徵函數/固有函數 f

For an LTI system, an input signal x[n] which is an eigenfunction of the system such as x[n] = ejωn appears at the output of the system with the eigenvalue H(e).

2017/01/30

Magnitude of Exponential Function e^jθ 如何求e^jθ的大小/絕對值

How to find the magnitude of exponential function e? Or |e| = ?

According to Euler's formula,

e = cosθ + isinθ

To find the magnitude of |e|,

|e| = SQRT(e) = SQRT(cos2θ + isin2θ) = SQRT(1) = 1

Therefore,

the magnitude of e is 1.

In other words, the magnitude of complex exponential is 1.

Related Information:

Euler's formula 歐拉公式
Why is the magnitude of e^(jwt) equal to 1?
Absolute value of complex exponential