How to sample data at set intervals and then plot?
Show older comments
I am currently trying to create code that samples ECG data at certain intervals and extracts the maximum value between each interval. I believe my code does this as the ouput A returns the peaks of the data. However when i try and then plot these peaks it instead plots it as the sample number. E.g. one of my peaks is 257 in amplitude but the graph plots it as the 257th sample instead of the sample corresponding to the max value. I have attched an example of what my code plots. Any help is greatly appreciated!
ECG = load('ECG.csv');
Fs = 350;
frame_duration = 0.5;
frame_len = frame_duration*Fs;
N = length(ECG);
num_frames = floor(N/frame_len);
Time = (0:length(ECG)-1)/Fs; %Number of samples divided by frquency
Amp = ECG(:,1); %ECG Amplitude
hold on
for k = 1:num_frames
frame = ECG((k-1)*frame_len + 1: frame_len*k);
max_val = max(frame);
if (max_val > 100)
A = max_val
figure
plot(Time,Amp,Time(A),Amp(A),'r*')
end
hold off
end
1 Comment
KALYAN ACHARJYA
on 5 Jan 2020
Ensure that A must be vector (array).
Accepted Answer
More Answers (1)
David Hill
on 5 Jan 2020
ECG = load('ECG.csv');
Fs = 350;
frame_duration = 0.5;
frame_len = frame_duration*Fs;
N = length(ECG);
num_frames = floor(N/frame_len);
Amp = ECG(:,1)'; %ECG Amplitude
Amp = Amp(1:num_frames*frame_len);
Time = (0:length(Amp)-1)/Fs;
amp = reshape(Amp,frame_len,num_frames);
[mamp,idx] = max(amp);
Idx=(find(mamp>100)-1)*frame_len + idx;
plot(Time,Amp,Time(Idx),mamp(Idx),'r*');
2 Comments
ImperialStar
on 5 Jan 2020
David Hill
on 5 Jan 2020
ECG = load('ECG.csv');
Fs = 350;
frame_duration = 0.5;
frame_len = frame_duration*Fs;
N = length(ECG);
num_frames = floor(N/frame_len);
Amp = ECG(:,1)'; %ECG Amplitude
Amp = Amp(1:num_frames*frame_len);
Time = (0:length(Amp)-1)/Fs;
amp = reshape(Amp,frame_len,num_frames);
[mamp,idx] = max(amp);
Idx=(find(mamp>100)-1)*frame_len + idx;
plot(Time,Amp,Time(Idx),Amp(Idx),'r*');
This should work. Could not test without the ECG.csv file.
Categories
Find more on AI for Signals 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!