我需要有关我的 matlab 代码的帮助。我已经记录了脑电图数据,现在我想在 matlab 中对其进行分析。我想找到特定频率范围的平均功率(theta:4-8 Hz,alpha:8-12Hz 等)。为此,我执行了 fft。接下来,我使用 interp1 函数来查找特定频率范围内的幅度。但我不确定我是否做得正确......如果有人可以查看代码,那就太好了。
感谢您的帮助!
%p2 is the data in the time domain
% Variables
fftlength = 1024; % Set FFT length
stepsize = 32; % Set step size
samples = fftlength:stepsize:length(p2); % create an index array
c = 1:fftlength;
%Specify hanning window
hanning = [1:fftlength]';
hanning_in = 2* pi() * (hanning - (fftlength+1)/2)/(fftlength+1);
%rescaled x-axis to match sample length?
hanning1 = (sin(hanning_in)./hanning_in).^2;
f=[128/fftlength:128/fftlength:128]; % frequency index for the spectral
array
bp_p2=cell(1,1);
channel=1;
for kk = 1:length(samples)
k = samples(kk);
spectrum = fft(p2(k-fftlength+1:k,:) .* hanning1)/fftlength; % apply window
to filtered data
spectrum2 =(sqrt(spectrum .* conj(spectrum))); % get magnitude uV
% theta (4-8),alpha (8-12),beta low(12-16), beta high(16-25)
theta=mean(interp1(f,spectrum2(:,channel),[4:f:8]));
alpha=mean(interp1(f,spectrum2(:,channel),[8:f:12]));
betalow=mean(interp1(f,spectrum2(:,channel),[12:f:16]));
betahigh=mean(interp1(f,spectrum2(:,channel),[16:f:25]));
%creating an array
%store all iteration loop outputs in a matrix
m(kk,:)=[theta alpha betalow betahigh];
end