Extracting the specific range of data.
Show older comments
I have some signal data and its sampled time , sampled at 1000hz . i would like to create a function that helps me extract just the specific time ranged datas(20 seconds of data or 30 seconds as per my wish ) so that i can later perform spectrogramm analysis.While selecting the data range of some seconds i want to avoid large spikes casued due to the error of the sensor so i want to avoid taking 20 seconds of data that includes such irregularities. For that i employed while loop to check if that randomly selected data range has its min value smaller than the (mean -some number *standard deviation) of original data. Im struggling to get my function working. So any help is highly appreciated.
t_diff is to be taken as duration of data example 20 seconds of data or 40 seconds etc.
my problem lies on declaring the variables before the while loop and those variables are not storing the data processed by the while loop and the rand function is not generating random values per execution.
function [] = twentysecondtime(time,data,t_diff)
mee=std(data);
meen=mean(data);
ppg_seg=0;
time_seg=zeros(1,t_diff*1000);
while (min(ppg_seg)<meen-3*mee)
a = 0;
b = (length(time)/fs)-t_diff;
rng("shuffle");
r = (b-a)*rand(1,1) + a;
t_start=floor(r);
t_end=floor(r)+t_diff;
time_seg= time(find(time>=t_start,1):find(time>=t_end,1));
ppg_seg = data(find(time>=t_start,1):find(time>=t_end,1));
end
plot(time_seg,ppg_seg);
end
Answers (1)
Star Strider
on 12 Dec 2021
0 votes
I have no idea what the signal looks like. It is apparently recorded rather than being processed in real time.
To detect the spikes, use the findpeaks or islocalmax functions. Once the spikes are isolated and their positions known, finding suitable parts of the signal between them should not be difficult.
.
2 Comments
Anup Khadka
on 12 Dec 2021
If they’re negative spikes, use the negative of the signal with findpeaks, or the islocalmin function.
t = linspace(0, 20, 250);
y = randn(size(t));
[pks,locs] = findpeaks(-y, 'MinPeakHeight',2); % 'findpeaks' Call
TF = islocalmin(y, 'MinProminence',3.6); % 'islocalmin' Call
figure
subplot(2,1,1)
plot(t, y)
hold on
plot(t(locs), -pks, 'vr')
hold off
grid
title('findpeaks')
subplot(2,1,2)
plot(t, y)
hold on
plot(t(TF), y(TF), 'vr')
hold off
grid
title('islocalmin')
With large spikes, the two functions should return the same information, with the appropriate name-value pair arguments for each. Thje funcitons behave slightly differently. The findpeaks function also has MinPeakProminence that I susally use since it is more robust than MinPeakHeight so experiment with that as well.
.
Categories
Find more on Parametric Spectral Estimation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
