Skip to content

Instantly share code, notes, and snippets.

@kalesan
kalesan / waterfilling.m
Created May 20, 2022 09:18
Water-filling example in Matlab/Octave
% Number of channels
N = 10;
N0 = 1; % Normalized noise level
SNR_dB = 10; % Signal-to-noise ratio in dB
P = 10**(SNR_dB / 10);
% The channel specific gains drawn from Gaussian distribution
g = abs(randn(N, 1));
<html>
<head>
<title>Water-filling illustration in Chart.js</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.5.0/chart.min.js"> </script>
</head>
<body>
<center>
<div>Bisection step</div>
<div style="width:50%">
@kalesan
kalesan / waterfilling.py
Last active January 3, 2024 08:17
Water-filling example code for https://scicoding.com/waterfilling/
# Example code for https://scicoding.com/waterfilling/
import numpy as np
# Number of channels
N = 10
N0 = 1 # Normalized noise level
SNR_dB = 10 # The signal to noise ratio in dB
P = 10**(SNR_dB/10) # Sum power budget defined via the SNR
# The channel specific gains drawn from Gaussian distribution
import cvxpy as cp
import numpy as np
# Number of channels
N = 10
N0 = 1 # Normalized noise level
SNR_dB = 10 # The signal to noise ratio in dB
P = 10**(SNR_dB/10) # Sum power budget defined via the SNR
# The channel specific gains drawn from Gaussian distribution