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