2018/06/28

Vector Spaces 向量空間

2D Vector Space
vector v = (x, y) or (v1, v2)

3D Vector Space
vector v = (x, y, z) or (v1, v2, v3)

N-Dimensional Vector Space
vector v = (v1, v2, v3, ..., vN)

References

Vector Space (Wikipedia)
What is a Vector Space? (Video)

2018/06/16

Matlab: Plot discrete sequence data with STEM() 繪製離散序列資料

To plot discrete sequence data in Matlab, use the stem() function:

Example:
For y = e-x + 1 with x between -2 and 2, plot the continuous y curve and discrete stem diagram.

x = -2:0.1:2;
y = exp(-x)+1;
subplot(211);
plot(x,y);
xlabel('x');ylabel('y');title('y = exp(-x)+1');
subplot(212);
stem(x,y);

xlabel('x');ylabel('y');title('discrete x');

Result:



References:

stem - plot discrete sequence data (MathWorks)
Matlab: Unit Impulse δ[n] 單位脈衝函數

2018/06/15

Matlab: Resample 重新取樣

To change the sample rate of an audio signal with Matlab, use the resample function:

load mtlb;
sound(mtlb,Fs);
pause(1); %Wait until the sound is finished
Fs_new = 16e3; %change the sample rate to 16000
[P,Q] = rat(Fs_new/Fs);

y = resample(mtlb,P,Q);

sound(y,Fs_new);

Reference

Changing Signal Sample Rate (MathWorks)

2018/06/11

Floating-Point

IEEE 754-1985, 754-2008
IEEE single-precision standard (binary32) - 32 bits
IEEE double-precision standard (binary64) - 64 bits

single-recision (binary32) -
1 bit - sign (S)
8 bits - exponention (E)
23 bits - mantissa (M)

Number = (-1)S×1.M×E-127

Reference:

Tutorial: Floating-Point Binary
Floating point ALU using VHDL implemented on FPGA
Single-precision floating-point format (Wikipedia)
Double-precision floating-point format (Wikipedia)

Two's complement

For representing +ve and -ve numbers.

The most significant bit (leftmost) bit:
0 => 0 or positive
1 => negative

e.g. 01110000 => +ve
e.g. 11110000 => -ve

If the left most bit = 0,

01110000 = 2^6+2^5+2^4 = 64+32+16 = 112

If the left most bit = 1, invert every remaining bit and add 1.

11110000 => 0001111 + 1 => 0010000 => -16

Reference:

Two's complement (Wikipedia)

2018/06/07

Matlab: Real and imaginary parts of complex number and multiplication with imaginary unit j

For a complex number x = 1 + 2i or x = 1 + 2j

Matlab commands for real part - real(x)
Matlab commands for imaginary part - imag(x)

Example:

>> x = 1 + 2j

x =

   1.0000 + 2.0000i

>> real(x)

ans =

     1

>> imag(x)

ans =

     2

>>

To multiply x with an imaginary unit i or -i, simply swap the real part with the imaginary part and add a negative sign.

Example:


x = 1 + 2j
mult_pos_j(x)
mult_neg_j(x)

function result = mult_pos_j(x)
    % x = a + bj
    % x(j) = aj - b = -b + aj
    result = -imag(x) + real(x)*j;
end

function result = mult_neg_j(x)
    % x = a + bj
    % x(-j) = -aj + b = b - aj
    result = imag(x) - real(x)*j;
end

Result:

x =

   1.0000 + 2.0000i


ans =

  -2.0000 + 1.0000i


ans =

   2.0000 - 1.0000i

Related Information:

Complex numbers - simple calculations (StudySwift - iOS)