-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathrm50Hz.m
More file actions
58 lines (44 loc) · 1.71 KB
/
rm50Hz.m
File metadata and controls
58 lines (44 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
function clean = rm50Hz(data,ord,sr,ncomp) % data, order, no components to remove
%ord = order of the data with respect to samples x
% This example uses DSS to remove power-line noise from EEG data.
% Finds components that are most dominated by 50 Hz and
% harmonics, regresses them out to obtain clean data.
%
% Uses nt_bias_fft(), nt_dss0(), nt_tsr().
% use DSS to isolate 50 Hz & harmonics
disp('50 Hz & harmonics DSS...');
% re-order data
data = permute(data,ord);
% covariance matrices of full band (c0) and filtered to 50 Hz & harmonics (c1)
[c0,c1]=nt_bias_fft(data,[50, 100, 150]/sr, 512);
% DSS matrix
[todss,pwr0,pwr1]=nt_dss0(c0,c1);
p1=pwr1./pwr0; % score, proportional to power ratio of 50Hz & harmonics to full band
% DSS components
z=nt_mmat(data,todss);
% first components are most dominated by 50Hz & harmonics
NREMOVE=ncomp;
clean=nt_tsr(data,z(:,1:NREMOVE,:)); % regress them out
% plot bias score
figure(1); clf; set(gcf,'color', [1 1 1]);
plot(p1, '.-'); xlabel('component'); ylabel('score'); title('DSS score');
% plot spectra of DSS components
figure(2); clf; set(gcf,'color', [1 1 1]);
nt_spect_plot2(nt_normcol(z(:,1:30,:)),512,[],[],sr);
title('spectra of first 30 DSS components'); ylabel('component')
% plot spectra of data before and after removal of power line components
figure(3); clf; set(gcf,'color', [1 1 1]);
subplot 121;
nt_spect_plot(data,1024,[],[],sr);
set(gca,'ygrid','on');
hold on
nt_spect_plot(clean,1024,[],[],sr);
nt_colorlines([],[3 1]);
title('power spectra, average over channels');
legend('before','after'); legend boxoff
set(gca,'ygrid','on');
subplot 122
nt_spect_plot(data-clean,1024,[],[],sr);
title('noise power (removed)');
set(gca,'ygrid','on');
clean = ipermute(clean,ord);