Skip to content

Instantly share code, notes, and snippets.

View shohei's full-sized avatar

Shohei Aoki shohei

View GitHub Profile
@shohei
shohei / mnist.py
Created September 4, 2021 04:08
Download MNIST datasets
# coding: utf-8
try:
import urllib.request
except ImportError:
raise ImportError('You should use Python 3.x')
import os.path
import gzip
import pickle
import os
import numpy as np
@shohei
shohei / determineSystem.m
Last active September 2, 2020 12:43
Grid search program to determine system transfer function
function besttf = determineSystem(z, npole, nzero)
%% determineSystem.m
% Grid search a system model from the given number of zeros and poles
%
%% Inputs:
% z : iddata object (created by iddata(y,u,Ts))
% npole : maximum number of poles for grid search
% nzero : maximum number of zeros for grid search
%
%% Outputs:
@shohei
shohei / findbest.m
Last active August 31, 2020 01:41
Choosing best system identification model using AIC
clear; close all;
s=tf('s');
G=1/(s^2+s+1);
ts=0.1;
t=0:ts:20;
nx=10;
u=[zeros(nx,1)',ones(length(t)-nx,1)'];
[y,t]=lsim(G,u,t);
z=iddata(y,u',0.1); %uを転置してカラムベクトルに直す
@shohei
shohei / opamp.txt
Created August 18, 2020 08:53
circuit js simulation for opamp module of switch science
$ 1 0.000005 81.92041607667615 50 5 43
c 224 208 224 160 0 0.000001 0.0010000007181592135
r 224 160 320 160 0 10000
r 224 128 320 128 0 10000
c 336 256 416 256 0 1e-10 0.0010000012681743442
r 560 96 608 96 0 10000
r 640 176 720 176 0 100000
c 496 128 560 128 0 0.000001 3.242821716512841
r 352 224 400 224 0 100000
g 224 272 224 288 0
@shohei
shohei / bathtub_simulation.m
Created July 26, 2020 06:50
Bathtub curve and Weibull distribution
clear all; close all;
f = @(m,eta,g,t) m/eta^m*(t-g).^(m-1);
t=0.1:0.1:2;
m=0.5; eta=3; g = 0;
lambda = f(m,eta,g,t);
subplot(311);
plot(t,lambda);
hold on;
@shohei
shohei / remove.py
Created June 10, 2020 20:19
Subtitle format code
sentences = []
fout = open("output.txt","w")
with open("sub.txt") as f:
lines = f.readlines()
for line in lines:
if not line in sentences:
sentences.append(line)
fout.write(line)
@shohei
shohei / download.py
Created June 2, 2020 08:49
Slack download
import json
import os
import random
with open('data.txt') as json_file:
data = json.load(json_file)
for p in data:
if "files" in p:
q = p['files'][0]
if "mimetype" in q:
@shohei
shohei / PCR.csv
Last active May 7, 2020 06:14
Total PCR Positive Cases in Japan (as of 2020.05.06)
date positive
2020-2-6 16
2020-2-7 16
2020-2-10 16
2020-2-12 16
2020-2-13 17
2020-2-14 21
2020-2-17 46
2020-2-18 53
2020-2-19 60
@shohei
shohei / static_test_stand.ino
Created March 16, 2020 10:37
Arduino Rocket Engine Static Test Stand
/*
Model Rocket Engine Dynamometer - Nick Cinquino 9/1/15
V.5 Original 10Kg loadcell Modified from Nathan Seidle, SparkFun Electronics, November 19th, 2014
Output data in grams (g). There are 101.97 gram-force per Newton, for conversion.
Your calibration factor may be very positive or very negative.
It all depends on the setup of your individual loadcell, and the direction the sensors deflect from zero state.
Need to experiment!
Hack the HX711 board to set pin 15 high, for 80 samples per second.
This example code uses bogde's excellent library: https://github.com/bogde/HX711
bogde's library is released under a GNU GENERAL PUBLIC LICENSE
@shohei
shohei / rocket_sizing.py
Created July 28, 2019 14:56 — forked from ina111/rocket_sizing.py
多段ロケットの最適質量配分(サイジング)問題の計算
# -*- coding: utf-8 -*-
# ======
# 多段ロケットの最適質量配分(サイジング)問題の計算
# 必要な軌道速度に空力損失、重力損失、推力損失、制御損失を追加し、
# トータルの⊿Vを事前に算出し、その軌道速度に必要なサイジングを行う。
# 初期検討段階にのみ使用可能。
#
# 入力:
# 各段のIsp[秒]
# 各段の構造比(0.0~1.0)(各段の全備重量と推進剤以外の割合)