Skip to content

Instantly share code, notes, and snippets.

import numpy as np
import matplotlib.pyplot as plt
def sum_harmonics(n, t):
result = np.zeros(t.shape)
for i in range(n):
result += 4 / (2 * i + 1) / np.pi * np.sin(t * (2 * i + 1))
return result
t = np.arange(0, 2 * np.pi, 0.0001)
import numpy as np
import matplotlib.pyplot as plt
t = np.arange(0, 1, 0.001)
x = t
plt.plot(t, x);plt.show()
# We now convolve x with itself
# and dt is t[2] - t[1]
h = t[1] - t[0]
import numpy as np
import itertools
VECSIZE = 6
M = np.eye(6)
for r in range(6):
print(f"FOR r = {r}:")
for pair in [i for i in itertools.product(range(1, VECSIZE + 1), range(1, VECSIZE + 1)) if i[0] != r and i[1] != r and i[0] < i[1]]:
print(pair)
e1 = np.zeros(VECSIZE, dtype='int')
myenv
import numpy as np
import sys
def waterfill(alpha_vals, P):
alpha_vals = np.array(alpha_vals)
n = len(alpha_vals)
allocation_done = False
allocation = np.zeros(len(alpha_vals))
while not allocation_done:
nu_val = 1 / (P + sum(1 / alpha_vals[:n])) * n
import numpy as np
import matplotlib.pyplot as plt
NFFT = 1024
BETA2 = -25509e-30
FS = 500e9
L = 1000000
# We have NFFT samples. Let's target a sampling rate of 500
# Gsamp/s.
@kumanna
kumanna / .gitignore
Last active September 28, 2023 10:09
.ipynb_checkpoints/
import numpy as np
# Generate random BPSK symbols
SYMBOLS = 1024
qpsk_symbols = (np.sign(np.random.rand(SYMBOLS) - 0.5) + 1j * np.sign(np.random.rand(SYMBOLS) - 0.5)) / np.sqrt(2)
h = np.array([1, 0.4 + 0.3j, 0.2 - 0.1j])
NCP = 4
NFFT = 64
class Test {
public static void main(String args[]) {
double d = 314.159265;
System.out.println((byte)d);
int i = (int) d;
System.out.println(i);
System.out.println((byte) (i & 0xff));
System.out.println(i >> 2);
// How I would do it:
int di = (int) d;
from bottle import route, run, request, app, redirect
import beaker.middleware
session_opts = {
'session.type': 'file',
'session.data_dir': './session/',
'session.auto': True,
}