Effacer les filtres
Effacer les filtres

How to do I get the standard deviation from an eeg input signal in SImulink?

19 vues (au cours des 30 derniers jours)
Tania Akhtar
Tania Akhtar le 15 Mai 2024
Modifié(e) : Tania Akhtar le 15 Mai 2024 à 14:19
Hello I'm trying to make a function block that calculates standard deviation of the signal, as the standard deviation blocks do not give me the standard deviation of the SIMULINK signal (they either give me 0 or say it needs discrete values). However that doesnt work either, is there a way for me to get the standard deviationl? I want to equal the signal to 0 if the sdv is higher than a certain value.
I've tried the following but it isn't working.
function y = fcn(u)
std(u)
y = std(u)
end
my input is an eeg signal taken from the workspace using "from workspace" (simin)
  2 commentaires
Sam Chak
Sam Chak le 15 Mai 2024
Hi, could you provide a sample of the EEG data for testing if the algorithm for standard deviation works as expected?
Tania Akhtar
Tania Akhtar le 15 Mai 2024
Modifié(e) : Tania Akhtar le 15 Mai 2024 à 14:19
it doesn't work at the moment but the data used is from the CHB MIT dataset, and was inserted as shown below:
edfgsig = edfread('chb01_04.edf', 'SelectedSignals', 'FP1-F7');
data_array = table2array(edfgsig);
data_array6 = vertcat(data_array{:});
data = (data_array26375552:380672));
freqs = 256;
signlength = length(data);
time = (siglength -1)/fs;
t=0:1/256:time ;
time=t';
input = [time, data];
it looks somewhat like this
0 -79.9023199023199
0.00390625000000000 -66.6178266178266
0.00781250000000000 -56.8498168498169
0.0117187500000000 -49.4261294261294
0.0156250000000000 -38.0952380952381

Connectez-vous pour commenter.

Réponse acceptée

Sam Chak
Sam Chak le 15 Mai 2024
Since you're able to extract the EEG signal from the CHB-MIT Dataset and load it into the Workspace, it would be more efficient to directly compute the standard deviation in MATLAB. The standard deviation is a statistical measure used to quantify the amount of variation in a set of data values. It does not inherently depend on time.
However, Simulink executes the graphical block diagramming at each simulation time step. Thus, instead of using the 'simin' block, which includes a time stamp on the data values, you can feed the chunk of EEG data directly into the 'Constant' block and then connect it to the 'Standard Deviation' block or the 'Mean' block. This way, the statistical measures will be calculated accurately.
Solution in MATLAB:
input = [0 -79.9023199023199
0.00390625000000000 -66.6178266178266
0.00781250000000000 -56.8498168498169
0.0117187500000000 -49.4261294261294
0.0156250000000000 -38.0952380952381
0.0195312500000000 -27.5457875457875
0.0234375000000000 -17.7777777777778
0.0273437500000000 -11.1355311355311
0.0312500000000000 -11.1355311355311];
[S, M] = std(input(:,2))
S = 24.9802
M = -39.8318
%% For Simulink
t = input(:,1);
y = input(:,2);
simin.time = t;
simin.signals.values = [y];
simin.signals.dimensions = 1;
Solution in Simulink:
  2 commentaires
Tania Akhtar
Tania Akhtar le 15 Mai 2024
Thank you so much , this is exactly what I needed. I do have one more question only if possible, Is there any way at all to display the signal itself or make an if statement depending on the value of the standard deviation, if it's bigger than a certian value for exmaple? I'm trying to use the if blocks and if action blocks but not quite sure I'm connect the right elements
Sam Chak
Sam Chak le 15 Mai 2024
You're welcome! To display the signal, you have a couple of options. You can use either the Scope block or the Display block, depending on which one suits your specific application better.
On another note, if you're not familiar with the If-Action block or find it challenging to work with, an alternative approach would be to use the MATLAB Function block. This allows you to code the If-Else statement directly, and it might provide a clearer and more intuitive solution for the coder.

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 15 Mai 2024
The instantaneous standard deviation of a signal is 0.
Standard deviation normally depends on a complete population -- a complete set of discrete signals.
It might possibly make sense to create a "moving standard deviation" -- but you would have to be moving over a fixed time interval (rather than a fixed number of samples)... it would get a bit tricky to implement for continuous signals.

Catégories

En savoir plus sur EEG/MEG/ECoG dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by