├── .gitignore ├── GenerateCSINetDataSet.mlx ├── LICENSE.md ├── README.md ├── SECURITY.md ├── SimChanCompEffOnPrecodingUsingMATLABAndKerasWithCSINetExample.mlx ├── images ├── ConstellationDiagram.png └── Workflow_Coexecution.png ├── postprocessChannelEstimate.m └── preprocessChannelEstimate.m /.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matlab-deep-learning/CSINet-Channel-Compression-in-MATLAB-Using-Keras/2363a692d75a8a2a2c8c9da662bb55d744375e58/.gitignore -------------------------------------------------------------------------------- /GenerateCSINetDataSet.mlx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matlab-deep-learning/CSINet-Channel-Compression-in-MATLAB-Using-Keras/2363a692d75a8a2a2c8c9da662bb55d744375e58/GenerateCSINetDataSet.mlx -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2023, The MathWorks, Inc. 2 | All rights reserved. 3 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 4 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 5 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 6 | 3. In all cases, the software is, and all modifications and derivatives of the software shall be, licensed to you solely for use in conjunction with MathWorks products and service offerings. 7 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Simulate Channel Compression Effect on Precoding Using MATLAB and Keras with CSINet 2 | 3 | This example shows how to co-execute MATLAB® and Python® to simulate the effect of channel estimate compression on precoding in a MIMO OFDM channel. It shows how to: 4 | * Generate CDL channel estimates in MATLAB using the [5G Toolbox™](https://www.mathworks.com/products/5g.html) 5 | * Load and test a pre-trained CSINet Keras™ model using co-execution with Python 6 | * Fine tune the model weights through transfer learning using co-execution with Python 7 | * Simulate the effect of channel estimate compression on precoding in MATLAB using the [5G Toolbox](https://www.mathworks.com/products/5g.html) and [Communications Toolbox™](https://www.mathworks.com/products/communications.html) 8 | 9 | The following figure summarizes the operations executed in MATLAB (marked in blue) versus those executed in Keras (marked in grey). 10 | 11 | ![](images/Workflow_Coexecution.png) 12 | 13 | ## Overview 14 | 15 | There are different options for accessing deep learning models within MATLAB, including: 16 | 17 | 1. Using models created in MATLAB using [Deep Learning Toolbox™](https://www.mathworks.com/products/deep-learning.html) 18 | 2. [Converting](https://www.mathworks.com/help/deeplearning/import-deep-neural-networks.html) models from other frameworks into MATLAB 19 | 3. Co-executing models from other frameworks with MATLAB 20 | 21 | This example provides an overview of the third approach. Co-execution is useful for leveraging [wireless products in MATLAB](https://www.mathworks.com/solutions/wireless-communications.html) to test existing deep learning models from other frameworks in an end-to-end link simulation. 22 | This workflow also allows engineering teams working with MATLAB & Python deep learning frameworks to easily combine their work in one environment. 23 | Approaches one & two are useful for building deep learning models from scratch or for using additional capabilities from the [Deep Learning Toolbox](https://www.mathworks.com/products/deep-learning.html) with pre-trained models, such as [Deep Learning Code Generation](https://www.mathworks.com/help/deeplearning/code-generation.html) or [deep learning models in Simulink®](https://www.mathworks.com/help/deeplearning/ug/classify-images-in-simulink-with-imported-tensorflow-network.html). 24 | 25 | ### Requirements 26 | To run this example, you need: 27 | - [MATLAB](http://www.mathworks.com) R2022b or later 28 | - [Communications Toolbox](https://www.mathworks.com/products/communications.html) 29 | - [5G Toolbox](https://www.mathworks.com/products/5g.html) 30 | - [Python](https://www.python.org/downloads/release/python-3104/) (tested with version 3.10.4) 31 | - [TensorFlow™](https://www.tensorflow.org/) (tested with version 2.10.0) 32 | - [Keras](https://keras.io/) (tested with version 2.10.0) 33 | - [Numpy™](https://numpy.org/) (tested with version 1.23.4) 34 | 35 | For more information about installing Python, see [Install Supported Python Implementation](https://www.mathworks.com/help/matlab/matlab_external/install-supported-python-implementation.html). 36 | 37 | ## Running the Example 38 | Open and run the live script `SimChanCompEffOnPrecodingUsingMATLABAndKerasWithCSINetExample.mlx`. 39 | To generate a new CDL channel estimates dataset, use the live script `GenerateCSINetDataSet.mlx`. 40 | The live scripts use the helper files `preprocessChannelEstimate.m` and `postprocessChannelEstimate.m` for pre/post-processing the training and testing data sets. 41 | 42 | ### Visualize the channel compression effect 43 | By the end of the example, you will be able to visualize the effect of channel feedback compression with CSINet [1] on the received constellation of an OFDM MIMO channel with zero-forcing precoding. 44 | The following figure shows the effect of using CSINet for channel feedback with compression rate 1/4 and normalized mean square error -42 dB in a CDL channel with the following parameters: 45 | * Tx Antennas: 32 46 | * Rx Antennas: 2 47 | * Delay Profile: CDL-B 48 | * RMS delay spread: 100 ns 49 | * Max delay after truncation: 32 50 | * Max Doppler: 2 Hz 51 | * Resource blocks: 48 52 | * Subcarrier spacing: 30 KHz 53 | 54 | 55 | 56 | ## References 57 | [1] Wen, Chao-Kai, Wan-Ting Shih, and Shi Jin, "Deep learning for massive MIMO CSI feedback," IEEE Wireless Communications Letters, vol. 7, no. 5, pp. 748-751, Oct. 2018. 58 | 59 | Copyright 2023, The MathWorks, Inc. 60 | 61 | [![View CSINet-Channel-Compression-in-MATLAB-Using-Keras on File Exchange](https://www.mathworks.com/matlabcentral/images/matlab-file-exchange.svg)](https://www.mathworks.com/matlabcentral/fileexchange/124575-csinet-channel-compression-in-matlab-using-keras) 62 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | 2 | # Reporting Security Vulnerabilities 3 | 4 | If you believe you have discovered a security vulnerability, please report it to 5 | [security@mathworks.com](mailto:security@mathworks.com). Please see 6 | [MathWorks Vulnerability Disclosure Policy for Security Researchers](https://www.mathworks.com/company/aboutus/policies_statements/vulnerability-disclosure-policy.html) 7 | for additional information. -------------------------------------------------------------------------------- /SimChanCompEffOnPrecodingUsingMATLABAndKerasWithCSINetExample.mlx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matlab-deep-learning/CSINet-Channel-Compression-in-MATLAB-Using-Keras/2363a692d75a8a2a2c8c9da662bb55d744375e58/SimChanCompEffOnPrecodingUsingMATLABAndKerasWithCSINetExample.mlx -------------------------------------------------------------------------------- /images/ConstellationDiagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matlab-deep-learning/CSINet-Channel-Compression-in-MATLAB-Using-Keras/2363a692d75a8a2a2c8c9da662bb55d744375e58/images/ConstellationDiagram.png -------------------------------------------------------------------------------- /images/Workflow_Coexecution.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matlab-deep-learning/CSINet-Channel-Compression-in-MATLAB-Using-Keras/2363a692d75a8a2a2c8c9da662bb55d744375e58/images/Workflow_Coexecution.png -------------------------------------------------------------------------------- /postprocessChannelEstimate.m: -------------------------------------------------------------------------------- 1 | function CSIT = postprocessChannelEstimate(Hhat,opt) 2 | % postprocessChannelEstimate sets the mean and variance of the 3 | % predicated channel estimates to those of the original data set after 4 | % truncation. It also maps the channel estimates to the angular-delay domain, 5 | % interpolates the delay domain, and maps them back to the 6 | % spatial-frequency domain. 7 | 8 | % Copyright 2022 The MathWorks, Inc. 9 | 10 | Hhat = single(Hhat); 11 | 12 | % Permute Hhat to Nsub-by-nTx-by-dataChannels-by-nRx 13 | Hhat = permute(Hhat, [2,3,4,1]); 14 | 15 | nTx = opt.NumTxAntennas; 16 | nRx = opt.NumRxAntennas; 17 | 18 | midPoint = floor(opt.NumSubcarriers/2); 19 | lowerEdge = midPoint - (opt.NumSubcarriers-opt.maxDelay)/2 + 1; 20 | 21 | Htemp = ((Hhat(:,:,:,:) - opt.targetMean) / opt.targetStd) * opt.chanStats.std + opt.chanStats.mean; 22 | Htrunc = squeeze(complex(Htemp(:,:,1,:),Htemp(:,:,2,:))); 23 | HdaTrunc = fft2(Htrunc); 24 | Hda = [HdaTrunc(1:lowerEdge-1,:,:); zeros((opt.NumSubcarriers-opt.maxDelay),nTx,nRx); HdaTrunc(lowerEdge:end,:,:)]; 25 | CSIT = ifft2(Hda); 26 | 27 | % Permute CSIT nRx-by-nTx-by-Nsub 28 | CSIT = permute(CSIT, [3,2,1]); 29 | end -------------------------------------------------------------------------------- /preprocessChannelEstimate.m: -------------------------------------------------------------------------------- 1 | function [HtruncReal_perm, truncMean, truncStd] = preprocessChannelEstimate(Hest,opt) 2 | % preprocessChannelEstimate sets the mean and variance of the 3 | % channel estimates to the target mean and variance specified in OPT. 4 | % It then maps the channel estimates to the angular-delay domain, 5 | % truncates the delay domain, and maps them back to the 6 | % spatial-frequency domain. 7 | 8 | % Copyright 2022 The MathWorks, Inc. 9 | 10 | maxDelay = opt.maxDelay; 11 | targetStd = opt.targetStd; 12 | targetMean = opt.targetMean; 13 | 14 | [nSub,~,nRx,nTx] = size(Hest); 15 | 16 | midPoint = floor(nSub/2); 17 | lowerEdge = midPoint - (nSub-maxDelay)/2 + 1; 18 | upperEdge = midPoint + (nSub-maxDelay)/2; 19 | 20 | % Average over symbols (one slot) 21 | H = reshape(mean(Hest,2), [nSub,nRx,nTx]); 22 | H = permute(H,[1 3 2]); 23 | 24 | % Decimate over subcarriers using 2-D FFT for each Rx antenna 25 | HtruncReal = zeros(maxDelay,nTx,2,nRx,'like',real(H(1))); 26 | for rx = 1:nRx 27 | Hdft2 = fft2(H(:,:,rx)); 28 | Htemp = Hdft2([1:lowerEdge-1 upperEdge+1:end],:); 29 | Htrunc = ifft2(Htemp); 30 | 31 | HtruncReal(:,:,1,rx) = real(Htrunc); 32 | HtruncReal(:,:,2,rx) = imag(Htrunc); 33 | 34 | truncMean = mean(HtruncReal,'all'); 35 | truncStd = std(HtruncReal,[],'all'); 36 | 37 | HtruncReal(:,:,:,rx) = (HtruncReal(:,:,:,rx) - truncMean) ./ truncStd * targetStd + targetMean; 38 | end 39 | 40 | % Permute dimensions to nRx-by-nTx-by-maxDelay-by-2 to match the 41 | % pre-trained Keras models input layer 42 | HtruncReal_perm = permute(HtruncReal,[4,1,2,3]); 43 | end --------------------------------------------------------------------------------