How do I use the buffer function to operate real time on EEG signal files?
3 次查看(过去 30 天)
显示 更早的评论
Hello, I've got a code where I detect signals through thresholding, but I'd like for the thresholding to reapply to the signal every 40 seconds or so if I enter a 5 minute signal. I've found buffering can help with this, but I am having some issues applying it. I want to segment the signal into 40 second segments (can be overlapping or non overlapping), however since the original signal (300 seconds) has been multiplied by the frequency 256, it is now 76800 values and I'm slightly confused. I am not sure which variables to alter, and the wiki example doesn't seem to apply to my signal type. I help appreciate some help understanding how the function works and how to apply if possible.
eegsignal = (data_array2(710656:787456)); %signal to be inserted around 5 mins long
%contains non-seizure and then seizure
fs = 256;
frame_length = 40
signal_length = 300*256
sig = buffer(1:76800,40);
n = 5;
p = 1;
opt = -5;
z = [];
for i = 1:size(sig,2)
x = sig(:,i);
[y,z,oppt] = buffer([z;x],n,p,opt);
if i <= 4
disp('no seizure')
end
opt = oppt;
end
0 个评论
回答(1 个)
Star Strider
2024-5-12
I seriously doubt that MATLAB can do real-time signal processing, unless you are also useing the Data Acquisition Toolbox and appropriate hardware with it. (I have never done that, always using recorded signals.)
That aside, to use the buffer function, it uses the number of samples as the second argument. That can easily be caluculated as:
samples = desired_secondds * sampling frequency
so here that would be —
sampling_frequency = 256; % Hz
segments = 40; % Segment Length (seconds)
samples = sampling_frequency * segments % Samplse/second * Seconds = Samples
A 300 second signal sampled at 256 Hz would be —
Signal_Total_Time = 300;
Signal_Length = Signal_Total_Time * sampling_frequency
You can only segment your signal in this number of frames —
NrFrames = Signal_Total_Time / segments
The buffer function will return 8 frames (columns) with the last 5120 entries in the last column set to 0.
Most EEG signals are sampled at at least i kHz. Your sampling frequency may not capture all the details.
.
2 个评论
Star Strider
2024-5-12
Seizures are different. For example absence seizures are characterised by 3 Hz spike-wave characteristics. If you are classifying them, there may already be lilterature on that. If you have not already done so, do a PubMed search.
My approach should work for recorded signals.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Biomedical Signal Processing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!