victory的博客

长安一片月,万户捣衣声

0%

在python代码中使用c语言编写的函数-以输出Hello World为例

linux环境下!!!

Step 1:编写c语言代码-sayHello.c

include<stdio.h>
void sayHello()
{
    printf("Hello World!");
}

Step 2:把c语言文件编译成一个动态库

gcc sayHello.c -shared -o lib-sayHello.so

Step 3:编写python代码-main.py

from ctypes import *

#加载动态库
lib = cdll.LoadLibrary("./lib-sayHello.so")
#调用sayHello函数
lib.sayHello()

Step 4:运行python代码

python3 main.py

递归与分治策略

分治与递归经常同时应用在算法设计中

递归(Recursion)

递归算法—直接或间接地调用自身的较小模式的算法
递归函数—用函数自身的较小模式给出其定义的函数

阅读全文 »

多进程拷贝文件

实现流程分析

  1. 获取要copy的文件夹的名字
  2. 创建一个文件夹
  3. 获取old文件夹中的所有的文件名字
  4. 使用多进程方式copy原文件夹中的所有文件到新的文件夹中

Code

from multiprocessing import Pool,Manager
import os
import time

def copyFileTask(name,oldFolderName,newFolderName,queue):
    "complete the function of coping a file"
    fr = open(oldFolderName+"/"+name)
    fw = open(newFolderName+"/"+name,"w")
    content = fr.read()
    fw.write(content)
    fr.close()
    fw.close()
    queue.put(name)

def main():
    #0.get the file name you want to copy
    oldFolderName = input("Please input the file name:")
    #1.create a file directory
    newFolderName = oldFolderName+"-copy"
    #pmrint(newFolderName)
    os.mkdir(newFolderName)
    #2.get all file name of old file directory
    fileNames = os.listdir(oldFolderName)
    #print(fileNames)
    #3.copy all file of old file directory to a new file directory
    pool = Pool(5)
    queue = Manager().Queue()
    for name in fileNames:
        pool.apply_async(copyFileTask,args=(name,oldFolderName,newFolderName,queue))
    num = 0
    allNum = len(fileNames)
    while num < allNum:
        queue.get()
        num += 1
        copyRate = num/allNum
        print("\rcopy process:%.2f%% "%(copyRate*100),end="")
        time.sleep(1)
    print('\ncompleted')
    pool.close()
    pool.join()
if __name__ == "__main__":
    main()

Artifacts reduction algorithms’s two main ways

Regression and Filtering Methods

Regression

The regression model use a function to fit the data to smooth the data.
Disadvantages:
1.this method only works for reference channels that are available.
2.EEG signal being non-linear and non-stationary process,linear regression is not the best choice for analysis in such applications.
3.it can only be used to treat few particular types of artifact,not all types.

Filtering

linear adaptive filters

Note:too sensitive and unstable to adjust the parameters

non-linear adaptive filters(include Volterra filters and neural network based adptive filters)

Note:stronger processing capabilities and complex calculation
Disadvantages:
filters may eliminate useful EEG signals during artifact deletion.
阅读全文 »

Automatic removal of eye movement artifacts from the EEG using ICA and the dipole model

Abstract

In this study,we proposed and evaluated the use of Independent Component Analysis(ICA) combining the EEG dipole model to automatically remove eye movement artifacts from the EEG without needing EOG as a reference.

阅读全文 »

算法基础

算法定义

解决一个具体问题的方法称为一个算法

算法的特征

1)确定性:组成算法的每条指令清晰、无歧义
2)有限性:算法中每条指令的执行次数有限
3)可行性:每条指令是简单的、具体的
4)输入:有零个或多个外部量作为算法的输入
5)输出:算法产生至少一个量作为输出

算法是程序之灵魂

阅读全文 »

vim常用命令

yy:复制 光标所在的这一行 numyy:复制 光标所在行开始向下的num行

p:paste

dd:剪切 光标所在的这一行

numdd:剪切 光标所在行向下num行

D:从当前的光标开始剪切,一直到行末

d0:从单签光标开始剪切,一直到行首

x:删除当前的光标,每次只会删除一个

X:删除当前光标前面那个,每次只会删除一个

阅读全文 »