Assigning features to the matrix based on windowing

5 次查看(过去 30 天)
Hello,
At the beginning I have at my disposal file with 3 columns (signal sample, condition, device):
-297.367190000000 8 1
-295.132890000000 8 1
-282 8 1
-268.007000000000 8 1
-262.109380000000 8 1
-263.296880000000 8 1
-263.562500000000 8 1
-258.973210000000 8 1
-255.209820000000 8 1
-252.130060000000 8 1
-247.141450000000 8 1
-244 8 1
-243.025000000000 8 1
-237.704170000000 8 1
-230.770830000000 8 1
-230.597220000000 8 1
-239.697970000000 8 1
-254.455570000000 8 1
-268.051250000000 8 1
-269.360000000000 8 1
-255.611150000000 8 1
100.781000000000 3 2
54.1178190000000 3 2
25.2507100000000 3 2
23.8387100000000 3 2
46.2026210000000 3 2
49.5785290000000 3 2
20.7356310000000 3 2
-16 3 2
-73.7242630000000 3 2
Then using a the presented code for windowing I extract the following features:
fs = 256;
sbin=4;
%sbin = 1; %1s
window=fs*sbin;
overlap=fs;
Nwin = floor((length(data)-window)/overlap)+1;
for k=1:Nwin
feature{1,1}(k) = var(data(1,(k-1)*overlap+1:(k-1)*overlap+window));
[Higuchi_FD(k)] = feature2(data(1,(k-1)*overlap+1:(k-1)*overlap+window),window);
feature{2,1}(k) = feature2(k);
[Katz_FD(k)] = feature3(data(1,(k-1)*overlap+1:(k-1)*overlap+window));
feature{3,1}(k) = feature3(k);
for instance it gives the following results (the information is included in the rows):
{[ 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.02 0.02 0.01 0.01 0.01 0.01 0.01 0.01 ]}
{[ 1.21 1.21 1.20 1.21 1.22 1.21 1.21 1.21 1.21 1.20 1.21 1.21 1.20 1.21 1.21 1.20 1.19 ]}
{[ 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 ]}
At the end I need to assign the information about condition and device to the windowed features. There 9 condition and 3 devices. How to perform that?
Regards
Elzbieta
  1 个评论
Voss
Voss 2024-9-6
Please share all code and data necessary for us to run the code you've shown here. You can upload files using the paperclip button.

请先登录,再进行评论。

回答(2 个)

Shishir Reddy
Shishir Reddy 2024-9-6
Hey Elzbieta
Assigning the information about condition and device to the windowed features can be done by determining the most frequent condition and device for each window and assigning them to the features. This can be implemented as shown in the following code snippet -
for k = 1:Nwin
start_idx = (k-1) * overlap + 1;
end_idx = (k-1) * overlap + window;
windowed_data = signal_samples(start_idx:end_idx);
windowed_conditions = conditions(start_idx:end_idx);
windowed_devices = devices(start_idx:end_idx);
features{1, 1}(k) = var(windowed_data);
features{2, 1}(k) = feature2(windowed_data, window); % Assuming feature2 is defined
features{3, 1}(k) = feature3(windowed_data); % Assuming feature3 is defined
conditions_windowed(k) = mode(windowed_conditions); % or conditions(start_idx)
devices_windowed(k) = mode(windowed_devices); % or devices(start_idx)
end
Within each window, the condition and device are determined. As conditions or devices may vary within the window, the most frequent value (‘mode’ in MATLAB) is taken.
This approach ensures that each set of features extracted from a window is accurately labelled with the appropriate condition and device.
I hope this helps.
  1 个评论
Elzbieta
Elzbieta 2024-9-6
Thank you for your answer. However the the order of fragments containing the same condition and device may be different from that resulting from for loop. In addition, the windows are of different lengths

请先登录,再进行评论。


Image Analyst
Image Analyst 2024-9-6
Why not just tack on the condition and device as the last two rows in your loop?
feature{4}(k) = data(k, 2);
feature{5}(k) = data(k, 3);

Community Treasure Hunt

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

Start Hunting!

Translated by