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 次方