




下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、這是我搜集整理的一個關(guān)于卷積編碼和Viterbi譯碼的Matlab程序,現(xiàn)在把它們放在這里,希望對需要的人有些幫助。卷積編碼程序:function output, len_tal = cnv_encd(secrettext, encodetext)g = 0 0 1 0 0 1 0 0; 0 0 0 0 0 0 0 1; 1 0 0 0 0 0 0 1; 0 1 0 0 1 1 0 1;k0 = 1;% 讀入文本文件并計算文件長度frr = fopen(secrettext, r);msg, len = fread(frr, ubit1);msg = msg;% check to see if
2、 extra zero padding is necessaryif rem(length(msg), k0) 0 msg = msg, zeros(size(1:k0-rem(length(msg),k0);endn = length(msg)/k0; % 把輸入比特按k0分組,n為所得的組數(shù)。% check the size of matrix gif rem(size(g, 2), k0) 0 error(Error, g is not of the right size.);end% determine L and n0L = size(g, 2)/k0;n0 = size(g, 1)
3、;% add extra zeros,以保證編碼器是從全0開始,并回到全0狀態(tài)。u = zeros(size(1:(L-1)*k0), msg, zeros(size(1:(L-1)*k0);% generate uu, a matrix whose columns are the contents of conv. encoder at% various clock cycles.u1 = u(L*k0: -1 :1);for i = 1:n+L-2 u1 = u1, u(i+L)*k0:-1:i*k0+1);enduu = reshape(u1, L*k0, n+L-1);% determ
4、ine the outputoutput = reshape(rem(g*uu, 2), 1, n0*(L+n-1);len_tal = n0*(L + n - 1);% write the output to the encodetextresult = fopen(encodetext, w);for i = 1:n0*(L+n -1) fwrite(result, output(i), bit1);endfclose(result);Viterbi譯碼程序:function decoder_output, survivor_state, cumulated_metric = viterb
5、i(channel_output, decodetext)ticG= 0 0 1 0 0 1 0 0; 0 0 0 0 0 0 0 1; 1 0 0 0 0 0 0 1; 0 1 0 0 1 1 0 1;k = 1;frr = fopen(channel_output, r);msg, len = fread(frr, ubit1);channel_output = msg;n = size(G,1);% check the sizesif rem(size(G, 2), k) = 0 error(channel_output not of the right size);endL = siz
6、e(G, 2)/k;number_of_states = 2(L-1)*k);% generate state transition matrix, output matrix, and input matrixfor j = 0:number_of_states - 1 for i = 0:2k-1 next_state, memory_contents = nxt_stat(j,i, L, k); input(j+1, next_state + 1) = i; branch_output = rem(memory_contents*G, 2); nextstate(j+1, i+1) =
7、next_state; output(j+1, i+1) = bin2deci(branch_output); endend% add the extra zero, ensure the length of channel_output is integral% times to n.if rem(len, n)0 channel_output = channel_output, zeros(size(n-rem(len, n):-1:1);endstate_metric = zeros(number_of_states, 2);depth_of_trellis = length(chann
8、el_output)/n;channel_output_matrix = reshape(channel_output, n, depth_of_trellis);survivor_state = zeros(number_of_states, depth_of_trellis + 1);% start decoding of non-tail channel outputsfor i = 1:depth_of_trellis-L+1 flag = zeros(1, number_of_states); if i state_metric(j+1,1). + branch_metric) |
9、flag(nextstate(j+1, l+1) + 1) = 0) state_metric(nextstate(j+1,l+1)+1, 2) = state_metric(j+1, 1) + branch_metric; suvivor_state(nextstate(j+1,l+1) + 1, i+1) = j; flag(nextstate(j+1, l+1) + 1) = 1; end end end state_metric = state_metric(:, 2:-1:1);end% start decoding of the tail channel-outputsfor i
10、= depth_of_trellis - L + 2:depth_of_trellis flag = zeros(1, number_of_states); last_stop = number_of_states/(2(i - depth_of_trellis+L-2)*k); for j = 0:last_stop - 1 branch_metric = 0; binary_output = deci2bin(output(j + 1, 1), n); for r = 1:n branch_metric = branch_metric + metric(channel_output_mat
11、rix(r, i), binary_output(r); end if(state_metric(nextstate(j+1, l+1) + 1, 2)state_metric(j+1,1). + branch_metric) | flag(nextstate(j+1, 1) + 1) = 0) state_metric(nextstate(j+1,1)+1, 2) = state_metric(j+1, 1) + branch_metric; suvivor_state(nextstate(j+1,1) + 1, i+1) = j; flag(nextstate(j+1, 1) + 1) =
12、 1; end end state_metric = state_metric(:, 2:-1:1);end% generate the decode output from the optimal pathstate_sequence = zeros(1, depth_of_trellis + 1);state_sequence(1, depth_of_trellis) = survivor_state(1, depth_of_trellis+1);for i = 1:depth_of_trellis state_sequence(1, depth_of_trellis-i+1) = suv
13、ivor_state(state_sequence(1, depth_of_trellis+2-i). +1), depth_of_trellis - i+2);enddecoder_output_matrix = zeros(k, depth_of_trellis -L+1);for i = 1:depth_of_trellis - L + 1 dec_output_deci = input(state_sequence(1, i)+1, state_sequence(1, i+1)+1); dec_output_bin = deci2bin(dec_output_deci, k); dec
14、oder_output_matrix(:,i) = dec_output_bin(k:-1:1);enddecoder_output = reshape(decoder_output_matrix, 1, k*(depth_of_trellis-L+1);cumulated_metric = state_metric(1, 1);% write the output to the encodetextresult = fopen(decodetext, w);for i = 1:k*(depth_of_trellis-L+1) fwrite(result, decoder_output(i),
15、 bit1);endfclose(result);toc%*%function distance = metric(x,y)if x = y distance = 0;else distance = 1;end%*%function next_state, memory_contents = nxt_stat(current_state, input, L, k)binary_state = deci2bin(current_state, k*(L-1);binary_input = deci2bin(input, k);next_state_binary = binary_input, binary_state(1:(L-2)*k);next_state = bin2deci(next_state_bina
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 信息技術(shù)2.0語文組語言表達(dá)訓(xùn)練計劃
- 2025年養(yǎng)老護(hù)理醫(yī)院融合計劃
- 室內(nèi)空氣消毒84消毒液配比流程
- 礦業(yè)開采項(xiàng)目風(fēng)險管理計劃
- 模具快速開發(fā)與制作流程
- 文化創(chuàng)意孵化器內(nèi)設(shè)機(jī)構(gòu)職責(zé)
- 遠(yuǎn)程信息技術(shù)培訓(xùn)心得體會
- 中小學(xué)教師職業(yè)行為規(guī)范及安全管理心得體會
- 貨幣鑒別鑒定管理辦法
- 播州渣土揚(yáng)塵管理辦法
- 青少年去極端化安全教育宣傳
- AI賦能與素養(yǎng)導(dǎo)向:初中英語智慧課堂的融合實(shí)踐研究
- 樣品打樣合同協(xié)議
- 構(gòu)建中藥材種植標(biāo)準(zhǔn)化模式
- 2023年荊門市城市建設(shè)投資控股集團(tuán)有限公司人才招聘【23人】筆試參考題庫附帶答案詳解
- 《2025年危險化學(xué)品企業(yè)安全生產(chǎn)執(zhí)法檢查重點(diǎn)事項(xiàng)指導(dǎo)目錄》解讀與培訓(xùn)
- 心腦血管疾病創(chuàng)新藥物研究-全面剖析
- 2025年03月四川成都農(nóng)業(yè)科技中心公開招聘筆試歷年典型考題(歷年真題考點(diǎn))解題思路附帶答案詳解
- 《2025年CSCO非小細(xì)胞癌診療指南》解讀
- 能源管理規(guī)定
- 人工水磨鉆勞務(wù)合同標(biāo)準(zhǔn)文本
評論
0/150
提交評論