Home > vbmeg > functions > device > filter_func > vb_fftpower.m

vb_fftpower

PURPOSE ^

Calculate power spectrum using FFT

SYNOPSIS ^

function [p, f] = vb_fftpower(data, samplingrate)

DESCRIPTION ^

 Calculate power spectrum using FFT

 - Input
   data : Data (channel x time x trial)
   samplingrate : Sampling rate [Hz]

 - Output
   p : Power spectrum (channel x frequency x trial)
   f : Frequency label (1 x frequency)

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [p, f] = vb_fftpower(data, samplingrate)
0002 % Calculate power spectrum using FFT
0003 %
0004 % - Input
0005 %   data : Data (channel x time x trial)
0006 %   samplingrate : Sampling rate [Hz]
0007 %
0008 % - Output
0009 %   p : Power spectrum (channel x frequency x trial)
0010 %   f : Frequency label (1 x frequency)
0011 %
0012 % Copyright (C) 2011, ATR All Rights Reserved.
0013 % License : New BSD License(see VBMEG_LICENSE.txt)
0014 
0015 % Get the number of time points
0016 Nt = size(data, 2);
0017 
0018 % Rearrange dimensions
0019 rdata = permute(data, [2 1 3]);% time x channel x trial
0020 
0021 % Make frequency label
0022 f = (0:(Nt-1))*samplingrate/Nt;
0023 
0024 % Calculate power spectrum
0025 p = abs(fft(rdata)).^2/Nt/Nt;
0026 
0027 % Rearrange dimensions
0028 p = permute(p, [2 1 3]);% channel x frequency x trial
0029 
0030 % Make outputs
0031 p = p(:, 1:fix(Nt/2), :);
0032 f = f(1:fix(Nt/2));
0033

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005