hjorth参数 matlab
时间: 2023-11-03 12:06:12 浏览: 157
Hjorth参数是一组用于描述信号时域特征的统计量,包括活动度(Activity)、移动性(Mobility)和复杂度(Complexity)。它们可以用于分析脑电图(EEG)信号、心电图(ECG)信号等。
在MATLAB中,可以使用以下代码计算Hjorth参数:
```matlab
function [activity, mobility, complexity] = hjorth(signal)
% 计算Hjorth参数
% signal为输入信号,为一个列向量
diff1 = diff(signal); % 一阶差分
diff2 = diff(diff1); % 二阶差分
var_signal = var(signal); % 计算方差
var_diff1 = var(diff1); % 计算一阶差分的方差
var_diff2 = var(diff2); % 计算二阶差分的方差
activity = var_signal; % 活动度
mobility = sqrt(var_diff1 / var_signal); % 移动性
complexity = sqrt(var_diff2 / var_diff1) / mobility; % 复杂度
end
```
其中,输入信号`signal`为一个列向量,输出为活动度`activity`、移动性`mobility`和复杂度`complexity`。
相关问题
python的mne计算Hjorth
Hjorth指标是一种用于评估脑电信号(EEG)活动的参数,主要用于描述信号的熵和移动性。MNE软件包中可以使用以下代码计算Hjorth指标:
```python
import numpy as np
from mne.features import hjorth
# 生成示例EEG数据
eeg_data = np.random.rand(10, 1000)
# 计算Hjorth指标
activity, complexity, mobility = hjorth(eeg_data)
# 打印结果
print("Activity:", activity)
print("Complexity:", complexity)
print("Mobility:", mobility)
```
其中,`eeg_data`是一个包含10个通道和1000个时间点的EEG数据矩阵,`hjorth()`函数返回三个参数,分别是信号的活动度(activity)、复杂度(complexity)和移动性(mobility)。这三个指标分别代表了EEG信号的能量、波形形态和波形速度等特征。
mne中计算Hjorth的函数
MNE中没有直接计算Hjorth函数的函数,但可以通过以下步骤计算:
1. 导入需要使用的库和数据
```python
import numpy as np
from mne import io, Epochs
from mne.time_frequency import psd_array_multitaper
```
2. 读取数据并创建Epochs
```python
raw = io.read_raw_edf('data.edf', preload=True)
events = mne.find_events(raw)
event_id = {'event': 1}
tmin, tmax = -1, 1
epochs = Epochs(raw, events, event_id, tmin, tmax, baseline=None)
```
3. 计算每个通道的功率谱密度
```python
freqs, psds = psd_array_multitaper(epochs.get_data(), sfreq=raw.info['sfreq'], fmin=0, fmax=50)
```
4. 计算每个通道的Hjorth参数
```python
def hjorth(x):
"""
Compute Hjorth mobility and complexity of a time series from either two
cases:
1. x, the time series of type list (length N)
2. x, the power spectral density (PSD) of a time series of type numpy
array (length N/2+1)
In case 1, the function returns the tuple (m, c), where m is the mobility
and c is the complexity.
In case 2, the function returns the tuple (m, c, freq), where freq is the
frequency vector of length N/2+1.
In both cases, the units of the output values depend on the input values.
In case 1, if x has unit u, m and c will have units of u/Hz and u/Hz^2,
respectively. In case 2, if x has unit u^2/Hz, m and c will have units of
1/Hz and u^2/Hz^3, respectively.
This implementation is based on the algorithm described in the following
paper:
Hjorth, B. (1970). EEG analysis based on time domain properties.
Electroencephalography and Clinical Neurophysiology, 29(3), 306-310.
Parameters
----------
x : list | np.ndarray
The time series or PSD.
Returns
-------
m : float
The Hjorth mobility.
c : float
The Hjorth complexity.
freq : np.ndarray | None
The frequency vector if input is a PSD, otherwise None.
"""
if isinstance(x, list):
dx = np.diff(x)
ddx = np.diff(dx)
m2 = np.mean(dx**2)
m4 = np.mean(ddx**2)
return np.sqrt(m2 / x.var()), np.sqrt(m4 / m2) / x.var()
else:
w = 2 * np.pi * np.fft.fftfreq(len(x), d=1. / (2 * (len(x) - 1)))
w = w[:len(x) // 2 + 1]
pw = np.abs(x[:len(x) // 2 + 1])**2
m2w = np.trapz(pw * w**2, w)
m0w = np.trapz(pw, w)
m4w = np.trapz(pw * w**4, w)
return np.sqrt(m2w / m0w), np.sqrt(m4w / m2w) / m0w, w
```
```python
hjorth_params = []
for psd in psds:
hjorth_params.append(hjorth(psd)[0]) # 计算Hjorth mobility
```
5. 将Hjorth参数添加到原始数据中
```python
for i, ch_name in enumerate(raw.info['ch_names']):
raw.info['chs'][i]['hjorth_mobility'] = hjorth_params[i]
```
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![application/pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)