###### tags: `2021Ankang` # 安康進度 ## 11/18 安康會議 * 統一講 CFO, PHO,不要一人講PHO另一人講CPO,會造成誤解 * 投影片中需強調 atdma OQPSK 已整合,才不會讓人誤以為沒整合 # 11/17 ## test 10 s data ![](https://i.imgur.com/PV6nmIm.png) ## test 0.1s data ![](https://i.imgur.com/MQ6qTQJ.png) ![](https://i.imgur.com/2eoQBjn.png) ![](https://i.imgur.com/ZA0p4OL.png) ![](https://i.imgur.com/3bb6InV.png) ## test 0.8s data ![](https://i.imgur.com/LTWkCLr.png) ![](https://i.imgur.com/ULRl3nW.png) ![](https://i.imgur.com/navpxCb.png) ![](https://i.imgur.com/0Qr25R4.png) # 11/11 紀錄 P. 1 期中報告->期末報告 P.3 上半年度->改成全年 P.5 成果交付項目 —> 要再加上期末報告書 p.13 "根據 sepc定義 "==> "sepc"改成 "spec" p.17 "IPONIT" "IPIONT" --> 是否應為 "IPOINT"? p. 30 "Butter filter" --> "Butterworth filter" p. 35 "IPONIT", "IPIONT" --> 是否應為 "IPOINT"? p.43~p.44: "好像有一頁多打?”那頁好像跳掉了?” P. 16 可否畫圓一點 P.18 可否加一些文字描述尋到burst的peaks P.41 理想值怎麼算? p.47 Data conversion is done in 56 —> 也許不用強調(根本不用講)I/O (data conversion)的部分 -會再試一下 overlapadd method,可能可以改程式的寫法讓速度變快 -看能不能再減少CFOPHOTO estimation中用的迴圈 or 可能可以用較少點數去做match filter。(根據目前找到的cfo pho,看不出有規律) # 11/10 ![](https://i.imgur.com/i3wuGX1.png) ![](https://i.imgur.com/BuRnad5.png) ![](https://i.imgur.com/G4r06AM.png) ![](https://i.imgur.com/dnre99y.png) ![](https://i.imgur.com/FbvogXj.png) # 11/9 晚上 ![](https://i.imgur.com/S8vFh3j.png) 剛剛發現CFOPHOTO_estimator中的迴圈數可再大幅精簡, 在我的mac上處理 0.1(sec) data 的時間由2.3(sec)減少至0.66(s) ![](https://i.imgur.com/YocYBRS.jpg) ![](https://i.imgur.com/L4G6E2h.jpg) ![](https://i.imgur.com/aLZYPUD.jpg) ![](https://i.imgur.com/UdQczVk.png) ![](https://i.imgur.com/qJVuqVJ.png) ![](https://i.imgur.com/iGNE3fj.png) # 11/9 下午 1. 減少CFOPHOTO_estimator中的迴圈 2. 將fftw and overlap add method 套用到安康code,但**目前用了overlap add method 後沒有比較快** 3. 目前在 HJS Lab computer時間 0.1s的資料從上禮拜的3.5 所減至 2.58(sec) ## 減少CFOPHOTO_estimator中的迴圈 ### matlab 在 CFOPHOTO_estimator 中多加入判別 ![](https://i.imgur.com/U6PzIjN.png) 有此機制的時間: ![](https://i.imgur.com/VSu3gUu.png =60%x) 無此機制的時間: ![](https://i.imgur.com/zesBDnX.png =60%x) ### C++ 有此機制的時間: ![](https://i.imgur.com/mqibPF0.png =60%x) 無此機制的時間: ![](https://i.imgur.com/XMJv44H.png =60%x) ## fftw without overlapadd method * The following simulation compute `y1 = filter(conj(q(end : -1 : 1)), 1, r)` where `q` and `r` are all complex number length( r ) = 532480 length( q ) = 858 * Simulation environment ![](https://i.imgur.com/UAMjJPd.png =20%x) * ![](https://i.imgur.com/OKxgaRn.png =60%x) * result ![](https://i.imgur.com/DWUfvfe.png =50%x) ## fftw with overlapadd method * Simulation environment ![](https://i.imgur.com/UAMjJPd.png =20%x) * method ![](https://i.imgur.com/TIxT2QP.png) ![](https://i.imgur.com/jzLEkJD.png) ![](https://i.imgur.com/OWLOC4q.png) ![](https://i.imgur.com/0enFibW.png) ![](https://i.imgur.com/cE0B1q7.png) L = 900; % block size ![](https://i.imgur.com/3fwkaaw.png =70%x) ## 目前在 HJS Lab computer時間 0.1s的資料跑 2.58(sec) ![](https://i.imgur.com/fSdsWBO.png) ![](https://i.imgur.com/ZVTQa7L.png) ![](https://i.imgur.com/W4AsaHR.png) ![](https://i.imgur.com/EPSKXYz.png) # 11/5 可成功在Ankang code上執行 overlap add method problem: Lb太小時會segmentation fault ![](https://i.imgur.com/fTX6rsE.png) # 11/4 ## 安康會議討論 11/11 9:00(線上):以預報形式報告 11/18 9:00(線上):期末審查預報(聽說會有長官來看) 11/25 9:00(線上or實體,中心還在討論) 關於real time,中心說原則上希望real time,但主要訴求還是希望C執行的結果是正確的(因為我提到精確度跟執行時間上有trade off) * 在HJS lab computer用平行化處理看看時間能否壓低 * 看能否減少CFOPHOTO_estimator中的迴圈數=>減少conplex convolution的次數 * 用 overlap add method 看是否能加速(已經能在simple case上處理,但套到安康code時,目前遇到segmentation fault的問題,還在處理) ## 減少CFOPHOTO_estimator中的迴圈 ### matlab 在 CFOPHOTO_estimator 中多加入判別 ![](https://i.imgur.com/A1tEe7a.png =70%x) 有此機制的時間: ![](https://i.imgur.com/VSu3gUu.png =60%x) 無此機制的時間: ![](https://i.imgur.com/zesBDnX.png =60%x) ### C++ 有此機制的時間: ![](https://i.imgur.com/5lI4wXX.png =60%x) 無此機制的時間: ![](https://i.imgur.com/XMJv44H.png =60%x) # 11/3 ## 將resample的half-sided window length點數由6點調整為1點 * Simulation environment ![](https://i.imgur.com/UAMjJPd.png =20%x) * Sampling frequency: 6.25M Hz * Test with 1M samples(約為0.1s的data) * All process is done in 5.124441(sec) * There are 22 bursts in total. ![](https://i.imgur.com/zesBDnX.png =60%x) ![](https://i.imgur.com/0iuv9PV.png =80%x) ![](https://i.imgur.com/aa5JkZ2.png =70%x) ![](https://i.imgur.com/Uzf00s9.png =70%x) ![](https://i.imgur.com/7heTQJc.png =70%x) ![](https://i.imgur.com/1qyUGn7.png =80%x) ## Matlab ### overlap add method * Finish overlap add method matlab code: * 但目前用overlap add method時間並沒有執行比較快,請見下方模擬 ![](https://i.imgur.com/QGnuWQK.png =60%x) ![](https://i.imgur.com/onXYSII.png =60%x) ![](https://i.imgur.com/RtjDVC4.png =60%x) ![](https://i.imgur.com/YWQPtQ8.png =60%x) **with matlab** ### convolution without overlap add method * Test with the data in "coarseTO_estimator" * Simulation environment ![](https://i.imgur.com/UAMjJPd.png =20%x) ![](https://i.imgur.com/x7OeWSj.png =70%x) **result** ![](https://i.imgur.com/NAxnX5f.png =60%x) ### convolution with overlap add method * Test with the data in "coarseTO_estimator" * Simulation environment ![](https://i.imgur.com/UAMjJPd.png =20%x) ![](https://i.imgur.com/oxLJPzc.png =70%x) **result** ![](https://i.imgur.com/YKa4JH6.png =60%x) **with C** ### convolution without overlap add method * Test with the data in "coarseTO_estimator" * Simulation environment ![](https://i.imgur.com/UAMjJPd.png =20%x) ![](https://i.imgur.com/OKxgaRn.png =60%x) **result** ![](https://i.imgur.com/DWUfvfe.png =50%x) ## C ### Hjs Lab Computer * 成功在蘇炫榮老師lab電腦上使用fftw並執行程式 * 目前0.1s的data需跑3.5s,請見下方模擬 * Simulation environment ![](https://i.imgur.com/JvCMZAU.png =50%x) * Sampling frequency: 6.25M Hz * Test with 1.25M samples (相當於0.1s的訊號) 因為訊號為complex(包含實虛部data),所以需取 6.25M*2= 12.5M samples才為1s的data * All process is done in 3.5(sec)[1.25M samples, 0.1s data]: 0.1s的data需跑3.5s * There are 26 bursts in total. ![](https://i.imgur.com/YR7mhfk.png) ![](https://i.imgur.com/IjPKZZG.png) ![](https://i.imgur.com/MYgxq7F.png) ![](https://i.imgur.com/73h3M5p.png) # 11/2 ## Matlab * Simulation environment ![](https://i.imgur.com/UAMjJPd.png =20%x) * Sampling frequency: 6.25M Hz * Test with 1M samples(約為0.1s的data) * All process is done in 13.081393(sec) * There are 22 bursts in total. ![](https://i.imgur.com/eZNOS6I.png) ![](https://i.imgur.com/TafhAdw.png) ![](https://i.imgur.com/vTUjbAn.png) ![](https://i.imgur.com/7YCpwio.png) ## C * Simulation environment ![](https://i.imgur.com/UAMjJPd.png =20%x) ### Test1 * Sampling frequency: 6.25M Hz * **Test with 1M samples**(約為0.1s的data) * All process is done in 3.516641(sec) * There are 22 bursts in total. ![](https://i.imgur.com/H4rPOIj.png) ![](https://i.imgur.com/MKgsGyc.png) ![](https://i.imgur.com/VAxOLJ2.png) ![](https://i.imgur.com/pkQKpPS.jpg) ![](https://i.imgur.com/EEyrPST.png) ### Test2 * Sampling frequency: 6.25M Hz * **Test with 6.25M samples** * All process is done in 19.895152(sec) * There are 120 bursts in total. Here just show a few of them. ![](https://i.imgur.com/JZgkGNh.png) ![](https://i.imgur.com/9LqHMMO.png =70%x) p.s. * 實驗室電腦:Simulation environment ![](https://i.imgur.com/x6qh7Xg.png =40%x) # 10/30 ```問題已解決``` 單一個迴圈demapping皆正確,但是跑大於一個burst後,demapping的值跑掉 跟cfo, pho, to estimation無關,估計的值已經很準 應該是記憶體的問題 發現兩個迴圈後,syncSig.size() = 0, 不知為何 迴圈外正常 cout << "L_syncSig" << L_syncSig << "\n"; // 858 cout << "syncSig_I.size()" << syncSig_I.size() << "\n"; //858 迴圈內 cout << "L_syncSig" << L_syncSig << "\n"; // 858 cout << "syncSig_I.size()" << syncSig_I.size() << "\n"; //0 346 行 syncSig_I.clear(); syncSig_Q.clear();不可clear掉因為迴圈中會用 但是 目前不clear & clear都有問題 # 10/28 安康會議紀錄: * 完成SNR calculation, Symbol Error Rate計算 * 把訊號實際時間算出來 (也就是real-time可以處理的時間上限) * 把處理的總時間 (1.16 sec, or 9.xxx sec) break down to 6 + 22 * 5 = 116 個時間,使得這116個時間加起來剛好等於總時間。如有需要,可以不事先print出來 * resample的部分可以考慮用 fftw來加速 * CFOPHOTO_estimator的 convolution,可以考慮用 overlap-add來加速 * 繼續維持 system block diagram 的呈現,使各項討論可以依照該diagram為中心來進行。 # 10/27 ## C coding 技巧: * ./d > test1.log 可以將由./d 執行檔執行出來的結果寫進.log檔中 * cat test1.log 可以在終端機上印出 test1.log 的值 * commmand + "/": slash => 加斜線 * 在viscode中,ctrl + F + match case + march whole world * 養成好習慣:要用之前再allocate記憶體,用完之後馬上free 若用 fftw_alloc_complex(L)須補零 q = fftw_alloc_complex(Lz); for(int i = 0; i < L_q; i++){ q[i][0] = p_flip_I[i]; q[i][1] = - p_flip_Q[i]; // conj(q(end : -1 : 1) } for(int i = L_q; i < Lz; i++){ q[i][0] = 0; q[i][1] = 0; } p_flip_I.clear(); p_flip_Q.clear(); //conj_p_flip_Q.clear(); p1 = fftw_plan_dft_1d(Lz, q, q_fft, FFTW_FORWARD, FFTW_ESTIMATE);// |FFTW_PRESERVE_INPUT); fftw_execute(p1); fftw_free(q); # 10/26 * Github: [Ankang_OQPSK_C Github](https://github.com/WaitingLinComm/Ankang_OQPSK_C/tree/main/OQPSK_1026) * [Ankang OQPSK Data 雲端連結](https://drive.google.com/drive/folders/1ty3S6nbTjD6RyVTkCJUxPCkhLBuK7SIt?usp=sharing) p.s.因為data太大上傳不了github main.cpp 使用第一個burst做測試 可解出正確的 cfo_hat, pho_hat, d 可demapping出正確的symbol **problem:** 若直接讀取CFOPHOTO_estimator前的matlab資料,由CFOPHOTO_estimator ,可以解出正確的 cfo_hat, pho_hat, d,如下 ![](https://i.imgur.com/vsEJpx4.png =20%x) 但將所有block結合時,每次找出的cfo_hat, pho_hat, d值不同(有時正確有時錯誤),如下(有確認輸入CFOPHOTO_estimator的值無誤),感覺是記憶體配置的問題,但我試了很久還是無解 ![](https://i.imgur.com/UUrwWrm.png =80%x) # 10/21 ![](https://imgur.com/undefined.png) ## Problem 用fftw執行一次convolution時,結果正確。但在迴圈中用fftw執行多次convolution,只有第一次的convolution結果正確。 後來發現問題應該是跟fftw記憶體配置相關,但我目前無法解決。 * 在我matlab code的 `CFOPHOTO_estimator` 中,會使用到iteration多次的convolution,所以需要處理這個問題 * 轉成C++時,我原以為是我程式打錯,但卡了很久才發現問題的根源是:在迴圈中用 fftw 的問題,請見下方的測試 ## 以matlab測試下方程式 ``` x = [1 + 1*j 2 + 2*j]; y = [3 + 3*j 5 + 4*j]; for i = 1:3 conv(x,y) end ``` 結果(正確): ![](https://i.imgur.com/ckXt9vX.png =40%x) --- ## 以fftw測試 請參照 [我的 Github](https://github.com/WaitingLinComm/Ankang_OQPSK_C.git)中的 ./fft_iteration/test_easy_conv_iteration.cpp 結果(只有第一個iteration正確): ![](https://imgur.com/DW8iGEb.png =50%x) 後來發現repeated calls to fft by using fftw3 would crash. 以下連結中也有人遇到類似問題 [Link1](http://computer-programming-forum.com/49-fortran/d2086ddd612b7596.htm) [Link2](https://stackoverflow.com/questions/29761096/errors-with-repeated-fftw-calls) [Link3](https://www.796t.com/post/NmdiYw==.html ) ## 我的嘗試: ### Try1 (成功) [我的 Github](https://github.com/WaitingLinComm/Ankang_OQPSK_C.git)中的 ./fft_iteration/test_fft_iteration.cpp 我在每個迴圈中都計算相同的fft,每個迴圈印出的值都正確 發現: * `fftw_plan p` 和 `fftw_destroy_plan(p)` 須放在迴圈外,否則會出現只有前幾次iteration值才正確 * 不能每個迴圈都執行 `fftw_free(out)` ,否則會出現只有前幾次iteration值才正確,最後一個迴圈再執行一次`fftw_free(out)` 才不會有問題 * 可以每個迴圈都執行 `fftw_free(in)`,結果正確 ### Try2 (失敗) [我的 Github](https://github.com/WaitingLinComm/Ankang_OQPSK_C.git)中的 ./fft_iteration/test_easy_conv_iteration.cpp 我在每個迴圈中都計算相同的convolution,只有前幾次iteration值才正確 **經過多方嘗試,仍無法正確執行** ### Try3(失敗) 在 `fftw_execute` 前後印出q ![](https://i.imgur.com/n4OkGQ3.png =30%x) 在 `fftw_execute` 前後印出fft(q, 3) ![](https://i.imgur.com/0XAZ2wq.png =30%x) **情況與try2類似,只有第一次是正確的** 我嘗試 q = x = [1+1j 2+2j]長度為2,但想要做 三點 fft,怕後面的亂數導致影響,所以我將第三點 補0 ![](https://i.imgur.com/0njaBJL.png =30%x) 算fft後變成這樣(似乎不受亂數影響,但是值差一點點就對了): ![](https://i.imgur.com/vBkMZc4.png =30%x) # 10/19 (問題已解決) ## Easy case for fftw3 implementation Do fft of a complex vector The result is correct. The following code do: fft([1+i*1, 2+i*2], 4) ``` #include <stdio.h> #include <fftw3.h> int main() { int N = 4; int i; fftw_complex *in, *out; fftw_plan p; in = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * N); out = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * N); // The input vector is [1+i*1, 2+i*2, 0, 0] in matlab language in[0][0] = 1; in[0][1] = 1; in[1][0] = 2; in[1][1] = 2; // forward Fourier transform p = fftw_plan_dft_1d(N, in, out, FFTW_FORWARD, FFTW_ESTIMATE); fftw_execute(p); /*repeat as needed */ for (i = 0; i < N; i++) printf("[%d]: %f + j*%f\n", i, out[i][0], out[i][1]); fftw_destroy_plan(p); fftw_free(in); fftw_free(out); return 0; } ``` ## 安康signal **Problem**: 用fftw3 算出來的值,與用matlab算出來的值的不一樣,每個用fftw3 算出來的值與matlab的值皆差 0. 多,算出來的 two norm =419910922(與matlab的值比對) **目前不知道為什麼會有數值誤差** from matlab: ![](https://i.imgur.com/RAyXSd2.png) from C++: ![](https://i.imgur.com/0wA915Q.png =40%x) 下方為C++部分程式碼: * 實現 fft(r, 533337) * 下方主要執行步驟中有註解出所花費的時間 ``` int Lz; Lz = 533337;//L_r + L_q - 1; // realize r_fft = fft(r, Lz); fftw_complex *r; fftw_complex *r_fft; int P = Lz; // P point fft r = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * P); r_fft = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * P); for(int i = 0; i < SigLength_afterResample; i++){ r[i][0] = Sig_I[i]; r[i][1] = Sig_Q[i]; } //0.02155(sec) fftw_plan p; p = fftw_plan_dft_1d(P, r, r_fft, FFTW_FORWARD, FFTW_ESTIMATE); //0.006094(sec) fftw_execute(p); //0.021995(sec) fftw_destroy_plan(p); //0.000133(sec) fftw_free(r); for (int i = 0; i < 10; i++){ printf("[%d]: %f + j*%f\n", i, r_fft[i][0], r_fft[i][1]); } ``` # 20210719 進度紀錄 ![](https://i.imgur.com/UeB3vdh.png) 1. 整理先前在所學到的通訊系統相關概念,並整合在前幾個禮拜中由OQPSK中所學到的概念 * 筆記如下 a. Signal Space https://drive.google.com/file/d/1UD45pfMJ_amEbNL7qY_FHUoljbpTpcBg/view?usp=sharing b. PAM Tx/Rx, Nyquist criterion, ISI free, Raised Cosine filter, Squared Root Raised Cosine filter, matched filter design https://drive.google.com/file/d/1a3O6G27rLFuFuQvEjyR20CYq3ebbUfcq/view?usp=sharing 2. 重寫程式中的Resample function(先前的code寫得很亂),並理解matlab parfor的用法 * 筆記如下 https://drive.google.com/file/d/1T-N1UCQcRBSXB0KbBvkOHdeRtjEWRd44/view?usp=sharing 進一步做法請參照目錄欄中的 Processing and Resample 小節 下方筆記中所提到的window size,我是先取window size = 6 ![](https://i.imgur.com/tpxp9qi.png) 3. 有關安康待做事項第四項 SNR, SER curve * 完成QPSK, MPSK 錯誤率的相關推導 The following note includes SNR estimation, QPSK 錯誤率分析, M-ary 系統錯誤率分析, MPSK 錯誤率分析 https://drive.google.com/file/d/198nE3-7yUe_Pk4_SSx2LsNkir4BIXdb6/view?usp=sharing * 問題: 用pilot估計$N_0$時, ![](https://i.imgur.com/fjfB4dX.png) 若使用上方筆記的sol1,結果如下 ![](https://i.imgur.com/4Aitrow.png =50%x) 若使用上方筆記sol2,結果如下 ![](https://i.imgur.com/8isVzai.png =50%x) 我覺得sol2的做法蠻合理,但似乎用sol1的結果比較正確,我不太確定究竟sol1, sol2哪個方法是對的(老師先前說sol1的方法與sol2的方法是等效的) 4. 有關安康待做事項第三項 Blind estimation of CFO/PHO/TO 目前我所列出的最佳化問題如下,不知是否合理 ![](https://i.imgur.com/BnNoZDn.png) 5. 當資料取多一些後,星座圖點還蠻亂的,可能會影響後續解出bit的結果,感覺很需要用Blind estimation of CFO/PHO/TO 模擬如下: number of used data: 1e6 f_c= -338745; ![](https://i.imgur.com/C40eYIw.png) number of used data: 2e6 f_c= -338745; ![](https://i.imgur.com/Zkl6bA7.png)