├── .gitattributes ├── .gitignore ├── Assignment1 ├── diffeqn2.m └── src │ ├── diffeqn.m │ ├── q1_4_a.m │ ├── q1_4_b.m │ ├── q1_4_c.m │ ├── q1_4_d.m │ ├── q1_4_e.m │ ├── q1_4_f.m │ ├── q1_4_g.m │ ├── q1_5_b.m │ ├── q1_5_c.m │ └── q1_5_d.m ├── Assignment2 └── src │ ├── lineup.mat │ ├── q2_10_a.m │ ├── q2_10_b.m │ ├── q2_10_c.m │ ├── q2_10_d.m │ ├── q2_10_e.m │ ├── q2_10_f_y2.m │ ├── q2_10_f_y3.m │ ├── q2_10_f_y3calc.m │ ├── q2_4.m │ ├── q2_5_a.m │ ├── q2_5_d.m │ ├── q2_5_e.m │ ├── q2_5_f.m │ ├── q2_5_g.m │ └── test.m ├── Assignment3 └── src │ ├── dtfs.m │ ├── q3_10_p1.m │ ├── q3_10_p2.m │ ├── q3_5.m │ ├── q3_8.m │ └── q3_9.m ├── Assignment4 └── src │ ├── ctftmod.mat │ ├── q4_2.m │ ├── q4_5.m │ └── q4_6.m ├── Assignment5 └── src │ ├── a5_q1.m │ ├── a5_q2.m │ ├── a5_q3.m │ ├── assets │ ├── SSN.wav │ └── yuki_004627.ogg │ ├── butterLPF.m │ └── record.m ├── Project1 └── src │ ├── assets │ ├── C_01_01.wav │ ├── C_01_02.wav │ ├── SSN.wav │ └── yuki_004627.ogg │ ├── base_full.m │ ├── proj_1.m │ ├── results │ ├── C_01_01.wav_SSN.wav │ ├── C_01_01.wav_T1_TVC_1_50.wav │ ├── C_01_01.wav_T1_TVC_2_50.wav │ ├── C_01_01.wav_T1_TVC_4_50.wav │ ├── C_01_01.wav_T1_TVC_6_50.wav │ ├── C_01_01.wav_T1_TVC_8_50.wav │ ├── C_01_01.wav_T2_TVC_4_100.wav │ ├── C_01_01.wav_T2_TVC_4_20.wav │ ├── C_01_01.wav_T2_TVC_4_400.wav │ ├── C_01_01.wav_T2_TVC_4_50.wav │ ├── C_01_01.wav_T3_SSN_TVC_16_50.wav │ ├── C_01_01.wav_T3_SSN_TVC_2_50.wav │ ├── C_01_01.wav_T3_SSN_TVC_4_50.wav │ ├── C_01_01.wav_T3_SSN_TVC_6_50.wav │ ├── C_01_01.wav_T3_SSN_TVC_8_50.wav │ ├── C_01_01.wav_T4_SSN_TVC_6_100.wav │ ├── C_01_01.wav_T4_SSN_TVC_6_20.wav │ ├── C_01_01.wav_T4_SSN_TVC_6_400.wav │ └── C_01_01.wav_T4_SSN_TVC_6_50.wav │ ├── ssn_gen.m │ ├── test.m │ └── tone_vocoder.m ├── Project2 └── src │ ├── ADC_LPF.m │ ├── LPF.mat │ ├── LPF2.mat │ ├── LPF3.mat │ ├── OFDM.m │ ├── OFDM_full.m │ ├── addon.m │ ├── calcH.m │ ├── calcH2.m │ ├── calcH3.m │ ├── disscus_CP.m │ ├── disscus_LPF.m │ ├── iLPF.m │ ├── iLPF.mat │ ├── main.m │ ├── matlab.mat │ └── total.mat └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | *.mat filter=lfs diff=lfs merge=lfs -text 2 | *.wav filter=lfs diff=lfs merge=lfs -text 3 | *.ogg filter=lfs diff=lfs merge=lfs -text 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.rar 2 | *.pdf 3 | *.ppt* 4 | report.md 5 | .old 6 | /*/assets/ 7 | -------------------------------------------------------------------------------- /Assignment1/diffeqn2.m: -------------------------------------------------------------------------------- 1 | function y = diffeqn2(a,x,yn1) 2 | m = fliplr(diag((a .^ (0:length(x))))*triu(ones(length(x)+1))).'; 3 | n = diag([yn1 x])*triu(ones(length(x)+1)); 4 | y = sum(diag([yn1 x])*triu(ones(length(x)+1)) .* triu(flip(diag((a .^ (length(x):-1:0)))*ones(length(x)+1)))); 5 | y = y(2:end); -------------------------------------------------------------------------------- /Assignment1/src/diffeqn.m: -------------------------------------------------------------------------------- 1 | function y = diffeqn(a,x,yn1) 2 | y = [yn1 zeros(1, length(x))]; 3 | for i = 2:length(y) 4 | y(i) = a.*y(i-1) + x(i-1); 5 | end 6 | y = y(2:end); 7 | -------------------------------------------------------------------------------- /Assignment1/src/q1_4_a.m: -------------------------------------------------------------------------------- 1 | clc; clear; 2 | 3 | n = -3:3; 4 | x1 = [zeros(1,3), 1, zeros(1,3)]; 5 | x2 = 2 .* x1; 6 | 7 | y = @(x) sin(pi/2 .* x); 8 | 9 | subplot(3, 1, 1); 10 | stem(n, x1); 11 | axis([xlim -0.2 1.2]); 12 | xlabel('n'); ylabel('x[n]'); 13 | 14 | subplot(3, 1, 2); 15 | stem(n, y(x1), 'b.'); hold on; 16 | stem(n, y(x2), 'ro'); 17 | axis([xlim -0.2 1.2]); 18 | xlabel('n'); ylabel('y[n]'); 19 | legend('y|x_1', 'y|x_2'); 20 | 21 | subplot(3, 1, 3); 22 | stem(n, y(x1)+y(x2), 'b.'); hold on; 23 | stem(n, y(x1+x2), 'ro'); 24 | axis([xlim -1.2 1.2]); 25 | xlabel('n'); ylabel('y[n]'); 26 | legend('y|x_1 + y|x_2', 'y|(x_1+x_2)'); 27 | -------------------------------------------------------------------------------- /Assignment1/src/q1_4_b.m: -------------------------------------------------------------------------------- 1 | clc; clear; 2 | 3 | n = -5:9; 4 | x = [zeros(1,5), ones(1,10)]; 5 | n1 = -6:8; 6 | y = [x 0] + [0 x]; 7 | 8 | subplot(3, 1, 1); 9 | stem(n, x); 10 | axis([-5 9 -0.2 1.2]); 11 | xlabel('n'); ylabel('x[n]'); 12 | 13 | subplot(3, 1, 2); 14 | stem(n1, x); 15 | axis([xlim -0.2 1.2]); 16 | xlabel('n'); ylabel('x[n+1]'); 17 | 18 | subplot(3, 1, 3); 19 | stem(-6:9, y); 20 | axis([-6 9 -0.2 2.2]); 21 | xlabel('n'); ylabel('y[n]'); 22 | -------------------------------------------------------------------------------- /Assignment1/src/q1_4_c.m: -------------------------------------------------------------------------------- 1 | clc; clear; 2 | 3 | n = 0:6; 4 | % set x[n] = n 5 | x = n; 6 | 7 | y = @(X) log(x); 8 | 9 | subplot(2, 1, 1); 10 | stem(n, x); 11 | axis([-0.5 6 ylim]); 12 | xlabel('n'); ylabel('x[n]'); 13 | 14 | subplot(2, 1, 2); 15 | yx = y(x); 16 | stem(n, yx); 17 | axis([-0.5 6 ylim]); 18 | xlabel('n'); ylabel('y[n]'); 19 | -------------------------------------------------------------------------------- /Assignment1/src/q1_4_d.m: -------------------------------------------------------------------------------- 1 | clc; clear; 2 | 3 | y = @(x) sin(pi/2 .* x); 4 | 5 | n = -4:4; 6 | x = n; 7 | 8 | subplot(2, 1, 1); 9 | stem(n, x); 10 | xlabel('n'); ylabel('x[n]'); 11 | 12 | subplot(2, 1, 2); 13 | stem(n, y(x)); 14 | axis([xlim -1.2 1.2]); 15 | xlabel('n'); ylabel('y[n]'); 16 | -------------------------------------------------------------------------------- /Assignment1/src/q1_4_e.m: -------------------------------------------------------------------------------- 1 | clc; clear; 2 | 3 | y = @(x) x.^3; 4 | 5 | % non linear 6 | n = -2:2; 7 | x1 = n; 8 | x2 = 2 .* n; 9 | 10 | subplot(3, 1, 1); 11 | stem(n, x1); 12 | xlabel('n'); ylabel('x[n]'); 13 | 14 | subplot(3, 1, 2); 15 | stem(n, y(x1), 'b*'); hold on; 16 | stem(n, y(x2), 'ro'); 17 | xlabel('n'); ylabel('y[n]'); 18 | legend('y|x_1', 'y|x_2'); 19 | 20 | subplot(3, 1, 3); 21 | stem(n, y(x1)+y(x2), 'b*'); hold on; 22 | stem(n, y(x1+x2), 'ro'); 23 | xlabel('n'); ylabel('y[n]'); 24 | legend('y|x_1 + y|x_2', 'y|(x_1+x_2)'); 25 | -------------------------------------------------------------------------------- /Assignment1/src/q1_4_f.m: -------------------------------------------------------------------------------- 1 | clc; clear; 2 | 3 | y = @(n, x) n .* x; 4 | 5 | % not time-invariant 6 | n = -3:3; 7 | x1 = n; 8 | x2 = n-1; 9 | 10 | subplot(2, 1, 1); 11 | stem(n, x1, 'b*'); hold on; 12 | stem(n, x2, 'ro'); 13 | xlabel('n'); ylabel('x[n]'); 14 | legend('x[n]', 'x[n-1]'); 15 | 16 | subplot(2, 1, 2); 17 | stem(n, y(n, x1), 'b*'); hold on; 18 | stem(n, y(n, x2), 'ro'); 19 | xlabel('n'); ylabel('y[n]'); 20 | legend('y|x[n]', 'y|x[n-1]'); -------------------------------------------------------------------------------- /Assignment1/src/q1_4_g.m: -------------------------------------------------------------------------------- 1 | clc; clear; 2 | 3 | % not casual 4 | n = -4:4; 5 | x = n; 6 | 7 | y = intersect(n, 2.*n); 8 | 9 | subplot(2, 1, 1); 10 | stem(n, x); 11 | xlabel('n'); ylabel('x[n]'); 12 | 13 | subplot(2, 1, 2); 14 | stem(n, [Inf Inf y Inf Inf]); 15 | axis([-4 4 ylim]); 16 | xlabel('n'); ylabel('y[n]'); 17 | -------------------------------------------------------------------------------- /Assignment1/src/q1_5_b.m: -------------------------------------------------------------------------------- 1 | clc; clear; 2 | 3 | a = 1; 4 | yn1 = 0; 5 | n = 0:30; 6 | 7 | x1 = [1 zeros(1,30)]; 8 | x2 = ones(1,31); 9 | 10 | y1 = diffeqn(a, x1, yn1); 11 | y2 = diffeqn(a, x2, yn1); 12 | 13 | subplot(2,1,1); 14 | stem(n, y1); 15 | axis([xlim, 0 1.1]); 16 | xlabel('n'); ylabel('y_1[n]'); 17 | subplot(2,1,2); 18 | stem(n, y2); 19 | xlabel('n'); ylabel('y_2[n]'); 20 | -------------------------------------------------------------------------------- /Assignment1/src/q1_5_c.m: -------------------------------------------------------------------------------- 1 | clc; clear; 2 | 3 | a = 1; 4 | yn1 = -1; 5 | n = 0:30; 6 | 7 | x1 = ones(1,31); 8 | x2 = 2 .* ones(1,31); 9 | 10 | y1 = diffeqn(a, x1, yn1); 11 | y2 = diffeqn(a, x2, yn1); 12 | 13 | subplot(3,1,1); 14 | stem(n, y1); 15 | xlabel('n'); ylabel('y_1[n]'); 16 | subplot(3,1,2); 17 | stem(n, y2); 18 | xlabel('n'); ylabel('y_2[n]'); 19 | subplot(3,1,3); 20 | stem(n, 2.*y1 - y2); 21 | xlabel('n'); ylabel('2y_1[n]-y_2[n]'); 22 | axis([xlim, -1.1 0]); 23 | -------------------------------------------------------------------------------- /Assignment1/src/q1_5_d.m: -------------------------------------------------------------------------------- 1 | clc; clear; 2 | 3 | a = 1/2; 4 | yn11 = 0; 5 | yn12 = 1/2; 6 | n = 0:30; 7 | 8 | x = ones(1,31); 9 | 10 | y1 = diffeqn(a, x, yn11); 11 | yy = diffeqn2(a, x, yn11); 12 | y2 = diffeqn(a, x, yn12); 13 | 14 | subplot(2,1,1); 15 | stem(n, y1); 16 | axis([xlim 0 2.2]); 17 | xlabel('n'); ylabel('y_1[n]'); 18 | subplot(2,1,2); 19 | stem(n, y2); 20 | axis([xlim 0 2.2]); 21 | xlabel('n'); ylabel('y_2[n]'); 22 | -------------------------------------------------------------------------------- /Assignment2/src/lineup.mat: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:6207720f564e3a1828c6f3555efc1aa0ec6ff6b7ffc9a2bc30da0af1b5b96ba5 3 | size 168068 4 | -------------------------------------------------------------------------------- /Assignment2/src/q2_10_a.m: -------------------------------------------------------------------------------- 1 | clc; clear; close('all'); 2 | 3 | n = 0:1000; 4 | x = [1 zeros(1, 1000)]; 5 | 6 | b = [1 zeros(1, 999) 0.5]; 7 | a = 1; 8 | he = filter(b, a, x); 9 | 10 | figure; 11 | stem(n, he, 'r'); grid('on'); 12 | -------------------------------------------------------------------------------- /Assignment2/src/q2_10_b.m: -------------------------------------------------------------------------------- 1 | clc; clear; close('all'); 2 | 3 | n = 0:1000; 4 | x = [1 zeros(1, 1000)]; 5 | 6 | a = 1; 7 | b = [1 zeros(1, 999) 0.5]; 8 | y = filter(b, a, x); 9 | 10 | a = [1 zeros(1, 999) 0.5]; 11 | b = 1; 12 | z = filter(b, a, y); 13 | 14 | figure; 15 | subplot(3,1,1); 16 | stem(n, x, 'r'); 17 | title('x'); grid('on'); 18 | subplot(3,1,2); 19 | stem(n, y, 'r'); 20 | title('y'); grid('on'); 21 | subplot(3,1,3); 22 | stem(n, z, 'r'); 23 | title('z'); grid('on'); 24 | -------------------------------------------------------------------------------- /Assignment2/src/q2_10_c.m: -------------------------------------------------------------------------------- 1 | clc; clear; close('all'); 2 | 3 | n = 0:1000; 4 | x = [1 zeros(1, 1000)]; 5 | 6 | a = [1 zeros(1, 999) 0.5]; 7 | b = 1; 8 | her = filter(b, a, x); 9 | 10 | figure; 11 | stem(n, her, 'r'); 12 | title('her'); grid('on'); 13 | -------------------------------------------------------------------------------- /Assignment2/src/q2_10_d.m: -------------------------------------------------------------------------------- 1 | clc; clear; close('all'); 2 | 3 | load('./lineup.mat'); 4 | 5 | % sound(y, 8192); 6 | 7 | a = [1 zeros(1, 999) 0.5]; 8 | b = 1; 9 | z = filter(b, a, y); 10 | 11 | figure; 12 | subplot(2,1,1); 13 | plot(y); title('origin sound'); 14 | subplot(2,1,2); 15 | plot(z); title('filtered sound'); 16 | 17 | % sound(z, 8192); 18 | -------------------------------------------------------------------------------- /Assignment2/src/q2_10_e.m: -------------------------------------------------------------------------------- 1 | clc; clear; close('all'); 2 | 3 | n = 0:1000; 4 | x = [1 zeros(1, 1000)]; 5 | 6 | b = [1 zeros(1, 999) 0.5]; 7 | a = 1; 8 | he = filter(b, a, x); 9 | 10 | b = 1; 11 | a = [1 zeros(1, 999) 0.5]; 12 | her = filter(b, a, x); 13 | 14 | hoa = conv(he, her); 15 | 16 | figure; 17 | subplot(3,1,1); 18 | stem(n, he, 'r'); 19 | title('he'); grid('on'); 20 | subplot(3,1,2); 21 | stem(n, her, 'r'); 22 | title('her'); grid('on'); 23 | subplot(3,1,3); 24 | stem(0:2000, hoa, 'r'); 25 | title('hoa'); grid('on'); 26 | -------------------------------------------------------------------------------- /Assignment2/src/q2_10_f_y2.m: -------------------------------------------------------------------------------- 1 | clc; clear; close('all'); 2 | 3 | load('./lineup.mat'); 4 | 5 | Ryy2 = conv(y2, flipud(y2)); 6 | 7 | figure; 8 | plot(-6999:6999, Ryy2 / Ryy2(7000)); 9 | axis([-6999 6999 -.4 1]); 10 | 11 | b = 1; 12 | a = [1 zeros(1, 500) 0.7]; 13 | z2 = filter(b, a, y2); 14 | Rzz2 = conv(z2, flipud(z2)); 15 | % sound(z2, 8192); 16 | 17 | figure; 18 | subplot(2,1,1); 19 | plot(z2); title('filtered sound'); 20 | subplot(2,1,2); 21 | plot(-6999:6999, Rzz2 / Rzz2(7000)); title('z2 autocorrelation'); 22 | axis([-6999 6999 -.4 1]); 23 | -------------------------------------------------------------------------------- /Assignment2/src/q2_10_f_y3.m: -------------------------------------------------------------------------------- 1 | clc; clear; close('all'); 2 | 3 | load('./lineup.mat'); 4 | 5 | Ryy3 = conv(y3, flipud(y3)); 6 | 7 | figure; 8 | plot(-6999:6999, Ryy3 / Ryy3(7000)); 9 | axis([-6999 6999 -.4 1]); 10 | 11 | b = 1; 12 | a = [1 zeros(1, 750) 0.75 zeros(1, 1500) 0.6]; 13 | z3 = filter(b, a, y3); 14 | 15 | % sound(z3, 8192); 16 | 17 | figure; 18 | plot(z3); title('filtered sound'); 19 | -------------------------------------------------------------------------------- /Assignment2/src/q2_10_f_y3calc.m: -------------------------------------------------------------------------------- 1 | clc; clear; close('all'); 2 | 3 | load('./lineup.mat'); 4 | 5 | i = 0; 6 | for x = 0.7:0.01:0.8 7 | for y = 0:0.01:1 8 | b = 1; 9 | a = [1 zeros(1, 750) x zeros(1, 1500) y]; 10 | z3 = filter(b, a, y3); 11 | i = i + 1; 12 | data(i, :) = [x, y, sum(abs(z3))]; 13 | end 14 | end 15 | 16 | [val, pos] = min(data(:,3)); 17 | disp(data(pos,1)); 18 | disp(data(pos,2)); 19 | -------------------------------------------------------------------------------- /Assignment2/src/q2_4.m: -------------------------------------------------------------------------------- 1 | clc; clear; close('all'); 2 | 3 | %% 2_4_a 4 | nx1 = 0:9; 5 | x1 = [ones(1,5), zeros(1,5)]; 6 | 7 | nh1 = 0:4; 8 | h1 = [1, -1, 3, 1, 0]; 9 | h2 = [2, 5, 4, -1, 0]; 10 | 11 | figure; 12 | subplot(3,1,1); 13 | stem(nx1, x1); 14 | title('x_1'); grid('on'); 15 | subplot(3,1,2); 16 | stem(nh1, h1); 17 | title('h_1'); grid('on'); 18 | subplot(3,1,3); 19 | stem(nh1, h2); 20 | title('h_2'); grid('on'); 21 | 22 | 23 | %% 2_4_b 24 | y1 = conv(x1, h1); 25 | y2 = conv(h1, x1); 26 | ny = 0:13; 27 | 28 | figure; 29 | subplot(2,1,1); 30 | stem(ny, y1); 31 | title('conv(x1, h1)'); grid('on'); 32 | subplot(2,1,2); 33 | stem(ny, y2); 34 | title('conv(h1, x1)'); grid('on'); 35 | 36 | 37 | %% 2_4_c 38 | y1 = conv(x1, h1) + conv(x1, h2); 39 | y2 = conv(x1, h1+h2); 40 | 41 | figure; 42 | subplot(2,1,1); 43 | stem(ny, y1); 44 | title('conv(x1, h1) + conv(x1, h2)'); grid('on'); 45 | subplot(2,1,2); 46 | stem(ny, y2); 47 | title('conv(x1, h1+h2)'); grid('on'); 48 | 49 | 50 | %% 2_4_d 51 | w = conv(x1, h1); 52 | yd1 = conv(w, h2); 53 | 54 | hs = conv(h1, h2); 55 | yd2 = conv(x1, hs); 56 | nyd = 0:17; 57 | 58 | figure; 59 | subplot(2,1,1); 60 | stem(nyd, yd1); 61 | title('y_{d1}'); grid('on'); 62 | subplot(2,1,2); 63 | stem(nyd, yd2); 64 | title('y_{d2}'); grid('on'); 65 | 66 | 67 | %% 2_4_e 68 | n0 = 2; 69 | 70 | he1 = h1; 71 | nhe1 = nh1; 72 | delta_f = [0 0 1]; 73 | n_delta = [0 1 2]; 74 | he2 = conv(h1, delta_f); % h[n-2]=h[n]*delta[n-2]; n = 0:6 75 | 76 | ye1 = conv(x1, he1); 77 | nye1 = 0:13; 78 | ye2 = conv(x1, he2); 79 | nye2 = 0:15; 80 | 81 | figure; 82 | subplot(4,1,1); 83 | stem(nye1, ye1); axis([0 15 ylim]) 84 | title('y_{e1}=conv(x1, he1)'); grid('on'); 85 | subplot(4,1,3); 86 | stem(nye2, ye2); 87 | title('y_{e2}=conv(x1, he2)'); grid('on'); 88 | 89 | ye1 = conv(he1, x1); 90 | nye1 = 0:13; 91 | ye2 = conv(he2, x1); 92 | nye2 = 0:15; 93 | 94 | subplot(4,1,2); 95 | stem(nye1, ye1); axis([0 15 ylim]) 96 | title('y_{e1}=conv(he1, x1)'); grid('on'); 97 | subplot(4,1,4); 98 | stem(nye2, ye2); 99 | title('y_{e2}=conv(he2, x1)'); grid('on'); 100 | 101 | 102 | %% 2_4_f 103 | w = (nx1+1) .* x1; % w: 0~9 104 | hf2 = h1; % hf2: 0~4 105 | yf1 = conv(w, hf2); % yf1: 0~13 106 | 107 | d = [1 zeros(1,4)]; 108 | nd = 0:4; 109 | hf1 = (nd+1) .* d; % hf1: 0~4 110 | 111 | hs = conv(hf1, hf2); % hs: 0~8 112 | yf2 = conv(x1, hs); % yf2: 0~17 113 | 114 | figure; 115 | subplot(2,1,1); 116 | stem(0:13, yf1); 117 | title('y_{f1}'); grid('on'); 118 | subplot(2,1,2); 119 | stem(0:17, yf2); 120 | title('y_{f2}'); grid('on'); 121 | 122 | 123 | %% 2_4_g 124 | xg = [2 zeros(1,4)]; 125 | nd = 0:4; 126 | yga = xg .^ 2; % 0~4 127 | 128 | hg2 = h2; 129 | ygb = conv(xg, hg2); % 0~8 130 | 131 | yg1 = [yga zeros(1,4)] + ygb; 132 | 133 | d = [1 zeros(1,4)]; 134 | hg1 = d .^ 2; 135 | hparallel = hg1 + hg2; 136 | yg2 = conv(xg, hparallel); % 0~8 137 | 138 | figure; 139 | subplot(2,1,1); 140 | stem(0:8, yg1); 141 | title('y_{g1}'); grid('on'); 142 | subplot(2,1,2); 143 | stem(0:8, yg2); 144 | title('y_{g2}'); grid('on'); 145 | -------------------------------------------------------------------------------- /Assignment2/src/q2_5_a.m: -------------------------------------------------------------------------------- 1 | clc; clear; close('all'); 2 | 3 | 4 | w_f = @(x) x - circshift(x, 1) - circshift(x, 2); % only work for this situation 5 | x1 = [1 0 0 0 0 0]; 6 | x2 = [0 1 0 0 0 0]; 7 | x3 = [1 2 0 0 0 0]; 8 | nx = 0:5; 9 | 10 | w1 = w_f(x1); 11 | w2 = w_f(x2); 12 | w3 = w_f(x3); 13 | 14 | figure; 15 | subplot(4,1,1); 16 | stem(nx, w1); 17 | title('w_1'); grid('on'); 18 | subplot(4,1,2); 19 | stem(nx, w2); 20 | title('w_2'); grid('on'); 21 | subplot(4,1,3); 22 | stem(nx, w3); 23 | title('w_3'); grid('on'); 24 | subplot(4,1,4); 25 | stem(nx, w1+2*w2); 26 | title('w_1+2*w_2'); grid('on'); 27 | 28 | y1 = cos(x1); 29 | y2 = cos(x2); 30 | y3 = cos(x3); 31 | 32 | figure; 33 | subplot(4,1,1); 34 | stem(nx, y1); 35 | title('y_1'); grid('on'); 36 | subplot(4,1,2); 37 | stem(nx, y2); 38 | title('y_2'); grid('on'); 39 | subplot(4,1,3); 40 | stem(nx, y3); 41 | title('y_3'); grid('on'); 42 | subplot(4,1,4); 43 | stem(nx, y1+2*y2); 44 | title('y_1+2*y_2'); grid('on'); 45 | 46 | 47 | z1 = nx .* x1; 48 | z2 = nx .* x2; 49 | z3 = nx .* x3; 50 | 51 | figure; 52 | subplot(4,1,1); 53 | stem(nx, z1); 54 | title('z_1'); grid('on'); 55 | subplot(4,1,2); 56 | stem(nx, z2); 57 | title('z_2'); grid('on'); 58 | subplot(4,1,3); 59 | stem(nx, z3); 60 | title('z_3'); grid('on'); 61 | subplot(4,1,4); 62 | stem(nx, z1+2*z2); 63 | title('z_1+2*z_2'); grid('on'); 64 | -------------------------------------------------------------------------------- /Assignment2/src/q2_5_d.m: -------------------------------------------------------------------------------- 1 | clc; clear; close('all'); 2 | 3 | n = 0:19; 4 | delta = [1 zeros(1,19)]; 5 | 6 | h1 = filter(1, [1, -3/5], delta); 7 | 8 | h2_f = @(n) (3/5).^(n.*(n+1)./2); 9 | h2 = h2_f(n); 10 | 11 | figure; 12 | subplot(2,1,1); 13 | stem(n, h1); 14 | title('h_1'); grid('on'); 15 | subplot(2,1,2); 16 | stem(n, h2); 17 | title('h_2'); grid('on'); 18 | -------------------------------------------------------------------------------- /Assignment2/src/q2_5_e.m: -------------------------------------------------------------------------------- 1 | clc; clear; close('all'); 2 | 3 | n = 0:19; 4 | u = ones(1, 20); 5 | 6 | s1 = filter(1, [1, -3/5], u); 7 | 8 | s2 = ones(1, 20); 9 | for i = 1:19 10 | s2(i+1) = (3/5)^i * s2(i) + u(i+1); 11 | end 12 | 13 | figure; 14 | subplot(2,1,1); 15 | stem(n, s1); 16 | title('s_1'); grid('on'); 17 | subplot(2,1,2); 18 | stem(n, s2); 19 | title('s_2'); grid('on'); 20 | -------------------------------------------------------------------------------- /Assignment2/src/q2_5_f.m: -------------------------------------------------------------------------------- 1 | clc; clear; close('all'); 2 | 3 | n = 0:19; 4 | delta = [1 zeros(1,19)]; 5 | h1 = filter(1, [1, -3/5], delta); 6 | h2_f = @(n) (3/5).^(n.*(n+1)./2); 7 | h2 = h2_f(n); 8 | 9 | u = ones(1,20); 10 | 11 | z1 = conv(h1, u); 12 | z1 = z1(1:20); 13 | z2 = conv(h2, u); 14 | z2 = z2(1:20); 15 | 16 | figure; 17 | subplot(2,1,1); 18 | stem(n, z1); 19 | title('z_1'); grid('on'); 20 | subplot(2,1,2); 21 | stem(n, z2); 22 | title('z_2'); grid('on'); 23 | -------------------------------------------------------------------------------- /Assignment2/src/q2_5_g.m: -------------------------------------------------------------------------------- 1 | clc; clear; close('all'); 2 | 3 | n = 0:19; 4 | delta = [1 zeros(1,19)]; 5 | h1 = filter(1, [1, -3/5], delta); 6 | h2_f = @(n) (3/5).^(n.*(n+1)./2); 7 | h2 = h2_f(n); 8 | 9 | u = ones(1,20); 10 | 11 | s1 = filter(1, [1, -3/5], u); 12 | 13 | s2 = ones(1, 20); 14 | for i = 1:19 15 | s2(i+1) = (3/5)^i * s2(i) + u(i+1); 16 | end 17 | 18 | z1 = conv(h1, u); 19 | z1 = z1(1:20); 20 | z2 = conv(h2, u); 21 | z2 = z2(1:20); 22 | 23 | figure; 24 | subplot(2,1,1); hold('on'); 25 | stem(n, s1); 26 | stem(n, z1, '*'); 27 | title('s_1 &. z_1'); grid('on'); 28 | subplot(2,1,2); hold('on'); 29 | stem(n, s2); 30 | stem(n, z2, '*'); 31 | title('s_2 &. z_2'); grid('on'); 32 | -------------------------------------------------------------------------------- /Assignment2/src/test.m: -------------------------------------------------------------------------------- 1 | clc; clear; close('all'); 2 | 3 | load('./lineup.mat'); 4 | 5 | Ryy = conv(y, flipud(y)); 6 | 7 | figure; 8 | plot(-6999:6999, Ryy / Ryy(7000)); 9 | axis([-6999 6999 -.4 1]); -------------------------------------------------------------------------------- /Assignment3/src/dtfs.m: -------------------------------------------------------------------------------- 1 | function a = dtfs(x, x_init) 2 | if nargin == 1 3 | x_init = 0; 4 | end 5 | N = size(x, 2); 6 | a = 1/N * x * exp(-1i * 2*pi/N * (x_init:(x_init+N-1)).' * (0:N-1)); 7 | end 8 | -------------------------------------------------------------------------------- /Assignment3/src/q3_10_p1.m: -------------------------------------------------------------------------------- 1 | close('all'); clear; clc; 2 | 3 | %% b - test 4 | cal = 15; 5 | dtfscomps = zeros(1, cal); 6 | for i = 1:cal 7 | N = 2^i; 8 | x = 0.9 .^ (0:N-1); 9 | tests = 2^(cal-i); 10 | tic; 11 | for k = 1:tests 12 | X = dtfs(x, 0); 13 | end 14 | dtfscomps(i) = toc / tests; 15 | end 16 | 17 | 18 | %% c - test 19 | fftcomps = zeros(1, cal); 20 | for i = 1:cal 21 | N = 2^i; 22 | x = 0.9 .^ (0:N-1); 23 | tests = 2^(cal-i); 24 | tic; 25 | for k = 1:tests 26 | X = fft(x); % no need for *1/N, just a benchmark 27 | end 28 | fftcomps(i) = toc / tests; 29 | end 30 | 31 | 32 | %% bc - figure 33 | figure; 34 | loglog(2.^(1:cal), dtfscomps); hold('on'); 35 | loglog(2.^(1:cal), fftcomps); 36 | grid('on'); title('Time Cost'); 37 | legend('dtfs', 'fft'); xlabel('N'); ylabel('time'); 38 | 39 | %% bc - figure2 40 | figure; 41 | loglog(2.^(1:cal), dtfscomps ./ fftcomps); 42 | grid('on'); title('dtfscomps / fftcomps'); xlabel('N'); 43 | -------------------------------------------------------------------------------- /Assignment3/src/q3_10_p2.m: -------------------------------------------------------------------------------- 1 | close('all'); clear; clc; 2 | 3 | %% e 4 | N = 40; 5 | n = 0:(N-1); 6 | x = 0.9 .^ n; 7 | h = 0.5 .^ n; 8 | x_h = conv([x x], h); 9 | y = x_h((N+1):2*N); 10 | 11 | figure; hold('on'); 12 | stem(n, x); stem(n, h, 'bs'); stem(n, y, 'r*'); 13 | grid('on'); legend('x', 'h', 'y'); title('N=40'); xlabel('n'); 14 | 15 | 16 | %% g 17 | fft_x = fft(x); 18 | fft_h = fft(h); 19 | fft_y = fft_x .* fft_h; 20 | y_ifft = ifft(fft_y); 21 | 22 | figure; hold('on'); 23 | stem(n, y); stem(n, y_ifft, 'r*'); 24 | grid('on'); legend('y_conv', 'y_ifft'); title('N=40'); xlabel('n'); 25 | 26 | 27 | %% f 28 | N = 80; 29 | n = 0:(N-1); 30 | x = 0.9 .^ n; 31 | h = 0.5 .^ n; 32 | x_h = conv([x x], h); 33 | y = x_h((N+1):2*N); 34 | 35 | figure; hold('on'); 36 | stem(n, x); stem(n, h, 'bs'); stem(n, y, 'r*'); 37 | grid('on'); legend('x', 'h', 'y'); title('N=80'); xlabel('n'); 38 | 39 | 40 | %% h 41 | fft_x = fft(x); 42 | fft_h = fft(h); 43 | fft_y = fft_x .* fft_h; 44 | y_ifft = ifft(fft_y); 45 | 46 | figure; hold('on'); 47 | stem(n, y); stem(n, y_ifft, 'r*'); 48 | grid('on'); legend('y_conv', 'y_ifft'); title('N=80'); xlabel('n'); 49 | -------------------------------------------------------------------------------- /Assignment3/src/q3_5.m: -------------------------------------------------------------------------------- 1 | close('all'); clear; clc; 2 | 3 | %% c 4 | a = [1, 2*exp(-1i*pi/3), exp(1i*pi/4), exp(-1i*pi/4), 2*exp(1i*pi/3)]; 5 | 6 | N = size(a, 2); 7 | n = 0:20; 8 | 9 | x = a * exp(1i*2*pi/N * (0:(N-1)).' * n); 10 | 11 | figure; 12 | subplot(3,1,1); 13 | stem(n, abs(x)); axis([-1 5 -5 5]); 14 | title('|x[n]|'); xlabel('n'); ylabel('x'); 15 | subplot(3,1,2); 16 | stem(n, real(x)); axis([-1 5 -5 5]); 17 | title('real(x[n])'); xlabel('n'); ylabel('x'); 18 | subplot(3,1,3); 19 | stem(n, imag(x)); axis([-1 5 ylim]) 20 | title('imag(x[n])'); xlabel('n'); ylabel('x'); 21 | 22 | 23 | %% d 24 | n = 0:63; 25 | 26 | x1 = repmat(ones(1,8), 1, size(n,2)/8); 27 | x2 = repmat([ones(1,8) zeros(1,8)], 1, size(n,2)/16); 28 | x3 = repmat([ones(1,8) zeros(1,24)], 1, size(n,2)/32); 29 | 30 | figure; 31 | subplot(3,1,1); 32 | stem(n, x1); axis([0 64 -0.1 1.1]); 33 | title('x_1[n]'); xlabel('n'); ylabel('x'); 34 | subplot(3,1,2); 35 | stem(n, x2); axis([0 64 -0.1 1.1]); 36 | title('x_2[n]'); xlabel('n'); ylabel('x'); 37 | subplot(3,1,3); 38 | stem(n, x3); axis([0 64 -0.1 1.1]); 39 | title('x_3[n]'); xlabel('n'); ylabel('x'); 40 | 41 | 42 | %% e 43 | a1 = repmat(1/8 * fft(ones(1,8)), 1, size(n,2)/8); 44 | a2 = repmat(1/16 * fft([ones(1,8) zeros(1,8)]), 1, size(n,2)/16); 45 | a3 = repmat(1/32 * fft([ones(1,8) zeros(1,24)]), 1, size(n,2)/32); 46 | 47 | figure; 48 | subplot(3,1,1); 49 | stem(n, abs(a1)); axis([0 63 ylim]); grid('on'); 50 | title('|a_1|'); xlabel('k'); ylabel('a'); 51 | subplot(3,1,2); 52 | stem(n, abs(a2)); axis([0 63 ylim]); grid('on'); 53 | title('|a_2|'); xlabel('k'); ylabel('a'); 54 | subplot(3,1,3); 55 | stem(n, abs(a3)); axis([0 63 ylim]); grid('on'); 56 | title('|a_3|'); xlabel('k'); ylabel('a'); 57 | 58 | 59 | %% f 60 | a3_shift = fftshift(a3); 61 | 62 | mid = size(n,2)/2 + 1; 63 | a3_2 = a3_shift(mid-2:mid+2); 64 | a3_8 = a3_shift(mid-8:mid+8); 65 | a3_12 = a3_shift(mid-12:mid+12); 66 | a3_all = a3_shift(mid-15:mid+16); 67 | 68 | n = 0:31; 69 | x3_2 = a3_2 * exp(1i*2*pi/size(a3_2,2) * (-2:2).' * n); 70 | x3_8 = a3_8 * exp(1i*2*pi/size(a3_8,2) * (-8:8).' * n); 71 | x3_12 = a3_12 * exp(1i*2*pi/size(a3_12,2) * (-12:12).' * n); 72 | x3_all = a3_all * exp(1i*2*pi/size(a3_all,2) * (-15:16).' * n); 73 | 74 | figure; 75 | subplot(4,1,1); 76 | stem(n, real(x3_2)); grid('on'); axis([0 31 ylim]); 77 | title('real(x_{3\_2})'); xlabel('n'); ylabel('x'); 78 | subplot(4,1,2); 79 | stem(n, real(x3_8)); grid('on'); axis([0 31 ylim]); 80 | title('real(x_{3\_8})'); xlabel('n'); ylabel('x'); 81 | subplot(4,1,3); 82 | stem(n, real(x3_12)); grid('on'); axis([0 31 ylim]); 83 | title('real(x_{3\_12})'); xlabel('n'); ylabel('x'); 84 | subplot(4,1,4); 85 | stem(n, real(x3_all)); grid('on'); axis([0 31 ylim]); 86 | title('real(x_{3\_all})'); xlabel('n'); ylabel('x'); 87 | 88 | 89 | %% h 90 | n = 0:63; 91 | figure; hold('on'); 92 | stem(n, x3); 93 | n = 0:31; 94 | stem(n, real(x3_2),'m^'); grid('on'); 95 | stem(n, real(x3_8),'bs'); grid('on'); 96 | stem(n, real(x3_12),'g+'); grid('on'); 97 | stem(n, real(x3_all),'r*'); grid('on'); 98 | xlabel('n'); ylabel('x'); 99 | legend('x_3', 'real(x_{3\_2})', 'real(x_{3\_8})', 'real(x_{3\_12})', 'real(x_{3\_all})') 100 | -------------------------------------------------------------------------------- /Assignment3/src/q3_8.m: -------------------------------------------------------------------------------- 1 | close('all'); clear; clc; 2 | 3 | %% a 4 | a1 = [1 -0.8]; b1 = 1; 5 | a2 = [1 0.8]; b2 = 1; 6 | 7 | 8 | %% b 9 | n = 1024; 10 | [h1, w1] = freqz(b1, a1, n, 'whole'); 11 | [h2, w2] = freqz(b2, a2, n, 'whole'); 12 | 13 | subplot(2,1,1); 14 | plot(w1, abs(h1)); grid('on'); 15 | set(gca,'xlim',[0,2.*pi], 'xtick',0:pi/2:2*pi, 'XTickLabel',{'0','\pi/2','\pi','3\pi/2','2\pi'}); 16 | title('Frequency Response of System 1'); xlabel('\omega'); ylabel('amplitude'); 17 | subplot(2,1,2); 18 | plot(w2, abs(h2)); grid('on'); 19 | set(gca,'xlim',[0,2.*pi], 'xtick',0:pi/2:2*pi, 'XTickLabel',{'0','\pi/2','\pi','3\pi/2','2\pi'}); 20 | title('Frequency Response of System 2'); xlabel('\omega'); ylabel('amplitude'); 21 | 22 | %% c 23 | k = 0:19; 24 | a_x = [0 3/4 zeros(1,7) -1/2 0 -1/2 zeros(1,7) 3/4]; 25 | 26 | figure; 27 | stem(k, a_x); grid('on'); axis([0 19 ylim]); 28 | title('a_k'); xlabel('\omega_k=(2\pi/20)k'); ylabel('a') 29 | 30 | 31 | %% d 32 | x_20 = 20 * ifft(a_x); 33 | x = repmat(x_20, 1, 6); 34 | n = -20:99; 35 | 36 | figure; 37 | stem(n, x); grid('on'); 38 | xlabel('n'); ylabel('x'); 39 | 40 | 41 | %% e 42 | y1 = filter(b1, a1, x); 43 | y2 = filter(b2, a2, x); 44 | 45 | figure; 46 | subplot(2,1,1); 47 | stem(n, y1); grid('on'); axis([0 99 ylim]); 48 | title('y_1'); xlabel('n'); ylabel('y'); 49 | subplot(2,1,2); 50 | stem(n, y2); grid('on'); axis([0 99 ylim]); 51 | title('y_2'); xlabel('n'); ylabel('y'); 52 | 53 | 54 | %% f 55 | n = 0:19; 56 | y1_20 = y1(20:39); 57 | y2_20 = y2(20:39); 58 | a_y1 = 1/20 * fft(y1_20); 59 | a_y2 = 1/20 * fft(y2_20); 60 | 61 | figure; 62 | subplot(2,1,1); 63 | stem(n, abs(a_y1)); grid('on'); axis([0 19 ylim]); 64 | title('a_y_1'); xlabel('\omega_k=(2\pi/20)k'); ylabel('a'); 65 | subplot(2,1,2); 66 | stem(n, abs(a_y2)); grid('on'); axis([0 19 ylim]); 67 | title('a_y_2'); xlabel('\omega_k=(2\pi/20)k'); ylabel('a'); 68 | -------------------------------------------------------------------------------- /Assignment3/src/q3_9.m: -------------------------------------------------------------------------------- 1 | close('all'); clear; clc; 2 | 3 | t = linspace(0, 20, 1000); 4 | x = cos(t); 5 | sys = tf(1,[1 1]); 6 | 7 | %% a 8 | yt = lsim(sys, x, t); 9 | 10 | figure; hold('on'); 11 | plot(t(501:end), x(501:end)); 12 | plot(t(501:end), yt(501:end)); 13 | grid('on'); legend('x(t)', 'y(t)'); xlabel('t'); 14 | 15 | 16 | %% b 17 | x2 = sign(x); 18 | y2t = lsim(sys, x2, t); 19 | 20 | figure; hold('on'); 21 | plot(t(501:end), x2(501:end)); 22 | plot(t(501:end), y2t(501:end)); 23 | grid('on'); legend('x_2(t)', 'y_2(t)'); xlabel('t'); 24 | 25 | %% c 26 | a_k = @(k) 2/(pi*k) * sin(pi/2*k)^3; 27 | apos_k = @(k) a_k(k); 28 | aneg_k = @(k) a_k(-k); 29 | 30 | s1 = apos_k(1)*exp(1i*t) + aneg_k(1)*exp(-1i*t); 31 | s2 = apos_k(2)*exp(2i*t) + aneg_k(2)*exp(-2i*t); 32 | s3 = apos_k(3)*exp(3i*t) + aneg_k(3)*exp(-3i*t); 33 | s4 = apos_k(4)*exp(4i*t) + aneg_k(4)*exp(-4i*t); 34 | s5 = apos_k(5)*exp(5i*t) + aneg_k(5)*exp(-5i*t); 35 | ssum = s1 + s2 + s3 + s4 + s5; 36 | 37 | figure; hold('on'); 38 | plot(t(501:end), x2(501:end)); 39 | plot(t(501:end), ssum(501:end)); 40 | grid('on'); legend('x_2(t)', 'sum(s1-5)'); xlabel('t'); 41 | 42 | %% d 43 | y1 = lsim(sys, s1, t); 44 | y2 = lsim(sys, s2, t); 45 | y3 = lsim(sys, s3, t); 46 | y4 = lsim(sys, s4, t); 47 | y5 = lsim(sys, s5, t); 48 | yssum = y1+y2+y3+y4+y5; 49 | y_ssum = lsim(sys, ssum, t); 50 | 51 | figure; hold('on'); 52 | plot(t(501:end), yssum(501:end)); 53 | plot(t(501:end), y_ssum(501:end) - 0.1); 54 | grid('on'); legend('sum(y1-5)', 'ssum->lsim - 0.1'); xlabel('t'); 55 | 56 | %% e 57 | figure; hold('on'); 58 | plot(t(501:end), y2t(501:end)); 59 | plot(t(501:end), y_ssum(501:end)); 60 | grid('on'); legend('y_2(t)', 'yssum'); xlabel('t'); 61 | 62 | %% f 63 | y1v = 1/(1+1i)*apos_k(1)*exp(1i*t) + 1/(1-1i)*aneg_k(1)*exp(-1i*t); 64 | y2v = 1/(1+2i)*apos_k(2)*exp(2i*t) + 1/(1-2i)*aneg_k(2)*exp(-2i*t); 65 | y3v = 1/(1+3i)*apos_k(3)*exp(3i*t) + 1/(1-3i)*aneg_k(3)*exp(-3i*t); 66 | y4v = 1/(1+4i)*apos_k(4)*exp(4i*t) + 1/(1-4i)*aneg_k(4)*exp(-4i*t); 67 | y5v = 1/(1+5i)*apos_k(5)*exp(5i*t) + 1/(1-5i)*aneg_k(5)*exp(-5i*t); 68 | 69 | 70 | figure; 71 | subplot(5,2,1); 72 | plot(t(501:end), y1(501:end)); 73 | grid('on'); title('y_1'); xlabel('t'); 74 | subplot(5,2,2); 75 | plot(t(501:end), y1v(501:end)); 76 | grid('on'); title('y_1v'); xlabel('t'); 77 | subplot(5,2,3); 78 | plot(t(501:end), y2(501:end)); 79 | grid('on'); title('y_2'); xlabel('t'); 80 | subplot(5,2,4); 81 | plot(t(501:end), y2v(501:end)); 82 | grid('on'); title('y_2v'); xlabel('t'); 83 | subplot(5,2,5); 84 | plot(t(501:end), y3(501:end)); 85 | grid('on'); title('y_3'); xlabel('t'); 86 | subplot(5,2,6); 87 | plot(t(501:end), y3v(501:end)); 88 | grid('on'); title('y_3v'); xlabel('t'); 89 | subplot(5,2,7); 90 | plot(t(501:end), y4(501:end)); 91 | grid('on'); title('y_4'); xlabel('t'); 92 | subplot(5,2,8); 93 | plot(t(501:end), y4v(501:end)); 94 | grid('on'); title('y_4v'); xlabel('t'); 95 | subplot(5,2,9); 96 | plot(t(501:end), y5(501:end)); 97 | grid('on'); title('y_5'); xlabel('t'); 98 | subplot(5,2,10); 99 | plot(t(501:end), y5v(501:end)); 100 | grid('on'); title('y_5v'); xlabel('t'); 101 | -------------------------------------------------------------------------------- /Assignment4/src/ctftmod.mat: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:ce870440f493d03f82a1e48b5a4c37a40200d24d1c82272c2d2c36270204849f 3 | size 147213 4 | -------------------------------------------------------------------------------- /Assignment4/src/q4_2.m: -------------------------------------------------------------------------------- 1 | close('all'); clear; clc; 2 | 3 | %% a 4 | X_gen = @(w) 4./(4+w.^2); 5 | 6 | 7 | %% b 8 | tau = 1e-2; 9 | T = 11; 10 | t = 0:tau:(T-tau); 11 | N = round(T/tau); 12 | 13 | y = exp(-2 * abs(t-5)); 14 | y(t>10) = 0; 15 | 16 | figure; 17 | plot(t, y); grid('on'); 18 | axis([t(1) t(end) ylim]); 19 | title('y(t)=x(t-5)'); xlabel('t'); 20 | 21 | 22 | %% c 23 | Y = fftshift(tau*fft(y)); 24 | 25 | 26 | %% d 27 | w = -(pi/tau) + (0:(N-1)) * (2*pi/(N*tau)); 28 | 29 | 30 | %% e 31 | X = exp(5i*w) .* Y; 32 | 33 | 34 | %% f 35 | figure; 36 | subplot(2,1,1); 37 | semilogy(w, abs(X)); grid('on'); 38 | axis([w(1) w(end) ylim]); 39 | title('X Magnitude'); xlabel('\omega'); 40 | subplot(2,1,2); 41 | plot(w, angle(X)); grid('on'); 42 | axis([w(1) w(end) ylim]); 43 | title('X Phase'); xlabel('\omega'); 44 | 45 | X_ana = X_gen(w); 46 | 47 | figure; 48 | subplot(2,1,1); 49 | semilogy(w, abs(X_ana)); grid('on'); 50 | axis([w(1) w(end) ylim]); 51 | title('Analytical X Magnitude'); xlabel('\omega'); 52 | subplot(2,1,2); 53 | plot(w, unwrap(angle(X_ana))); grid('on'); 54 | axis([w(1) w(end) ylim]); 55 | title('Analytical X Phase'); xlabel('\omega'); 56 | 57 | figure; 58 | semilogy(w, abs(X)); hold('on'); 59 | semilogy(w, abs(X_ana)); grid('on'); 60 | axis([w(1) w(end) ylim]); 61 | xlabel('\omega'); legend('fft X', 'ana X'); 62 | 63 | 64 | %% g 65 | figure; 66 | subplot(2,1,1); 67 | semilogy(w, abs(Y)); grid('on'); 68 | title('Y Magnitude'); xlabel('\omega'); 69 | subplot(2,1,2); 70 | plot(w, unwrap(angle(Y))); grid('on'); 71 | axis([w(1) w(end) ylim]); 72 | title('Y Phase'); xlabel('\omega'); 73 | -------------------------------------------------------------------------------- /Assignment4/src/q4_5.m: -------------------------------------------------------------------------------- 1 | close('all'); clear; clc; 2 | 3 | %% a 4 | b1 = [1 -2]; 5 | a1 = [1 3/2 1/2]; 6 | 7 | %% b 8 | [r1, p1] = residue(b1, a1); 9 | fprintf('r1 = \n'); disp(r1); 10 | fprintf('p1 = \n'); disp(p1); 11 | 12 | 13 | %% d 14 | b2 = [3 10 5]; 15 | a2 = [1 7 16 12]; 16 | 17 | %% e 18 | [r2, p2] = residue(b2, a2); 19 | fprintf('r2 = \n'); disp(r2); 20 | fprintf('p2 = \n'); disp(p2); 21 | 22 | 23 | %% g 24 | b3 = -4; 25 | a3 = [1 0 -4]; 26 | 27 | %% h 28 | [r3, p3, k3] = residue(b3, a3); 29 | fprintf('r3 = \n'); disp(r3); 30 | fprintf('p3 = \n'); disp(p3); 31 | -------------------------------------------------------------------------------- /Assignment4/src/q4_6.m: -------------------------------------------------------------------------------- 1 | close('all'); clear; clc; 2 | 3 | load('ctftmod.mat'); 4 | 5 | %% a 6 | z = [dash dash dot dot]; 7 | 8 | figure; 9 | plot(t, z); grid('on'); 10 | title('z'); xlabel('t'); 11 | 12 | 13 | %% b 14 | [h, wout] = freqs(bf, af); 15 | 16 | figure; 17 | subplot(2,1,1); 18 | semilogx(wout, abs(h)); grid('on'); 19 | axis([xlim 0 1]); 20 | xlabel('\omega'); ylabel('Magnitude'); 21 | subplot(2,1,2); 22 | semilogx(wout, angle(h)); grid('on'); 23 | axis([xlim -pi pi]); 24 | xlabel('\omega'); ylabel('Phase'); 25 | 26 | 27 | %% c 28 | ydash = lsim(bf, af, dash, t(1:length(dash))); 29 | ydot = lsim(bf, af, dot, t(1:length(dot))); 30 | 31 | figure; 32 | subplot(2,1,1); 33 | plot(t(1:length(dash)), ydash, t(1:length(dash)), dash); grid('on'); 34 | xlabel('t'); ylabel('dash'); legend('filtered', 'original') 35 | subplot(2,1,2); 36 | plot(t(1:length(dot)), ydot, t(1:length(dot)), dot); grid('on'); 37 | xlabel('t'); ylabel('dot'); legend('filtered', 'original') 38 | 39 | 40 | %% d 41 | y = dash .* cos(2*pi*f1*t(1:length(dash))); 42 | yo = lsim(bf, af, y, t(1:length(dash))); 43 | 44 | figure; 45 | subplot(2,1,1); 46 | plot(t(1:length(dash)), yo); grid('on'); 47 | xlabel('t'); title('yo'); 48 | subplot(2,1,2); 49 | plot(t(1:length(dash)), yo, t(1:length(dash)), y); grid('on'); 50 | xlabel('t'); legend('yo', 'y'); 51 | 52 | 53 | %% f 54 | m1 = lsim(bf, af, x .* cos(2*pi*f1*t), t); 55 | 56 | figure; 57 | plot(t, m1); grid('on'); 58 | title('m_1'); xlabel('t'); 59 | 60 | 61 | %% g 62 | m2 = lsim(bf, af, x .* sin(2*pi*f2*t), t); 63 | m3 = lsim(bf, af, x .* sin(2*pi*f1*t), t); 64 | 65 | figure; 66 | subplot(2,1,1); 67 | plot(t, m2); grid('on'); 68 | title('m_2'); xlabel('t'); 69 | subplot(2,1,2); 70 | plot(t, m3); grid('on'); 71 | title('m_3'); xlabel('t'); 72 | -------------------------------------------------------------------------------- /Assignment5/src/a5_q1.m: -------------------------------------------------------------------------------- 1 | close('all'); clear; clc; 2 | 3 | %% load 4 | f_name = 'yuki_004627.ogg'; 5 | [y, fs] = audioread(strcat('./assets/', f_name)); 6 | y = (sum(y.') / 2).'; % merge track 7 | 8 | 9 | %% preview 10 | % sound(y, fs); 11 | 12 | t = linspace(0, length(y)/fs, length(y)); 13 | 14 | figure; 15 | plot(t, y); 16 | grid('on'); axis([t(1) t(end) ylim]); 17 | title(f_name, 'interpreter', 'none'); xlabel('t'); 18 | 19 | 20 | %% repeat signal 21 | sig = repmat(y, 10, 1); 22 | 23 | 24 | %% calc periodogram power spectral density 25 | [pxx, w] = periodogram(sig, [], 512, fs); 26 | 27 | figure; 28 | subplot(2, 1, 1); 29 | plot(w, 10*log10(pxx)); 30 | grid('on'); axis([w(1) w(end) ylim]); 31 | title('Periodogram of signal'); xlabel('\omega (Hz)'); ylabel('Power/Frequency (dB/Hz)'); 32 | subplot(2, 1, 2); 33 | plot(w, pxx); 34 | grid('on'); axis([w(1) w(end) ylim]); 35 | title('Periodogram of signal'); xlabel('\omega (Hz)'); ylabel('Power/Frequency'); 36 | 37 | 38 | %% fir2 39 | b = fir2(3000, w/(fs/2), sqrt(pxx/max(pxx))); 40 | [h, wh] = freqz(b, 1, 128); 41 | 42 | figure; 43 | subplot(2, 1, 1); 44 | plot(wh, 20*log10(abs(h))); 45 | grid('on'); axis([wh(1) wh(end) ylim]); 46 | title('Amplitude frequency response of filter'); xlabel('\omega'); ylabel('Amplitude (dB)'); 47 | subplot(2, 1, 2); 48 | plot(wh, abs(h)); 49 | grid('on'); axis([wh(1) wh(end) ylim]); 50 | title('Amplitude frequency response of filter'); xlabel('\omega'); ylabel('Amplitude'); 51 | 52 | 53 | %% noise generate 54 | noise = 1 - 2*rand(1, length(y)); 55 | 56 | [pxxn, wn] = periodogram(noise, [], 512, fs); 57 | 58 | figure; 59 | subplot(2, 1, 1); 60 | plot(wn, 10*log10(pxxn)); 61 | grid('on'); axis([wn(1) wn(end) ylim]); 62 | title('Periodogram of noise'); xlabel('\omega (Hz)'); ylabel('Power/Frequency (dB/Hz)'); 63 | subplot(2, 1, 2); 64 | plot(wn, pxxn); 65 | grid('on'); axis([wn(1) wn(end) ylim]); 66 | title('Periodogram of noise'); xlabel('\omega (Hz)'); ylabel('Power/Frequency'); 67 | 68 | 69 | %% apply filter 70 | y_n = filter(b, 1, noise); 71 | 72 | [pxxyn, wyn] = periodogram(y_n, [], 512, fs); 73 | 74 | figure; 75 | subplot(2, 1, 1); hold('on'); 76 | plot(wyn, 10*log10(pxxyn)); 77 | plot(w, 10*log10(pxx)); 78 | grid('on'); axis([wyn(1) wyn(end) ylim]); 79 | legend('noise', 'signal'); 80 | title('Periodogram'); xlabel('\omega (Hz)'); ylabel('Power/Frequency (dB/Hz)'); 81 | subplot(2, 1, 2); hold('on'); 82 | plot(wyn, pxxyn); 83 | plot(w, pxx); 84 | grid('on'); axis([wyn(1) wyn(end) ylim]); 85 | legend('noise', 'signal'); 86 | title('Periodogram'); xlabel('\omega (Hz)'); ylabel('Power/Frequency'); 87 | 88 | 89 | %% save SSN 90 | audiowrite('./assets/SSN.wav', y_n, fs); 91 | -------------------------------------------------------------------------------- /Assignment5/src/a5_q2.m: -------------------------------------------------------------------------------- 1 | close('all'); clear; clc; 2 | 3 | %% load 4 | f_name = 'yuki_004627.ogg'; 5 | [x, fs] = audioread(strcat('./assets/', f_name)); 6 | x = (sum(x.') / 2).'; % merge track 7 | 8 | SSN = audioread(strcat('./assets/SSN.wav')); 9 | 10 | 11 | %% add noise 12 | SNR = -5; 13 | syms('a', 'b'); 14 | [a, b] = solve( ... 15 | (a*norm(x)) / (b*norm(SSN)) == 10^(SNR/20), ... 16 | a^2*norm(x)^2 + 2*a*b*norm(x.*SSN) + b^2*norm(SSN)^2 == norm(x)^2 ... 17 | ); 18 | a = double(a(a>0)); 19 | b = double(b(b>0)); 20 | y = a*x + b*SSN; 21 | 22 | 23 | %% check 24 | fprintf('E_x=%.2f\n', norm(x)^2); 25 | fprintf('E_y=%.2f\n', norm(y)^2); 26 | fprintf('SNR=%.3f\n', 20*log10(norm(a*x)/norm(b*SSN))); 27 | 28 | 29 | %% preview 30 | % sound(y, fs); 31 | 32 | t = linspace(0, length(y)/fs, length(y)); 33 | [pyy, w] = periodogram(repmat(y, 10, 1), [], 512, fs); 34 | pxx = periodogram(repmat(x, 10, 1), [], 512, fs); 35 | 36 | figure; 37 | subplot(2, 1, 1); 38 | plot(t, y); 39 | grid('on'); axis([t(1) t(end) ylim]); 40 | title(sprintf('Signal add SSN, SNR=%d', SNR)); xlabel('t'); 41 | subplot(2, 1, 2); 42 | plot(w, 10*log10(pyy), w, 10*log10(pxx)); 43 | legend('orgin signal', 'signal with noise') 44 | grid('on'); axis([w(1) w(end) ylim]); 45 | title('Periodogram of signal'); xlabel('\omega (Hz)'); ylabel('Power/Frequency (dB/Hz)'); 46 | -------------------------------------------------------------------------------- /Assignment5/src/a5_q3.m: -------------------------------------------------------------------------------- 1 | close('all'); clear; clc; 2 | 3 | %% load 4 | f_name = 'yuki_004627.ogg'; 5 | [y, fs] = audioread(strcat('./assets/', f_name)); 6 | y = (sum(y.') / 2).'; % merge track 7 | t = linspace(0, length(y)/fs, length(y)); 8 | 9 | %% full wave rectification 10 | y = abs(y); 11 | 12 | %% change cutoff freq 13 | cutoff = [100, 200, 300]; 14 | figure; 15 | for i = 1:length(cutoff) 16 | subplot(length(cutoff), 1, i); 17 | plot(t, y, t, butterLPF(y, fs, 2, cutoff(i))); 18 | legend('orginal signal', 'envelope curve'); 19 | axis([t(1) t(end) ylim]); xlabel('t'); grid('on'); 20 | title(sprintf('Order: %d, Cutoff freq: %dHz', 3, cutoff(i))); 21 | end 22 | 23 | %% change order 24 | order = [2, 6]; 25 | figure; 26 | for i = 1:length(order) 27 | subplot(length(order), 1, i); 28 | plot(t, y, t, butterLPF(y, fs, order(i), 200)); 29 | legend('orginal signal', 'envelope curve'); 30 | axis([t(1) t(end) ylim]); xlabel('t'); grid('on'); 31 | title(sprintf('Order: %d, Cutoff freq: %dHz', order(i), 200)); 32 | end 33 | 34 | %% add on 35 | order = 1:2:10; 36 | figure; hold('on'); 37 | lege = repmat("", 1, length(order)); 38 | for i = 1:length(order) 39 | [b, a] = butter(order(i), 0.5); 40 | [h, w] = freqz(b, a); 41 | plot(w, abs(h)); 42 | lege(i) = sprintf('order=%d',order(i)); 43 | end 44 | legend(lege); xlabel('\omega'); ylabel('Amplitude'); 45 | grid('on'); axis([0 pi 0 1]); 46 | set(gca,'XTick', 0:pi/4:pi, 'XTickLabel',{'0','\pi/4','\pi/2','3\pi/4','\pi'}); 47 | -------------------------------------------------------------------------------- /Assignment5/src/assets/SSN.wav: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:5a48156fa6b73e3339f0dac0acc3a8670ebc4349f2a39b728f9afde09e19329d 3 | size 245498 4 | -------------------------------------------------------------------------------- /Assignment5/src/assets/yuki_004627.ogg: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:6e41127474941ef25cf5c2ef475d0a0dc8ca96e15397c884de27f122cf684d75 3 | size 26316 4 | -------------------------------------------------------------------------------- /Assignment5/src/butterLPF.m: -------------------------------------------------------------------------------- 1 | function y_f = butterLPF(y, fs, order, cutoff) 2 | [b, a] = butter(order, cutoff/(fs/2)); 3 | y_f = filter(b, a, y); 4 | end 5 | -------------------------------------------------------------------------------- /Assignment5/src/record.m: -------------------------------------------------------------------------------- 1 | close('all'); clear; clc; 2 | 3 | fs = 44100; nbits = 8; length = 5; 4 | % Record your voice for 5 seconds. 5 | recObj = audiorecorder(fs, nbits,1); 6 | disp('Start speaking.'); 7 | recordblocking(recObj, length); 8 | disp('End of Recording.'); 9 | % Play back the recording. 10 | play(recObj); 11 | % Store data in double-precision array 12 | myRecording = getaudiodata(recObj); 13 | subplot(2,1,1); plot(myRecording); % Plot the waveform 14 | 15 | audiowrite('./assets/my_voice.wav', myRecording, fs); 16 | 17 | [sigread, fsread] = audioread('./assets/my_voice.wav'); 18 | subplot(2,1,2); plot(sigread); % Plot the waveform. 19 | -------------------------------------------------------------------------------- /Project1/src/assets/C_01_01.wav: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:e817e0acd5d39ecdfa88f1c31b1bfbb7a171bd83151a90ba464b3d0460e10d2c 3 | size 104474 4 | -------------------------------------------------------------------------------- /Project1/src/assets/C_01_02.wav: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:9b524a0274345c90aeefd48718b7d74ac9901c6e8d48e6b840b63e94dc33a730 3 | size 59316 4 | -------------------------------------------------------------------------------- /Project1/src/assets/SSN.wav: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:5a48156fa6b73e3339f0dac0acc3a8670ebc4349f2a39b728f9afde09e19329d 3 | size 245498 4 | -------------------------------------------------------------------------------- /Project1/src/assets/yuki_004627.ogg: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:6e41127474941ef25cf5c2ef475d0a0dc8ca96e15397c884de27f122cf684d75 3 | size 26316 4 | -------------------------------------------------------------------------------- /Project1/src/base_full.m: -------------------------------------------------------------------------------- 1 | close('all'); clear; clc; 2 | 3 | %% basic para 4 | f_name = 'C_01_01.wav'; 5 | N = 64; 6 | butter_order = 4; 7 | env_cutoff = 100; 8 | 9 | %% load 10 | [y, fs] = audioread(strcat('./assets/', f_name)); 11 | t = linspace(0, length(y)/fs, length(y)); 12 | 13 | % figure; hold('on'); 14 | % plot(t, y); 15 | % axis([0 t(end) ylim]); grid('on'); 16 | 17 | %% split 18 | f0 = 200; 19 | f1 = 7000; 20 | f2d = @(f) log10(f/165.4 + 1) / 0.06; 21 | d2f = @(d) 165.4 * (10.^(0.06*d) - 1); 22 | 23 | d_range = linspace(f2d(f0), f2d(f1), N+1); 24 | f_range_l = d2f(d_range); 25 | f_range = [f_range_l(1:end-1); f_range_l(2:end)].'; 26 | f_mid = diff(f_range_l)/2 +f_range_l(1:end-1); 27 | 28 | %% init filter 29 | butters = zeros([2*butter_order+1 size(f_range)]); 30 | for i = 1:length(f_mid) 31 | [butters(:,i,1), butters(:,i,2)] = butter(butter_order, f_range(i,:)/(fs/2)); 32 | end 33 | 34 | figure; hold('on'); 35 | for i = 1:length(f_mid) 36 | [h, w] = freqz(butters(:,i,1), butters(:,i,2)); 37 | plot(w, abs(h)); 38 | end 39 | xlabel('\omega'); ylabel('Amplitude'); 40 | grid('on'); axis([0 pi 0 1]); 41 | set(gca, 'XTick', 0:pi/4:pi, 'XTickLabel', {'0','\pi/4','\pi/2','3\pi/4','\pi'}); 42 | 43 | %% band-pass 44 | y_f = zeros(length(y), length(f_mid)); 45 | for i = 1:length(f_mid) 46 | y_f(:,i) = filter(butters(:,i,1), butters(:,i,2), y); 47 | end 48 | 49 | % figure; hold('on'); 50 | % for i = 1:length(f_mid) 51 | % plot(t, y_f(:,i)); 52 | % end 53 | 54 | %% envelope 55 | y_f = abs(y_f); 56 | [LPF_b, LPF_a] = butter(butter_order, env_cutoff/(fs/2)); 57 | y_ff = filter(LPF_b, LPF_a, y_f); 58 | 59 | % figure; hold('on'); 60 | % for i = 1:length(f_mid) 61 | % plot(t, y_ff(:,i)); 62 | % end 63 | % axis([0 t(end) ylim]); grid('on'); 64 | 65 | %% freq shift 66 | y_ffe = zeros(size(y_ff)); 67 | for i = 1:length(f_mid) 68 | y_ffe(:,i) = sin(2*pi*f_mid(i)*t).' .* y_ff(:,i); 69 | end 70 | 71 | % figure; hold('on'); 72 | % for i = 1:length(f_mid) 73 | % plot(t, y_ffe(:,i)); 74 | % end 75 | 76 | %% summation 77 | y_s = sum(y_ffe, 2); 78 | y_s = y_s/norm(y_s)*norm(y); 79 | 80 | % figure; hold('on'); 81 | % plot(t, y_s, t, y); 82 | 83 | % sound(y_s, fs); 84 | -------------------------------------------------------------------------------- /Project1/src/proj_1.m: -------------------------------------------------------------------------------- 1 | close('all'); clear; clc; 2 | 3 | %% load & init 4 | f_name = 'C_01_01.wav'; 5 | [y, fs] = audioread(strcat('./assets/', f_name)); 6 | t = linspace(0, length(y)/fs, length(y)); 7 | 8 | is_save = false; 9 | is_plot = true; 10 | 11 | %% task-1 12 | env_cutoff = 50; 13 | N_pool = [1, 2, 4, 6, 8]; 14 | 15 | if is_plot 16 | figure; 17 | n = 0; 18 | end 19 | for N = N_pool 20 | x = tone_vocoder(y, fs, N, env_cutoff); 21 | if is_save 22 | audiowrite(sprintf('./results/%s_T1_TVC_%d_%d.wav', f_name, N, env_cutoff), x, fs); 23 | end 24 | if is_plot 25 | n = n + 1; 26 | subplot(length(N_pool), 1, n); 27 | plot(t, x); axis([0 t(end) ylim]); 28 | % plot((-length(y)/2:(length(y)/2-1))*(fs/length(y)), fftshift(abs(fft(x)))); 29 | title(sprintf('T1_TVC_%d_%d', N, env_cutoff), 'Interpreter', 'none'); 30 | end 31 | end 32 | error; 33 | 34 | %% task-2 35 | env_cutoff_pool = [20, 50, 100, 400]; 36 | N = 4; 37 | 38 | if is_plot 39 | figure; 40 | n = 0; 41 | end 42 | for env_cutoff = env_cutoff_pool 43 | x = tone_vocoder(y, fs, N, env_cutoff); 44 | if is_save 45 | audiowrite(sprintf('./results/%s_T2_TVC_%d_%d.wav', f_name, N, env_cutoff), x, fs); 46 | end 47 | if is_plot 48 | n = n + 1; 49 | subplot(length(env_cutoff_pool), 1, n); 50 | plot(t, x); axis([0 t(end) ylim]); 51 | title(sprintf('T2_TVC_%d_%d', N, env_cutoff), 'Interpreter', 'none'); 52 | end 53 | end 54 | 55 | 56 | %% ssn+y 57 | y_ssn = ssn_gen(y, fs, -5); 58 | if is_save 59 | audiowrite(sprintf('./results/%s_SSN.wav', f_name), x, fs); 60 | end 61 | 62 | 63 | %% task-3 64 | 65 | env_cutoff = 50; 66 | N_pool = [2, 4, 6, 8, 16]; 67 | 68 | if is_plot 69 | figure; 70 | n = 0; 71 | end 72 | for N = N_pool 73 | x = tone_vocoder(y_ssn, fs, N, env_cutoff); 74 | if is_save 75 | audiowrite(sprintf('./results/%s_T3_SSN_TVC_%d_%d.wav', f_name, N, env_cutoff), x, fs); 76 | end 77 | if is_plot 78 | n = n + 1; 79 | subplot(length(N_pool), 1, n); 80 | plot(t, x); axis([0 t(end) ylim]); 81 | title(sprintf('T3_SSN_TVC_%d_%d', N, env_cutoff), 'Interpreter', 'none'); 82 | end 83 | end 84 | 85 | 86 | %% task-4 87 | env_cutoff_pool = [20, 50, 100, 400]; 88 | N = 6; 89 | 90 | if is_plot 91 | figure; 92 | n = 0; 93 | end 94 | for env_cutoff = env_cutoff_pool 95 | x = tone_vocoder(y_ssn, fs, N, env_cutoff); 96 | if is_save 97 | audiowrite(sprintf('./results/%s_T4_SSN_TVC_%d_%d.wav', f_name, N, env_cutoff), x, fs); 98 | end 99 | if is_plot 100 | n = n + 1; 101 | subplot(length(env_cutoff_pool), 1, n); 102 | plot(t, x); axis([0 t(end) ylim]); 103 | title(sprintf('T4_SSN_TVC_%d_%d', N, env_cutoff), 'Interpreter', 'none'); 104 | end 105 | end 106 | -------------------------------------------------------------------------------- /Project1/src/results/C_01_01.wav_SSN.wav: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:1396c2488456e25f1e45bd7db560a40608c914ad9d066623317bc679cdb752d4 3 | size 104474 4 | -------------------------------------------------------------------------------- /Project1/src/results/C_01_01.wav_T1_TVC_1_50.wav: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:d38e9d1c7f886f2b7c8313655ae812688b46830634b7ea0db61714b6c56bc81e 3 | size 104474 4 | -------------------------------------------------------------------------------- /Project1/src/results/C_01_01.wav_T1_TVC_2_50.wav: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:8eb6f59e335c8af5db121b01bd10fad1be3be67d952e7baa4fd48dc3a645e6b6 3 | size 104474 4 | -------------------------------------------------------------------------------- /Project1/src/results/C_01_01.wav_T1_TVC_4_50.wav: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:e8a6ba07b9532f5f5573b77a463aeaf197b659c65d50a3e89f72629a3eb3dcfe 3 | size 104474 4 | -------------------------------------------------------------------------------- /Project1/src/results/C_01_01.wav_T1_TVC_6_50.wav: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:554926536c976c8a178b769ddb5fa7a90b84ce8b90ea560f15dca3fa5b8f6bfa 3 | size 104474 4 | -------------------------------------------------------------------------------- /Project1/src/results/C_01_01.wav_T1_TVC_8_50.wav: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:e59e217a49d660fe4a22957541ffbe3577d7aa108a3173cb1f91e17e1cae850d 3 | size 104474 4 | -------------------------------------------------------------------------------- /Project1/src/results/C_01_01.wav_T2_TVC_4_100.wav: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:81a65a1769513482073663e2a76f0635ab7a280d0010fd60b137787918a33e33 3 | size 104474 4 | -------------------------------------------------------------------------------- /Project1/src/results/C_01_01.wav_T2_TVC_4_20.wav: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:15a1569731e63c53fa9d34777e1ec08404596b09381dc14b163cd43bc4c0e8d3 3 | size 104474 4 | -------------------------------------------------------------------------------- /Project1/src/results/C_01_01.wav_T2_TVC_4_400.wav: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:7cbc624b626ac7ddc28da9e8ffaa340ff65d1d4ebf18181ec3887c7116555487 3 | size 104474 4 | -------------------------------------------------------------------------------- /Project1/src/results/C_01_01.wav_T2_TVC_4_50.wav: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:e8a6ba07b9532f5f5573b77a463aeaf197b659c65d50a3e89f72629a3eb3dcfe 3 | size 104474 4 | -------------------------------------------------------------------------------- /Project1/src/results/C_01_01.wav_T3_SSN_TVC_16_50.wav: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:729a082629fe2883c1416e16f1e4b241b053f5eb82e6e8793b014a385d985327 3 | size 104474 4 | -------------------------------------------------------------------------------- /Project1/src/results/C_01_01.wav_T3_SSN_TVC_2_50.wav: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:0c5779cee8948f22fcb4f7aa1a96b183ef17866b04d6ae0c34467f02f59a6a3f 3 | size 104474 4 | -------------------------------------------------------------------------------- /Project1/src/results/C_01_01.wav_T3_SSN_TVC_4_50.wav: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:118f8bfc7ecfdb1134b3bce20c61aa34de0c8374f65f942ea43a92eebe108463 3 | size 104474 4 | -------------------------------------------------------------------------------- /Project1/src/results/C_01_01.wav_T3_SSN_TVC_6_50.wav: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:71cbf6612789eb0c5b7ff5e958027de32471855780496fe29c013b7f56912b85 3 | size 104474 4 | -------------------------------------------------------------------------------- /Project1/src/results/C_01_01.wav_T3_SSN_TVC_8_50.wav: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:38e8a76727cbc155157c69bb4c1a7a57a9d273319fe4520418a9d5362c68956f 3 | size 104474 4 | -------------------------------------------------------------------------------- /Project1/src/results/C_01_01.wav_T4_SSN_TVC_6_100.wav: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:3b17c6a19404891c51313852c5d5b7dc5a00b009a602d945b45b87c06d41577d 3 | size 104474 4 | -------------------------------------------------------------------------------- /Project1/src/results/C_01_01.wav_T4_SSN_TVC_6_20.wav: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:5979fdcbb2d7e233994f1f7c9cb63147096d3a8e0965712a3d434f760e835ade 3 | size 104474 4 | -------------------------------------------------------------------------------- /Project1/src/results/C_01_01.wav_T4_SSN_TVC_6_400.wav: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:0af6126718856ce12db8b105b520e331a2a6295ff2cbc037d1a73bee797bc06f 3 | size 104474 4 | -------------------------------------------------------------------------------- /Project1/src/results/C_01_01.wav_T4_SSN_TVC_6_50.wav: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:71cbf6612789eb0c5b7ff5e958027de32471855780496fe29c013b7f56912b85 3 | size 104474 4 | -------------------------------------------------------------------------------- /Project1/src/ssn_gen.m: -------------------------------------------------------------------------------- 1 | function x = ssn_gen(y, fs, SNR) 2 | switch nargin 3 | case 2 4 | SNR = -5; 5 | case 3 6 | otherwise 7 | error('Wrong nargins'); 8 | end 9 | if size(y, 1) < size(y, 2) 10 | y = y.'; 11 | end 12 | if size(y, 2) ~= 1 13 | y = sum(y, 2); 14 | end 15 | 16 | [pxx, w] = periodogram(repmat(y, 10, 1), [], 512, fs); 17 | SSN = filter(fir2(3000, w/(fs/2), sqrt(pxx/max(pxx))), 1, 1 - 2*rand(1, length(y))).'; 18 | x = 10^(SNR/20)*norm(SSN)/norm(y) * y + SSN; 19 | x = x / norm(x) * norm(y); 20 | end 21 | -------------------------------------------------------------------------------- /Project1/src/test.m: -------------------------------------------------------------------------------- 1 | clc; clear; 2 | 3 | [pxx, w] = periodogram(repmat(y, 10, 1), [], 512, fs); 4 | [pxx2, w2] = periodogram(repmat(y_ssn, 10, 1), [], 512, fs); 5 | 6 | figure; 7 | plot(w, 10*log10(pxx), w2, 10*log10(pxx2)) 8 | title('Periodogram of signal'); xlabel('Frequency (Hz)'); ylabel('Power/Frequency (dB/Hz)'); 9 | grid('on'); legend('y', 'y\_ssn') 10 | -------------------------------------------------------------------------------- /Project1/src/tone_vocoder.m: -------------------------------------------------------------------------------- 1 | function x = tone_vocoder(y, fs, N, env_cutoff, butter_order, f0, f1) 2 | switch nargin 3 | case 2 4 | N = 64; env_cutoff = 100; butter_order = 4; f0 = 200; f1 = 7000; 5 | case 3 6 | env_cutoff = 100; butter_order = 4; f0 = 200; f1 = 7000; 7 | case 4 8 | butter_order = 4; f0 = 200; f1 = 7000; 9 | case 5 10 | f0 = 200; f1 = 7000; 11 | case 7 12 | otherwise 13 | error('Wrong nargins'); 14 | end 15 | if size(y, 1) < size(y, 2) 16 | y = y.'; 17 | end 18 | if size(y, 2) ~= 1 19 | y = sum(y, 2); 20 | end 21 | 22 | f2d = @(f) log10(f/165.4 + 1) / 0.06; 23 | d2f = @(d) 165.4 * (10.^(0.06*d) - 1); 24 | 25 | d_range = linspace(f2d(f0), f2d(f1), N+1); 26 | f_range_l = d2f(d_range); 27 | f_range = [f_range_l(1:end-1); f_range_l(2:end)].'; 28 | f_mid = diff(f_range_l)/2 +f_range_l(1:end-1); 29 | 30 | x = zeros(size(y)); 31 | [LPF_b, LPF_a] = butter(butter_order, env_cutoff/(fs/2)); 32 | t = linspace(0, length(y)/fs, length(y)); 33 | for i = 1:length(f_mid) 34 | [BPF_b, BPF_a] = butter(butter_order, f_range(i,:)/(fs/2)); 35 | x = x + sin(2*pi*f_mid(i)*t).' .* filter(LPF_b, LPF_a, abs(filter(BPF_b, BPF_a, y))); 36 | end 37 | 38 | x = x / norm(x) * norm(y); 39 | end 40 | -------------------------------------------------------------------------------- /Project2/src/ADC_LPF.m: -------------------------------------------------------------------------------- 1 | 2 | %% 3 | res = reshape(repmat(X_r_adc, T*fs, 1), 1, []); 4 | t_res = linspace(0, length(res)/fs - 1/fs, length(res)); 5 | 6 | figure; 7 | plot(t_res, real(res), t_res, imag(res)); 8 | axis([0 t_res(end) ylim]); grid('on'); 9 | xlabel('t (s)'); ylabel('X[n]'); 10 | legend('real', 'image'); title('DAC'); 11 | 12 | %% 13 | h_n = [ones(1, T*fs) zeros(1, T*fs)]; 14 | figure; 15 | plot(abs(fftshift(fft(h_n)))); 16 | -------------------------------------------------------------------------------- /Project2/src/LPF.mat: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:bf9387df43d4205f15e0c4c6fd102fc4b9fa8a9ddaa90b137e64731af2d93283 3 | size 77436403 4 | -------------------------------------------------------------------------------- /Project2/src/LPF2.mat: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:08fff3d00c63d6437a77eafb173a083ca2cb8cdd653a7a6e5c117d37d3afa80d 3 | size 776019 4 | -------------------------------------------------------------------------------- /Project2/src/LPF3.mat: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:c41f3a8f0e856901d7f009d734d69546462c553ac40f7f2897b2026eee6eb4b1 3 | size 6956873 4 | -------------------------------------------------------------------------------- /Project2/src/OFDM.m: -------------------------------------------------------------------------------- 1 | function y = OFDM(x, CP, T, w_c, fs, cutoff, isFig, pilot, useH) 2 | if nargin == 0 3 | close('all'); 4 | x = rand(1, 32); CP = 16; T = 1e-6; w_c = 100e6; fs = 1e9; 5 | cutoff=0.02; isFig=true; pilot = 1; useH = false; 6 | elseif nargin == 5 7 | cutoff=0.02; isFig=true; pilot = 0; useH = false; 8 | end 9 | 10 | %% iFFT / iDFT 11 | X = ifft(x); 12 | 13 | %% add CP 14 | X_CP = [X(end-CP+1:end) X]; 15 | 16 | if useH 17 | h_n = [0.5 0.2 0.375 0.475]; 18 | X_r_adc = conv(X_CP, h_n); 19 | else 20 | %% DAC 21 | X_c = reshape(repmat(X_CP, T*fs, 1), 1, []); 22 | t_X_c = linspace(0, length(X_c)/fs - 1/fs, length(X_c)); % non-integer end 23 | 24 | %% modulation 25 | X_cos = real(X_c) .* cos(w_c*t_X_c); 26 | X_sin = imag(X_c) .* sin(w_c*t_X_c); 27 | X_m = X_cos + X_sin; 28 | 29 | %% transfer 30 | h_n = [0.5 zeros(1, 1.5*T*fs-1) 0.4 zeros(1, 1*T*fs-1) 0.35 zeros(1, 0.5*T*fs-1) 0.3]; 31 | X_t = conv(X_m, h_n); 32 | t_X_t = linspace(0, length(X_t)/fs - 1/fs, length(X_t)); 33 | 34 | %% demodulation 35 | if cutoff < 0 36 | X_r_d = 2 * iLPF(X_t .* cos(w_c*t_X_t), -cutoff) + 2j * iLPF(X_t .* sin(w_c*t_X_t), -cutoff); 37 | else 38 | [b, a] = butter(5, cutoff, 'low'); 39 | X_r_d = 2 * filter(b, a, X_t .* cos(w_c*t_X_t)) + 2j * filter(b, a, X_t .* sin(w_c*t_X_t)); 40 | end 41 | 42 | 43 | %% ADC 44 | X_r_adc = mean(reshape(X_r_d, T*fs, length(X_r_d)/T/fs)); 45 | end 46 | 47 | %% remove CP 48 | X_rCP = X_r_adc((CP+1):(CP+length(x))); 49 | 50 | %% FFT / DFT 51 | y = abs(fft(X_rCP)); 52 | 53 | if pilot == 0 54 | return 55 | end 56 | 57 | %% calc H 58 | if pilot == 1 59 | pilot = ones(1, length(x)); 60 | elseif pilot == 2 61 | pilot = randn(1, length(x)); 62 | end 63 | 64 | pilot_OFDM = OFDM(pilot, CP, T, w_c, fs, cutoff, false, 0, useH); 65 | H_k = pilot ./ pilot_OFDM / length(pilot); 66 | 67 | %% de-gain 68 | y = y .* H_k .* length(y); 69 | 70 | 71 | %% figures 72 | if isFig 73 | figure; hold('on'); 74 | stem(0:(length(x)-1), x); 75 | axis([-1 length(x) ylim]); grid('on'); xlabel('n'); 76 | title('signal'); 77 | 78 | figure; hold('on'); 79 | stem(0:(length(X_CP)-1), real(X_CP)); stem(0:(length(X_CP)-1), imag(X_CP)); 80 | axis([-1 length(X_CP) ylim]); grid('on'); 81 | line([CP-0.5, CP-0.5], [100, -100], 'Color', 'magenta'); 82 | xlabel('n'); ylabel('x[n]'); 83 | legend('real', 'image'); title('Add CP'); 84 | 85 | if useH 86 | figure; 87 | stem(0:(length(h_n)-1), h_n); 88 | axis([-0.25 length(h_n)-0.25 ylim]); grid('on'); 89 | xlabel('n'); ylabel('h[n]'); 90 | title('h'); 91 | else 92 | figure; 93 | plot(t_X_c, real(X_c), t_X_c, imag(X_c)); 94 | axis([0 t_X_c(end) ylim]); grid('on'); 95 | xlabel('t (s)'); ylabel('X[n]'); 96 | legend('real', 'image'); title('DAC'); 97 | 98 | figure; hold('on'); 99 | plot(t_X_c, X_cos, t_X_c, X_sin); 100 | axis([0 t_X_c(end) ylim]); grid('on'); 101 | xlabel('t (s)'); ylabel('X(t)'); 102 | legend('x\_cos', 'x\_sin'); title('modulation'); 103 | 104 | figure; hold('on'); 105 | plot(t_X_c, X_m); 106 | axis([0 t_X_c(end) ylim]); grid('on'); 107 | xlabel('t (s)'); ylabel('X(t)'); 108 | title('summation'); 109 | 110 | figure; 111 | plot(linspace(0, 3*T, 3*T*fs+1), h_n, 'r'); 112 | axis([0 3*T ylim]); grid('on'); 113 | xlabel('t (s)'); ylabel('h(t)') 114 | title('Channel'); 115 | 116 | figure; 117 | plot(t_X_t, X_t); 118 | axis([0 t_X_t(end) ylim]); grid('on'); 119 | xlabel('t (s)'); ylabel('X(t)'); 120 | title('transfer'); 121 | 122 | figure; 123 | plot(t_X_t, real(X_r_d), t_X_t, imag(X_r_d)); 124 | axis([0 t_X_t(end) ylim]); grid('on'); 125 | xlabel('t (s)'); ylabel('X(t)'); 126 | legend('real', 'image'); title('demodulation'); 127 | 128 | figure; hold('on'); 129 | stem(0:(length(X_r_adc)-1), real(X_r_adc)); stem(0:(length(X_r_adc)-1), imag(X_r_adc)); 130 | axis([-1 length(X_r_adc) ylim]); grid('on'); 131 | xlabel('n'); ylabel('X[n]'); 132 | legend('real', 'image'); title('ADC'); 133 | end 134 | 135 | figure; hold('on'); 136 | stem(0:(length(X_rCP)-1), real(X_rCP)); stem(0:(length(X_rCP)-1), imag(X_rCP)); 137 | axis([-1 length(X_rCP) ylim]); grid('on'); 138 | xlabel('n'); ylabel('X(t)'); 139 | legend('real', 'image'); title('remove CP'); 140 | 141 | figure; 142 | stem(0:(length(H_k)-1), H_k); 143 | axis([-1 length(H_k) ylim]); grid('on'); 144 | xlabel('k'); ylabel('H[k]'); 145 | title('H'); 146 | 147 | figure; hold('on'); 148 | diff = norm(x - y) .^ 2; 149 | stem(0:(length(x)-1), x); stem(0:(length(y)-1), y, '*'); 150 | axis([-1 length(x) ylim]); grid('on'); xlabel('n'); 151 | grid('on'); legend('x', 'y'); xlabel('n'); 152 | title(sprintf('Variance = %d', diff)); 153 | 154 | y = {y, diff}; 155 | end 156 | end 157 | 158 | -------------------------------------------------------------------------------- /Project2/src/OFDM_full.m: -------------------------------------------------------------------------------- 1 | close('all'); clear(); clc(); 2 | 3 | x = rand(1, 32); 4 | load matlab.mat 5 | CP = 3; 6 | T = 1e-6; 7 | w_c = 100e6; 8 | fs = 1e9; 9 | cutoff = 0.02; 10 | isFig = true; 11 | pilot = 1; 12 | useH = true; 13 | 14 | 15 | %% iFFT / iDFT 16 | X = ifft(x); 17 | 18 | %% add CP 19 | X_CP = [X(end-CP+1:end) X]; 20 | 21 | if useH 22 | h_n = [0.5 0.2 0.375 0.475]; 23 | X_r_adc = conv(X_CP, h_n); 24 | else 25 | %% DAC 26 | X_c = reshape(repmat(X_CP, T*fs, 1), 1, []); 27 | t_X_c = linspace(0, length(X_c)/fs - 1/fs, length(X_c)); % non-integer end 28 | 29 | %% modulation 30 | X_cos = real(X_c) .* cos(w_c*t_X_c); 31 | X_sin = imag(X_c) .* sin(w_c*t_X_c); 32 | X_m = X_cos + X_sin; 33 | 34 | %% transfer 35 | h_n = [0.5 zeros(1, 1.5*T*fs-1) 0.4 zeros(1, 1*T*fs-1) 0.35 zeros(1, 0.5*T*fs-1) 0.3]; 36 | X_t = conv(X_m, h_n); 37 | t_X_t = linspace(0, length(X_t)/fs - 1/fs, length(X_t)); 38 | 39 | %% demodulation 40 | if cutoff < 0 41 | X_r_d = 2 * iLPF(X_t .* cos(w_c*t_X_t), -cutoff) + 2j * iLPF(X_t .* sin(w_c*t_X_t), -cutoff); 42 | else 43 | [b, a] = butter(5, cutoff, 'low'); 44 | X_r_d = 2 * filter(b, a, X_t .* cos(w_c*t_X_t)) + 2j * filter(b, a, X_t .* sin(w_c*t_X_t)); 45 | end 46 | 47 | 48 | %% ADC 49 | X_r_adc = mean(reshape(X_r_d, T*fs, length(X_r_d)/T/fs)); 50 | end 51 | 52 | %% remove CP 53 | X_rCP = X_r_adc((CP+1):(CP+length(x))); 54 | 55 | %% FFT / DFT 56 | y = abs(fft(X_rCP)); 57 | 58 | if pilot == 0 59 | return 60 | end 61 | 62 | %% calc H 63 | if pilot == 1 64 | pilot = ones(1, length(x)); 65 | elseif pilot == 2 66 | pilot = rand(1, length(x)); 67 | end 68 | 69 | pilot_OFDM = OFDM(pilot, CP, T, w_c, fs, cutoff, false, 0, useH); 70 | H_k = pilot ./ pilot_OFDM / length(pilot); 71 | 72 | %% de-gain 73 | y = y .* H_k .* length(y); 74 | 75 | 76 | %% figures 77 | if isFig 78 | figure; hold('on'); 79 | stem(0:(length(x)-1), x); 80 | axis([-1 length(x) ylim]); grid('on'); xlabel('n'); 81 | title('signal'); 82 | 83 | figure; hold('on'); 84 | stem(0:(length(X_CP)-1), real(X_CP)); stem(0:(length(X_CP)-1), imag(X_CP)); 85 | axis([-1 length(X_CP) ylim]); grid('on'); 86 | line([CP-0.5, CP-0.5], [100, -100], 'Color', 'magenta'); 87 | xlabel('n'); ylabel('x[n]'); 88 | legend('real', 'image'); title('Add CP'); 89 | 90 | if useH 91 | figure; 92 | stem(0:(length(h_n)-1), h_n); 93 | axis([-0.25 length(h_n)-0.25 ylim]); grid('on'); 94 | xlabel('n'); ylabel('h[n]'); 95 | title('h'); 96 | else 97 | figure; 98 | plot(t_X_c, real(X_c), t_X_c, imag(X_c)); 99 | axis([0 t_X_c(end) ylim]); grid('on'); 100 | xlabel('t (s)'); ylabel('X[n]'); 101 | legend('real', 'image'); title('DAC'); 102 | 103 | figure; hold('on'); 104 | plot(t_X_c, X_cos, t_X_c, X_sin); 105 | axis([0 t_X_c(end) ylim]); grid('on'); 106 | xlabel('t (s)'); ylabel('X(t)'); 107 | legend('x\_cos', 'x\_sin'); title('modulation'); 108 | 109 | figure; hold('on'); 110 | plot(t_X_c, X_m); 111 | axis([0 t_X_c(end) ylim]); grid('on'); 112 | xlabel('t (s)'); ylabel('X(t)'); 113 | title('summation'); 114 | 115 | figure; 116 | plot(linspace(0, 3*T, 3*T*fs+1), h_n, 'r'); 117 | axis([0 3*T ylim]); grid('on'); 118 | xlabel('t (s)'); ylabel('h(t)') 119 | title('Channel'); 120 | 121 | figure; 122 | plot(t_X_t, X_t); 123 | axis([0 t_X_t(end) ylim]); grid('on'); 124 | xlabel('t (s)'); ylabel('X(t)'); 125 | title('transfer'); 126 | 127 | figure; 128 | plot(t_X_t, real(X_r_d), t_X_t, imag(X_r_d)); 129 | axis([0 t_X_t(end) ylim]); grid('on'); 130 | xlabel('t (s)'); ylabel('X(t)'); 131 | legend('real', 'image'); title('demodulation'); 132 | 133 | figure; hold('on'); 134 | stem(0:(length(X_r_adc)-1), real(X_r_adc)); stem(0:(length(X_r_adc)-1), imag(X_r_adc)); 135 | axis([-1 length(X_r_adc) ylim]); grid('on'); 136 | line([CP-0.5, CP-0.5], [100, -100], 'Color', 'magenta'); 137 | line([CP+length(x)-0.5, CP++length(x)-0.5], [100, -100], 'Color', 'magenta'); 138 | xlabel('n'); ylabel('X[n]'); 139 | legend('real', 'image'); title('ADC'); 140 | end 141 | 142 | figure; hold('on'); 143 | stem(0:(length(X_rCP)-1), real(X_rCP)); stem(0:(length(X_rCP)-1), imag(X_rCP)); 144 | axis([-1 length(X_rCP) ylim]); grid('on'); 145 | xlabel('n'); ylabel('X[n]'); 146 | legend('real', 'image'); title('remove CP'); 147 | 148 | figure; 149 | stem(0:(length(H_k)-1), H_k); 150 | axis([-1 length(H_k) ylim]); grid('on'); 151 | xlabel('k'); ylabel('H[k]'); 152 | title('H'); 153 | 154 | figure; hold('on'); 155 | diff = norm(x - y) .^ 2; 156 | stem(0:(length(x)-1), x); stem(0:(length(y)-1), y, '*'); 157 | axis([-1 length(x) ylim]); grid('on'); xlabel('n'); 158 | grid('on'); legend('x', 'y'); xlabel('n'); 159 | title(sprintf('Variance = %d', diff)); 160 | end 161 | -------------------------------------------------------------------------------- /Project2/src/addon.m: -------------------------------------------------------------------------------- 1 | figure; hold('on'); 2 | stem(0:(length(x)-1), real(ifft(x))); stem(0:(length(x)-1), imag(ifft(x))); 3 | axis([-1 length(x) ylim]); grid('on'); xlabel('n'); 4 | title('signal'); 5 | 6 | 7 | figure; 8 | plot(t_X_c, X_cos + X_sin); 9 | axis([0 t_X_c(end) ylim]); grid('on'); 10 | xlabel('t (s)'); ylabel('X(t)'); 11 | legend('x\_cos', 'x\_sin'); title('modulation'); 12 | 13 | 14 | figure; hold('on'); 15 | plot(linspace(-fs/2+1, fs/2, length(X_t)), abs(fftshift(fft(X_t)))); 16 | grid('on'); axis([-4e7, 4e7, ylim]); xlabel('Frequency (Hz)'); 17 | 18 | 19 | figure; hold('on'); 20 | plot(linspace(-fs/2+1, fs/2, length(X_t)), abs(fftshift(fft(X_t .* cos(w_c*t_X_t))))); 21 | plot(linspace(-fs/2+1, fs/2, length(X_t)), abs(fftshift(fft(filter(b, a, X_t .* cos(w_c*t_X_t))))), 'r:'); 22 | grid('on'); axis([-4e7, 4e7, ylim]); xlabel('Frequency (Hz)'); 23 | 24 | ww = linspace(-fs/2+1, fs/2, length(X_m)); 25 | figure; hold('on'); 26 | plot(ww, abs(fftshift(fft(X_m)))); 27 | axis([ww(1) ww(end) ylim]); 28 | % line([w_c/2/pi, w_c/2/pi], [1e4, 0], 'Color', 'magenta'); 29 | % line([-w_c/2/pi, -w_c/2/pi], [1e4, 0], 'Color', 'magenta'); 30 | grid('on'); xlabel('Frequency (Hz)'); 31 | title('FT of modulated signal'); 32 | 33 | 34 | ww2 = linspace(-fs/2, fs/2-1, length(X_c)); 35 | figure; hold('on'); 36 | plot(ww, abs(fftshift(fft(X_c)))); 37 | axis([ww(1) ww(end) ylim]); 38 | grid('on'); xlabel('Frequency (Hz)'); 39 | title('FT of modulated signal'); 40 | -------------------------------------------------------------------------------- /Project2/src/calcH.m: -------------------------------------------------------------------------------- 1 | close('all'); clear; clc; 2 | 3 | N = 32; 4 | CP = 3; 5 | T = 1e-6; 6 | w_c = 100e6; 7 | fs = 1e9; 8 | 9 | h_n = [0.5 zeros(1, 1.5*T*fs-1) 0.4 zeros(1, 1*T*fs-1) 0.35 zeros(1, 0.5*T*fs-1) 0.3]; 10 | 11 | amp_h = h_n>0; 12 | 13 | h_n_t = [h_n zeros(1, T*fs)]; 14 | 15 | for i = 1:length(amp_h) 16 | if amp_h(i) > 0 17 | h_n_t((i+1):(i+T*fs-1)) = h_n_t((i+1):(i+T*fs-1)) + h_n(i); 18 | end 19 | end 20 | 21 | h_n_t(end) = []; 22 | 23 | t = linspace(0, length(h_n_t)/fs - 1/fs, length(h_n_t)); 24 | figure; 25 | plot(t, h_n_t, linspace(0, length(h_n)/fs - 1/fs, length(h_n)), h_n, 'r'); 26 | grid('on'); 27 | axis([t(1) t(end) ylim]); 28 | legend('h_t(t)', 'h(t)'); 29 | xlabel('t (s)'); 30 | 31 | HH = mean(reshape(h_n_t, T*fs, length(h_n_t)/T/fs)); 32 | figure; stem(HH); -------------------------------------------------------------------------------- /Project2/src/calcH2.m: -------------------------------------------------------------------------------- 1 | close('all'); clear; clc; 2 | 3 | N = 32; 4 | CP = 3; 5 | T = 1e-6; 6 | w_c = 100e6; 7 | fs = 1e9; 8 | cutoff = 0.02; 9 | 10 | x = zeros(1,32); 11 | 12 | X_CP = [1 zeros(1, N-1)]; 13 | X_c = reshape(repmat(X_CP, T*fs, 1), 1, []); 14 | t_X_c = linspace(0, length(X_c)/fs - 1/fs, length(X_c)); % non-integer end 15 | 16 | X_cos = real(X_c) .* cos(w_c*t_X_c); 17 | X_sin = imag(X_c) .* sin(w_c*t_X_c); 18 | X_m = X_cos + X_sin; 19 | 20 | h_n = [0.5 zeros(1, 1.5*T*fs-1) 0.4 zeros(1, 1*T*fs-1) 0.35 zeros(1, 0.5*T*fs-1) 0.3]; 21 | X_t = conv(X_m, h_n); 22 | t_X_t = linspace(0, length(X_t)/fs - 1/fs, length(X_t)); 23 | 24 | [b, a] = butter(5, cutoff, 'low'); 25 | X_r_d = 2 * filter(b, a, X_t .* cos(w_c*t_X_t)) + 2j * filter(b, a, X_t .* sin(w_c*t_X_t)); 26 | 27 | X_r_adc = mean(reshape(X_r_d, T*fs, length(X_r_d)/T/fs)); 28 | 29 | figure; hold('on'); 30 | plot(t_X_c, X_cos, t_X_c, X_sin); 31 | axis([0 t_X_c(end) ylim]); grid('on'); 32 | xlabel('t (s)'); ylabel('X(t)'); 33 | legend('x\_cos', 'x\_sin'); title('modulation'); 34 | 35 | figure; hold('on'); 36 | plot(t_X_c, X_m); 37 | axis([0 t_X_c(end) ylim]); grid('on'); 38 | xlabel('t (s)'); ylabel('X(t)'); 39 | title('summation'); 40 | 41 | figure; 42 | plot(t_X_t, X_t); 43 | axis([0 t_X_t(end) ylim]); grid('on'); 44 | xlabel('t (s)'); ylabel('X(t)'); 45 | title('transfer'); 46 | 47 | figure; 48 | plot(t_X_t, real(X_r_d), t_X_t, imag(X_r_d)); 49 | axis([0 t_X_t(end) ylim]); grid('on'); 50 | xlabel('t (s)'); ylabel('X(t)'); 51 | legend('real', 'image'); title('demodulation'); 52 | 53 | figure; 54 | plot(t_X_t, abs(X_r_d)); 55 | axis([0 4.5e-6 ylim]); grid('on'); 56 | xlabel('t (s)'); ylabel('X(t)'); 57 | title('demodulation'); 58 | 59 | figure; hold('on'); 60 | stem(0:(length(X_r_adc)-1), abs(X_r_adc)); 61 | axis([-0.25 4.25 ylim]); 62 | set(gca, 'XTick', 0:4, 'XTickLabel', {'0', '1', '2', '3', '4'}); 63 | grid('on'); 64 | xlabel('n'); ylabel('X[n]'); 65 | title('ADC'); 66 | -------------------------------------------------------------------------------- /Project2/src/calcH3.m: -------------------------------------------------------------------------------- 1 | close('all'); clear; clc; 2 | 3 | N = 32; 4 | CP = 3; 5 | T = 1e-6; 6 | w_c = 100e6; 7 | fs = 1e9; 8 | cutoff = 0.02; 9 | 10 | X_m = ones(1,T*fs); 11 | 12 | h_n = [0.5 zeros(1, 1.5*T*fs-1) 0.4 zeros(1, 1*T*fs-1) 0.35 zeros(1, 0.5*T*fs-1) 0.3]; 13 | X_t = conv(X_m, h_n); 14 | t_X_t = linspace(0, length(X_t)/fs - 1/fs, length(X_t)); 15 | 16 | figure; 17 | plot(t_X_t, X_t); 18 | axis([0 t_X_t(end) ylim]); grid('on'); 19 | xlabel('t (s)'); ylabel('X(t)'); 20 | title('transfer'); 21 | -------------------------------------------------------------------------------- /Project2/src/disscus_CP.m: -------------------------------------------------------------------------------- 1 | close('all'); clear(); clc(); 2 | 3 | N = 32; 4 | CP = 0; 5 | T = 1e-6; 6 | w_c = 100e6; 7 | fs = 1e9; 8 | 9 | data = zeros(32, 100); 10 | 11 | for i = 1:32 12 | CP = i; 13 | for j = 1:100 14 | x = rand(1, N); 15 | y = OFDM(x, CP, T, w_c, fs, 0.02, false, 1, false); 16 | data(i, j) = norm(x - y) .^ 2; 17 | end 18 | end 19 | 20 | data = data.'; 21 | m = mean(data); 22 | v = var(data); 23 | %% 24 | 25 | figure; 26 | errorbar(m(1:3), v(1:3), 'o-'); 27 | set(gca, 'XTick', 1:3, 'XTickLabel', {'1', '2', '3'}); 28 | axis([0.5 3.5 ylim]); 29 | grid('on'); 30 | xlabel('CP length'); ylabel('Variance') 31 | -------------------------------------------------------------------------------- /Project2/src/disscus_LPF.m: -------------------------------------------------------------------------------- 1 | close('all'); clear(); clc(); 2 | 3 | N = 32; 4 | CP = 3; 5 | T = 1e-6; 6 | w_c = 100e6; 7 | fs = 1e9; 8 | 9 | % freq_pool = 0:1e3:w_c; 10 | freq_pool = 1e5:1e6:10*w_c; 11 | % freq_pool(1) = 1; 12 | data = zeros(length(freq_pool), 100); 13 | 14 | for i = 1:length(freq_pool) 15 | for j = 1:100 16 | x = rand(1, N); 17 | y = OFDM(x, CP, T, w_c, fs, -freq_pool(i)/pi/fs, false, 1, false); 18 | data(i, j) = norm(x - y) .^ 2; 19 | end 20 | disp(freq_pool(i)); 21 | end 22 | 23 | data = data.'; 24 | m = mean(data); 25 | v = var(data); 26 | %% 27 | 28 | figure; 29 | semilogy(freq_pool, m, '-'); 30 | % set(gca, 'XTick', 1:3, 'XTickLabel', {'1', '2', '3'}); 31 | % axis([0.5 3.5 ylim]); 32 | grid('on'); 33 | xlabel('Cutoff (rad/s)'); ylabel('Variance'); 34 | title('ideal LPF'); 35 | -------------------------------------------------------------------------------- /Project2/src/iLPF.m: -------------------------------------------------------------------------------- 1 | function y = iLPF(x, cutoff) 2 | x_fft = fft(x); 3 | x_fft(round(length(x)*cutoff/2):(end-round(length(x)*cutoff/2-1))) = 0; 4 | % plot(abs(fftshift(x_fft))); 5 | y = ifft(x_fft); 6 | end 7 | -------------------------------------------------------------------------------- /Project2/src/iLPF.mat: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:d675137ec540415417da309605505f93f1793a1dc5b02fbb530f992ff4225bc6 3 | size 773847 4 | -------------------------------------------------------------------------------- /Project2/src/main.m: -------------------------------------------------------------------------------- 1 | close('all'); clear(); clc(); 2 | 3 | %% data def 4 | load matlab.mat 5 | N = 32; 6 | CP = 3; 7 | T = 1e-6; 8 | w_c = 100e6; 9 | fs = 1e9; 10 | cutoff = -1; 11 | 12 | % x = rand(1, N); 13 | 14 | 15 | 16 | %% OFDM 17 | y = OFDM(x, CP, T, w_c, fs, cutoff, true, 1, false); 18 | -------------------------------------------------------------------------------- /Project2/src/matlab.mat: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:62ba7ae1ef2672d7f7a8ef9eeff38c438a4afd249c64f881cf90e5efc9a86803 3 | size 5984 4 | -------------------------------------------------------------------------------- /Project2/src/total.mat: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:8d499f85ec20aed0f6fca1e1b72e822361e694e15124773d94bcbaa0beeb4c5c 3 | size 167119359 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Signals and Systems Lab Assignments 2 | 3 | SUSTech EE205 4 | 5 | by Lapluis --------------------------------------------------------------------------------