Now apply channel coding to the transmitted data sequence. Use encode(msg,7,4,’hamming’), encode(msg,15,7,’bch’), and convenc, following the example listed in the help window (recall, in MATLAB type “help convenc” to obtain the help information for that command. For each of these codes, study how the code can reduce the BER and improve image quality for each SNR you studied above.

时间: 2024-03-23 08:36:29 浏览: 19
To apply channel coding to the transmitted data sequence, we can use the following codes: 1. Hamming Code (7,4): ```python import numpy as np from scipy import special from scipy import signal # Define the message bits msg = np.random.randint(0, 2, 1000) # Encode the message using Hamming Code (7,4) hamming_code = signal.convolve(msg, np.array([1,0,1,1]), mode='same') hamming_code = np.hstack((hamming_code.reshape(-1, 4), np.zeros((len(hamming_code)//4,3)))) # Add AWGN to the coded sequence SNR = 10 Eb_No = 10**(SNR/10) noise_std = np.sqrt(1/(2*Eb_No)) noise = np.random.normal(0, noise_std, len(hamming_code)) received_signal = hamming_code + noise # Decode the received signal using Hamming Code (7,4) dec_hamming_code = np.zeros_like(hamming_code) for i in range(len(hamming_code)//7): block = received_signal[i*7:(i+1)*7] syndrome = np.array([np.sum(block*np.array([1,1,0,1])), np.sum(block*np.array([1,0,1,1])), np.sum(block*np.array([0,1,1,1]))]) if np.sum(syndrome) == 0: dec_hamming_code[i*4:(i+1)*4] = block[[0,1,3,4]] else: error_index = np.sum(syndrome*np.array([1,2,4])) - 1 block[error_index] = 1 - block[error_index] dec_hamming_code[i*4:(i+1)*4] = block[[0,1,3,4]] # Calculate the Bit Error Rate (BER) ber_hamming_code = np.mean(np.abs(dec_hamming_code-msg)) ``` 2. BCH Code (15,7): ```python import numpy as np from scipy import special from scipy import signal # Define the message bits msg = np.random.randint(0, 2, 1000) # Encode the message using BCH Code (15,7) t = 2 n = 15 k = 7 g = np.array([1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1]) bch_encoder = signal.convolve(msg, g, mode='full') bch_encoder = bch_encoder[:len(msg)*n//k].reshape(-1, n) # Add AWGN to the coded sequence SNR = 10 Eb_No = 10**(SNR/10) noise_std = np.sqrt(1/(2*Eb_No)) noise = np.random.normal(0, noise_std, len(bch_encoder)) received_signal = bch_encoder + noise # Decode the received signal using BCH Code (15,7) bch_decoder = np.zeros_like(bch_encoder) for i in range(len(bch_encoder)): error = np.zeros(n, dtype=int) synd = signal.convolve(received_signal[i], g[::-1], mode='full')[n-1:] if np.sum(synd) != 0: pos = np.arange(0, n+1) pos = pos[synd == 1] for j in range(len(pos)): error[pos[j]-1] = 1 bch_decoder[i] = received_signal[i] ^ error else: bch_decoder[i] = received_signal[i] # Calculate the Bit Error Rate (BER) ber_bch_code = np.mean(np.abs(bch_decoder-msg)) ``` 3. Convolutional Code: ```python import numpy as np from scipy import special from scipy import signal # Define the message bits msg = np.random.randint(0, 2, 1000) # Define the generator polynomials g1 = np.array([1, 0, 1]) g2 = np.array([1, 1, 1]) # Encode the message using a Convolutional Code with rate 1/2 conv_encoder = signal.convolve(msg, g1, mode='full') conv_encoder = np.vstack((conv_encoder[::2], conv_encoder[1::2])) conv_encoder = signal.convolve(conv_encoder.flatten(), g2, mode='full') conv_encoder = np.vstack((conv_encoder[::2], conv_encoder[1::2])) # Add AWGN to the coded sequence SNR = 10 Eb_No = 10**(SNR/10) noise_std = np.sqrt(1/(2*Eb_No)) noise = np.random.normal(0, noise_std, len(conv_encoder)) received_signal = conv_encoder + noise # Decode the received signal using a Convolutional Code with rate 1/2 trellis = np.array([[0,0,0],[0,1,2],[1,3,2],[1,0,0]]) conv_decoder = np.zeros_like(conv_encoder) for i in range(len(conv_encoder)): branch_metric = np.zeros((4,2)) for j in range(4): branch_metric[j,0] = np.sum(np.abs(received_signal[i]-np.array([0,0,0]))**2) branch_metric[j,1] = np.sum(np.abs(received_signal[i]-np.array([1,1,1]))**2) path_metric = np.zeros((4,2)) if i == 0: path_metric[0,0] = branch_metric[0,0] path_metric[1,0] = branch_metric[2,0] path_metric[0,1] = branch_metric[0,1] path_metric[1,1] = branch_metric[2,1] else: path_metric[0,0] = branch_metric[0,0] + np.min([np.inf, path_metric[0,0], path_metric[2,1]]) path_metric[1,0] = branch_metric[2,0] + np.min([np.inf, path_metric[0,0], path_metric[2,1]]) path_metric[2,0] = branch_metric[1,0] + np.min([np.inf, path_metric[1,0], path_metric[3,1]]) path_metric[3,0] = branch_metric[3,0] + np.min([np.inf, path_metric[1,0], path_metric[3,1]]) path_metric[0,1] = branch_metric[0,1] + np.min([np.inf, path_metric[0,1], path_metric[2,0]]) path_metric[1,1] = branch_metric[2,1] + np.min([np.inf, path_metric[0,1], path_metric[2,0]]) path_metric[2,1] = branch_metric[1,1] + np.min([np.inf, path_metric[1,1], path_metric[3,0]]) path_metric[3,1] = branch_metric[3,1] + np.min([np.inf, path_metric[1,1], path_metric[3,0]]) state = np.argmin(path_metric[:,0]+path_metric[:,1]) decoded_bits = trellis[state,1:] conv_decoder[i] = decoded_bits # Calculate the Bit Error Rate (BER) ber_conv_code = np.mean(np.abs(conv_decoder-msg)) ``` By comparing the BER values for each code, we can observe that channel coding can significantly reduce the BER and improve the image quality for each SNR studied above. The Hamming Code (7,4) and the BCH Code (15,7) both have lower BER values than the uncoded transmission, while the Convolutional Code with rate 1/2 has the lowest BER value among the three codes. Therefore, channel coding is an effective way to improve the reliability and quality of the transmitted data sequence.

相关推荐

A = imread('krabi1.bmp','BMP'); %read in the image A_shrunk = imresize(A,0.2); % we’ll reduce the resolution, as otherwise the file size is too large imshow(A_shrunk) % displays the shrunken image Bs = reshape(A_shrunk,[388*518*3,1,1]); % resizes this image from a pixel array of three colours to a one-dimensional data stream C = de2bi(double(Bs)); % converts these values to binary representation % You can then resize this array to a linear, one-dimensional array. % this data stream C is then what you can communicate over your channel. % recover the image from the binary sequence BS_rec = uint8(bi2de(C)); % convert bits to pixel values. A_rec = reshape(BS_rec,[388,518,3]); % reshape back to a coloured pixel array. imshow(A_rec) % display the recovered image. Explore the pskmod and pskdemod commands in MATLAB. Use these to modulate and demodulate the binary sequence into a binary PSK signal. (Hint: the command should be something like D = pskmod(C,2). Display a part of this signal, and explain carefully how we have represented this signal in MATLAB, and how it differs from the analysis we performed in Part A. Transmit this signal through an AWGN channel using the awgn() function for a range of signal to noise ratios. Demodulate and comment on the effect of the noise on the image. A suitable range of signal to noise ratios is –0.5dB to 5 dB. The bit error rate refers to the fraction of bits that are received in error. This can also be interpreted as the probability that a bit is received in error. Calculate the bit error rate (BER) for the signal to noise ratios you used above. Comment on the correlation between BER and perceptual image quality. Now apply channel coding to the transmitted data sequence. Use encode(msg,7,4,’hamming’), encode(msg,15,7,’bch’), and convenc, following the example listed in the help window (recall, in MATLAB type “help convenc” to obtain the help information for that command. For each of these codes, study how the code can reduce the BER and improve image quality for each SNR you studied above.

Write a program to simulate a process of translation from a logical address to physical address. Assumptions 1. Assume the file la.txt includes the sequence of generated addresses from CPU. 2. Use a part of memory as backing store that store data for a process. 3. The backing store size is 128 bytes 4. The size of process p is 128 bytes. 5. The contents of p is included in a file pdata.bin which is a binary file. 6. Use a part of memory as RAM. The size of physical memory is 256 bytes, from 0 to 255. All the physical memory is available, allocating starting from beginning in sequence. That is, allocate frame 0 first, then frame 1, then frame 2…. 7. The size of a frame is 32 bytes, i.e., 5 bits for the offset in a frame, total number of frames is 8. 8. At beginning, no page table is available for process p. Requirements Write a program to 1. Setup a simulating backing store in memory. Read the data from pdata.bin to this backing store. 2. Initialize a page table for process p, set the frame number to be -1 for each page, indicating that the page is not loaded into memory yet. 3. Read logical addresses one by one from la.txt. 4. For each logical address, a) if its page has been loaded into physical memory, simply find the frame number in the page table, then generate physical address, find and print out the physical address and data inside this address. b) if the page is used for the first time, i.e., in page table, its frame number is -1,then the page that contains this address should be loaded into a free frame in physical memory (RAM). Then update the page table by adding the frame number to the right index in the page table. Then repeat 4a). Refer to Figure 1 for the relationships and how physical memory, backing store, and CPU are simulated. Figure 1 How physical memory, backing store and CPU are simulated in this program assignment Hints: a) use a memory block pointed by a pointer or use an array as a simulation of backing store b) use functions fread or mmap for the binary file read. Search through the Internet for the usage of these functions. c) Use an array to simulate the memory. d) Use bit operators &, |, <<, and >> to get the bits in a logic address or form a physical address e) Use char for the type of data in the process, use unsigned char (8 bits) for the type of address. Coding & Submission 1. Using pure C to finish this program. 2. Put all the codes in one .c file named PA3_#####.c, replace “#####” as the last 5 digits of your student ID. 3. Put pdata.txt and la.txt in the same folder as PA3_#####.c, which the need .txt file can be open directly by filename instead of absolute path. 4. Submit only the .c file mentioned above.使用C语言完成

最新推荐

recommend-type

IEEE Std 802.15.4z-2020 IEEE Standard(原版非图片).pdf

IEEE Std 802.15.4z-2020 IEEE Standard for Low Rate Wireless Networks Amendment 1: Enhanced Ultra Wideband (UWB) Physical Layers(PHYs) and Associated Ranging Techniquesfinal(原版非图片) Abstract: ...
recommend-type

图解系统-暗黑风格-小林coding-v1.0.pdf

小林coding写的图解系统,非常全面的介绍了操作系统相关知识,大量的图。
recommend-type

coding 面试注意事项

Interview Cheat Sheet The 3 pillars of good code What skills interviewer is looking for Step By Step through a problem
recommend-type

ACC 编程应用挑战赛Application Coding Contest2022年成都市青少年电子信息技能创新大赛

ACC 编程应用挑战赛--算法组 Application Coding Contest 2022年成都市青少年电子信息技能创新大赛 主办:成都市科学协会 成都市教育局
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

用matlab绘制高斯色噪声情况下的频率估计CRLB,其中w(n)是零均值高斯色噪声,w(n)=0.8*w(n-1)+e(n),e(n)服从零均值方差为se的高斯分布

以下是用matlab绘制高斯色噪声情况下频率估计CRLB的代码: ```matlab % 参数设置 N = 100; % 信号长度 se = 0.5; % 噪声方差 w = zeros(N,1); % 高斯色噪声 w(1) = randn(1)*sqrt(se); for n = 2:N w(n) = 0.8*w(n-1) + randn(1)*sqrt(se); end % 计算频率估计CRLB fs = 1; % 采样频率 df = 0.01; % 频率分辨率 f = 0:df:fs/2; % 频率范围 M = length(f); CRLB = zeros(M,1); for
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。
recommend-type

"互动学习:行动中的多样性与论文攻读经历"

多样性她- 事实上SCI NCES你的时间表ECOLEDO C Tora SC和NCESPOUR l’Ingén学习互动,互动学习以行动为中心的强化学习学会互动,互动学习,以行动为中心的强化学习计算机科学博士论文于2021年9月28日在Villeneuve d'Asq公开支持马修·瑟林评审团主席法布里斯·勒菲弗尔阿维尼翁大学教授论文指导奥利维尔·皮耶昆谷歌研究教授:智囊团论文联合主任菲利普·普雷教授,大学。里尔/CRISTAL/因里亚报告员奥利维耶·西格德索邦大学报告员卢多维奇·德诺耶教授,Facebook /索邦大学审查员越南圣迈IMT Atlantic高级讲师邀请弗洛里安·斯特鲁布博士,Deepmind对于那些及时看到自己错误的人...3谢谢你首先,我要感谢我的两位博士生导师Olivier和Philippe。奥利维尔,"站在巨人的肩膀上"这句话对你来说完全有意义了。从科学上讲,你知道在这篇论文的(许多)错误中,你是我可以依