Skip to content

Instantly share code, notes, and snippets.

View brilliant-ember's full-sized avatar

Mohammed Al brilliant-ember

View GitHub Profile
@brilliant-ember
brilliant-ember / set-up.sh
Last active October 23, 2022 22:10
Ubuntu ML Set-up
sudo apt install python3-pip tmux vim git jupyter podman nodejs virtualbox ruby xclip curl -y
sudo apt install python3.10-venv -y
pip3 install librosa tensorflow numpy matplotlib torch pandas virtualenv
# install go
wget https://go.dev/dl/go1.19.linux-amd64.tar.gz
sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go1.19.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
sudo apt install gopls dlv -y
@brilliant-ember
brilliant-ember / Inverse_Z_transform_python.py
Created April 27, 2021 21:52
How to do inverse Z transform with python, this function will break up the partial fraction assuming Z transform. Note that it doesn't handle complex roots, if you have complex roots use the scipy residuez function to find the poles and coefficients.
### Solving Z domain partial fraction with sympy
from sympy import *
z = symbols('z')
def inverse_z(h):
'''finds X(z)/z for the inverse z transform table look up
'''
h = h/z
h = h.apart() * z
return expand(h)
@brilliant-ember
brilliant-ember / python_serial_receiver.py
Last active December 10, 2020 16:40
Python and Arduino Serial communication
import serial
from time import sleep
COM = '/dev/ttyUSB0' #This is for linuxm Will be COM# for windows copmuters so check ur usb port names
BAUD = 9600
ser = serial.Serial(COM, BAUD, timeout = .1)
print('Waiting for device');
sleep(1)
@brilliant-ember
brilliant-ember / tmux.conf
Created September 10, 2020 14:30
My Linux tmux config, for easy copy-paste between tmux and the computer, and using vim mode, and my preferred color. You have to have xclip installed
# paste all of this here: ~/.tmux.conf
# for copying to sys clipboard
bind -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "xclip -i -f -selection primary | xclip -i -selection clipboard"
bind -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "xclip -i -f -selection primary | xclip -i -selection clipboard"
bind -T copy-mode-vi C-j send-keys -X copy-pipe-and-cancel "xclip -i -f -selection primary | xclip -i -selection clipboard"
#general other stuff
set -g default-terminal "xterm-256color"
set -g mouse on
@brilliant-ember
brilliant-ember / plot_response_and_error.m
Last active April 10, 2020 21:06
Plots a system's response, and error response of various inputs namely step, ramp, and parabolic inputs.
# u can change the input type and response by uncommenting
## t the stions of the code that are below each subplot
clear; clc;
pkg load control;
K = 32.3;
s = tf('s');
openLoopTf = K/( s*(s+3)*(s+6));
##openLoopTf = (672*(s+5)) / (s*(s+6)*(s+7)*(s+8));;
## closed loop
## very important to follow this order for the input
@brilliant-ember
brilliant-ember / tf_to_symbolic.py
Created April 7, 2020 22:18
Converts a control lib transfer function to sympy lib symbolic equation, uses x instead of s for the symbolic representation
def tf_to_symbolic_fraction(tf):
x = symbols('x')
num, den = tfdata(tf)
num = num[0][0]
den = den[0][0]
counter = 1
length_num = len(num)
length_den = len(den)
sym_num, sym_den = 0,0
@brilliant-ember
brilliant-ember / modulation.m
Last active April 5, 2020 12:57
Plot periodic functions in Octave or Matlab with this script. It multiplies (modulates) the carrier and the msg signals, and plots the time domain and FFT reprisentation
% referenced gist https://gist.github.com/akiatoji/5649907
clear ; close all; clc
fundPeriod = pi/1000;
num_tsteps = 1000;
num_periods = 4;
tstep = num_periods * fundPeriod / num_tsteps;
t = 0:tstep:(num_periods * fundPeriod);
msg = 2*cos(400*t)+4*sin(500*t+pi/3);
@brilliant-ember
brilliant-ember / control_functions.py
Last active March 31, 2020 03:01
Control systems helpful function
# percent overshoot to theta angle and zeta ratio calculator
# PD controller calculator
#so far can only find kp value for a PD controller
# numpy is weird it has ln has a log for some reason
from numpy import log as ln
from math import atan, sqrt, pi, degrees
from sympy import symbols, simplify, fraction,solve, pprint, evalf, im, I
from math import isclose