




下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、精選優(yōu)質(zhì)文檔-傾情為你奉上這是我搜集整理的一個關(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;% ch
2、eck to see if 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
3、 = size(g, 1);% 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+
4、L-1);% determine 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_me
5、tric = viterbi(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 siz
6、e);endL = size(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
7、(j+1, i+1) = 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 =
8、 length(channel_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). + bran
9、ch_metric) | 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-
10、outputsfor i = 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(chann
11、el_output_matrix(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
12、+1, 1) + 1) = 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_trell
13、is-i+1) = suvivor_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_
14、deci, k); decoder_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, decod
15、er_output(i), 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_binary);mem
溫馨提示
- 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)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- DB14-T 3355-2025 設(shè)施蔬菜高溫悶棚技術(shù)規(guī)程
- 餐飲業(yè)股份合作投資合同樣本
- Brand KPIs for neobanking Next in Brazil-英文培訓(xùn)課件2025.4
- 標(biāo)準(zhǔn)房地產(chǎn)抵押合同(35篇)
- 2025年心理測量學(xué)基礎(chǔ)知識測驗試題及答案
- 構(gòu)建初中語文文學(xué)閱讀學(xué)習(xí)任務(wù)群的統(tǒng)合性思考
- 餐廳經(jīng)理勞動合同范本:保密條款與知識產(chǎn)權(quán)
- 餐飲品牌加盟店租賃及經(jīng)營合作協(xié)議
- 生物醫(yī)藥財產(chǎn)抵押貸款合同模板
- 成都市二手房交易房屋交易合同解除及后續(xù)處理條款
- T-CECA 20007-2021 城市水系統(tǒng)綜合規(guī)劃技術(shù)規(guī)程
- JJG 475-2008電子式萬能試驗機(jī)
- 配件供應(yīng)技術(shù)服務(wù)和質(zhì)保期服務(wù)計劃方案
- 弱電系統(tǒng)運維服務(wù)方案
- 《濟(jì)南市城鎮(zhèn)燃?xì)忸I(lǐng)域重大隱患判定指導(dǎo)手冊》
- 中聯(lián)重科質(zhì)檢部績效考核指標(biāo)
- 2024年鄭州市高三二模(高中畢業(yè)年級第二次質(zhì)量預(yù)測)文科綜合試卷(含答案)
- 期中詞性轉(zhuǎn)換專練 2023-2024學(xué)年牛津上海版(試用本)八年級英語下冊
- 北京市海淀區(qū)2023-2024學(xué)年九年級上學(xué)期期末練習(xí)英語試題
- 四川省安全員《A證》考試題庫及答案
- 職業(yè)生涯規(guī)劃書成長賽道
評論
0/150
提交評論