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
#! -*- coding:utf-8 -*-
from __future__ import division
"""
< Sample 1. Double Flash Illusion >
- 컴퓨터/모니터의 성능에 따라 자극 제시 시간이 변할 수 있습니다.
- 만든이: 한효빈, 2015/03/01, hiobeen@yonsei.ac.kr
- Stimuli properties are adopted from: {
Cecere, R., Rees, G., & Romei, V. (2015).
@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 / hiobeen_spectrogram.m
Last active November 4, 2021 04:33
MATLAB function for calculating spectrogram from EEG dataset
function EEG = hiobeen_spectrogram( EEG, fft_win_size, t_resolution, freq_cut, option )
%% Calculating spectrogram from EEG dataset
%
% EEG=hiobeen_spectrogram( EEG ); % optimized to eeglab default format
% EEG=hiobeen_spectrogram( EEG [,fft_win_size] [,t_resolution,] [freq_cut,] [option] )
%
% .. fft_win_size (default 2^10) : Window size to sample (unit: data point
% .. t_resolution (default 0.1) : Time resolution of sliding (unit: sec)
% .. freq_cut (default: Nyquist) : Frequency upper-limit (unit: Hz)
@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 / hiobeen_spectrogram.py
Last active May 25, 2021 03:51
Calculating spectrogram for EEG data in Python 3
import numpy as np
def fft_half(x, srate=2000):
return np.fft.fft(x)[:int(len(x)/2)]/len(x), np.linspace(0,srate/2,len(x)/2)
# [1 x n] 2D time vector (t) should be in unit of seconds. Length should be
def get_spectrogram( data, t=EEG.times, srate=2000,
fft_win_size=2**10, t_resolution=0.1, freq_cut = 150):
# For many- and single-trials data compatibility
if data.ndim < 3: data= np.expand_dims(data,2)
@Hio-Been
Hio-Been / hb_pixabay_crawling.py
Last active April 8, 2021 21:23
Python script for Pixabay image crawling
# -*- coding: utf-8 -*-
"""
@author: HioBeen Han, hiobeen.han@kaist.ac.kr
"""
from time import sleep, gmtime, strftime
init_t = strftime("%Y%m%d-%H%M%S", gmtime())
print('Initiated at ' + init_t + ' ....')
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import requests
@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