most of time if I write this blog in English, I’m afraid of some of guys could not follow , so the main part of the blog will be shown with chinese

however some code with high dimensional would be english too for easy understanding .

FT的频谱分析官方分了3-4中解决方案，笔者一一测试， 30hz以下用hanning taper, 30-100使用multitaper。

1. 将数据读入matlab并用ft_definetrial 和ft_preprocessing 处理

2. 使用ft_freqanalysis计算单位时间和频率的功率值

3. 可视化处理结果，可用ft_singleplotTFR() 或者 ft_muitiplotTFR() ,另外可以用ft_topoplotTFR画出多个信道的脑部分布图

```#定义数据结构：
cfg=[];
cfg.dataset='Subject01.ds';
cfg.trialdef.eventtype='';
cfg.trialdef.eventvalue='';
cfg.prestim=1;
cfg.poststim=2;
cfg=ft_definetrial(cfg)

#预处理数据
data=ft_preprocessing(cfg);

#可视化清楚杂讯

cfg=[];
cfg.method='summary';
cfg.channel={'MEG'}
data_clean=ft_rejectvisual(cfg,data)

```

```save datafic data_clean

```

fieldtrip做这一块非常简洁，用的代码少的不要要的

```cfg=[];
cfg.method='wavelet';##选择小波分析，有很多比如 mtmconvol  mtmfft...
cfg.width=7; ## 这个是小波分析的cycles长度，
cfg.output='pow';   ##输出的数值 如pow' 功率谱  'powandcsd' 返回频谱和交叉频谱 'fourier' 返回复杂傅里叶频谱
cfg.foi=[1:2:30];  ## 感兴趣的频率范围
cfg.toi=[-0.5:0.05:1.5]  ## 感兴趣的时间段，其实就是stimulation 附近那一段时间
TRFh=ft_freanalysis(cfg,data_clean)
```

One crucial parameter to set is cfg.width. It determines the width of the wavelets in number of cycles. Making the value smaller will increase the temporal resolution at the expense of frequency resolution and vice versa. The spectral bandwidth at a given frequency F is equal to F/width*2 (so, at 30 Hz and a width of 7, the spectral bandwidth is 30/7*2 = 8.6 Hz) while the wavelet duration is equal to width/F/pi (in this case, 7/30/pi = 0.074s = 74ms) 4).

#可视化

```cfg = [];
cfg.baseline     = [-0.5 -0.1]; ##强调基线
cfg.baselinetype = 'absolute';
cfg.zlim         = [-3e-25 3e-25]; ##颜色控制
cfg.showlabels   = 'yes';
cfg.layout       = 'CTF151.lay';##默认
figure
ft_multiplotTFR(cfg, TRFh)

```

For signals lower than 30 Hz it is recommend to use only a single taper, e.g. a Hanning taper
High frequency smoothing has been shown to be particularly advantageous when dealing with electrophysiological brain signals above 30 Hz. Oscillatory gamma activity (30-100 Hz) is quite broad band and thus analysis of such signals benefit from multitapering.

##hanning taper 低于30hz使用:

```cfg = [];
cfg.baseline     = [-0.5 -0.1];
cfg.baselinetype = 'absolute';
cfg.zlim         = [-3e-27 3e-27];
cfg.showlabels   = 'yes';
cfg.layout       = 'CTF151.lay';
figure
ft_multiplotTFR(cfg, TFRwave);

```
```##画出topoplotTFR
cfg = [];
cfg.baseline     = [-0.5 -0.1];
cfg.baselinetype = 'absolute';
cfg.xlim         = [0.9 1.3];
cfg.zlim         = [-1.5e-27 1.5e-27];
cfg.ylim         = [15 20];
cfg.marker       = 'on';
figure
ft_topoplotTFR(cfg, TFRwave);

```