Skip to content

Instantly share code, notes, and snippets.

View Hio-Been's full-sized avatar
🏠
Working from home

Hio-Been Han Hio-Been

🏠
Working from home
  • Korea Institute of Science and Technology
  • Seoul, South Korea
View GitHub Profile
@Hio-Been
Hio-Been / imagesc_surf.m
Last active July 26, 2021 02:50
imagesc_surf: Handy MATLAB function for imagesc-like 2D visualization using surf.m
function handle = imagesc_surf( x, y, d )
size_xy = size( d );
if size(x,1)>size(x,2), x=x'; end
if size(y,1)>size(y,2), y=y'; end
if ~(size_xy(1)==length(x)), x = imresize(x, [1,size_xy(1)]); end
if ~(size_xy(2)==length(y)), y = imresize(y, [1,size_xy(2)]); end
handle = surf( x, y, d' ); axis xy
handle.LineStyle = 'none';
view(gca,[-0.001 90]);
set(gca, 'XScale', 'log', 'YScale', 'log');
@Hio-Been
Hio-Been / gc_spectral_demo.m
Last active July 23, 2021 04:37
MATLAB demo script for granger causality (powered by MVGC toolbox)
%
% Jeelab Spectral Granger-causality demo script for dummies
% Toolbox source: http://www.sussex.ac.uk/sackler/mvgc/
%
% written by Hio-Been Han, 2021-07-23. hiobeen.han@kaist.ac.kr
% https://jeelab.net
%
%% (1) Environment setting
clear all;
@Hio-Been
Hio-Been / interp_nan2d.m
Created March 9, 2021 07:18
MATLAB function for interpolating 2d matrix
function mat_interp = interp_nan2d( mat, kernel_size )
%
% MATLAB function for interpolating 2d matrix
%
% Interpolating nan in 2D matrix
% Hio-Been Han, hiobeen.han@kaist.ac.kr
% 2021-03-09.
%
shape = size(mat);
if nargin < 2,kernel_size = ceil( mean(shape)/50 );end
@Hio-Been
Hio-Been / realtime_daq_read.m
Created November 10, 2020 11:59
Sample MATLAB script for real-time NI-DAQ data streaming (read only)
acqDuration = 60*5;
fprintf('\nInitiating DAQ recording.. Max duration: [%03d minutes]\n', acqDuration);
samplingRate = 2000;
%% (1) Get DAQ
warning off;
nSmooth = 180; % for visualization
try; DAQs.in.session.stop; release( DAQs.in.session ); end
%% (2) DAQ INIT
@Hio-Been
Hio-Been / parse_video.m
Last active September 30, 2020 12:36
MATLAB function (mp4 to jpg frames)
function parse_video(resizeOption, cropOption)
%
% Parsing video (*.mp4/*.avi) file(s) into image (*.jpg) files
%
% Written by Hio-Been Han, hiobeen.han@kaist.ac.kr
%
% 2020-09-30
%
if nargin < 1, resizeOption = false; end
if nargin < 2, cropOption = false; end
@Hio-Been
Hio-Been / hb_calc_movingwindow.m
Last active July 27, 2020 09:55
MATLAB function for calculating custom functions within sliding window
function [x_conv, window] = hb_calc_movingwindow( x, winsize, func, gaussOpt )
% Calculating *func* using moving window
% ex) For moving average
% data = hb_calc_movingwindow( data, 100, @nanmean );
%
% Written by hiobeen.han@kaist.ac.kr, 2020-07-27
if nargin < 3, func = @nanmean; end
if nargin < 4, gaussOpt = false; end
@Hio-Been
Hio-Been / generate_masks_manual.m
Created July 13, 2020 05:26
MATLAB function for generating binary masks (usually for CNN)
function generate_masks_manual()
% MATLAB function for generating binary masks
% Hio-Been Han, hiobeen.han@kaist.ac.kr
% 2020-07-13.
%% (1) Environment set
[img_directory] = uigetdir();
% img_directory = [pwd '/frame_copied'];
file_list = dir( [img_directory '/*.png'] );
@Hio-Been
Hio-Been / calculating_trembling_frequency.m
Created April 12, 2020 11:36
Calculating trembling frequency
%% (0) Set option
vid_save_option = false; % <- change this to true (to gen video output)
%% (1) Read frames from input video
vid_in = VideoReader( 'video_input.mp4' );
frames = [];
nFrames = vid_in.Duration * vid_in.FrameRate;
for frameIdx = 1:nFrames
frames(:,:,:,frameIdx) = vid_in.readFrame();
end
@Hio-Been
Hio-Been / get_drifting_grating.m
Created February 22, 2020 07:12
MATLAB function for drifting grating (2D sine wave)
function imgs = get_drifting_grating( n_frames, rec, tilt, sf, drift_speed, plot_option )
%% MATLAB function for drifting grating (2D sine wave)
% Usage:
% imgs = get_drifting_grating( n_frames, rec, tilt, sf, drift_speed, plot_option )
% ex) imgs = get_drifting_grating( 60, 500, 30, .01, 5, 1 );
% ex) imgs = get_drifting_grating();
%
% written by Hio-Been Han, 2020-02-22
% hiobeen.han@kaist.ac.kr
%
@Hio-Been
Hio-Been / hb_yooutube_mp3_auto_downloader.py
Last active December 9, 2019 09:27
Python script for automatic mp3 download from Youtube clip
songnames = [ 'Anne-Marie/2002',
'Aaron Sheer/Searching',
'The Clash/Should I Stay Or Should I Go',
'Jessie Reyez/Figures, a Reprise (Feat. Daniel Caesar)',
'Usher/Love In This Club (Feat. Young Jeezy)',
"Jason Mraz/I'm Yours",
"Jason Mraz/I Won't Give Up",
"Justin Bieber/Love Yourself",
"Anne-Marie/FRIENDS",
"The Chainsmokers/Closer (Feat.Halsey)",