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)