フィルターのクリア

how do I plot Realtime ecg data acquired from max30001 on MATLAB?

1 回表示 (過去 30 日間)
Muhammad Hadi Qureshi
Muhammad Hadi Qureshi 2022 年 12 月 20 日
編集済み: Rahul 2023 年 1 月 6 日
Hey,i am beginner and working on my research project.I have MatlabR2018a
I aquried data using max30001 for 60 seconds.I used "importfile" to import the data in matlabI tried"csvread" but it was giving error.I am attaching a picture of what i got after importing .
I want to use all the rows and only the ECGmv coloumn for plotting and doing futher work.Can you please tell me how to plot that.And please correct me if i am wrong,i am supposed to use only the ECGmv coloumn for plotting ,applying filters and feature extraction of ecg?

採用された回答

Rahul
Rahul 2023 年 1 月 4 日
編集済み: Rahul 2023 年 1 月 6 日
From the figure above, the file name is "4o.csv" and it contains the information acquired using MAX30001 for 60 seconds. you can read the CSV file using "readtable" function. Please check the code below:
Solution 1: Usual way
Note: You can extract any column by typing the variable name ("T") followed by .(dot) and tab key. This will list all available column names in the table data.
>> filename = 'C:\Users\ACER\Desktop\fyp\data\4o.csv';
>> T = readtable(filename, 'VariableNamesLine', 1, 'VariableNamingRule', 'preserve');
>> % Type the variable T followed by .(dot) and then press tab key on keyboard.
>> ECGmvdata = T.("ECG (mV)"); % extracting only ECGmv column
>> plot(ECGmvdata) % plotting ECGmv column
There is also another way to access and extract the ECG column data. In the image shared after importing the data, click on "Import Selection" button and click on "Generate Script" or "Generate Function". Please find the examples below of script as well as function
Solution 2: By Generating a function
function o1 = importfile_csv_data(filename, dataLines)
%IMPORTFILE Import data from a text file
% O1 = importfile_csv_data(FILENAME) reads data from text file FILENAME for the
% default selection. Returns the data as a table.
%
% O1 = importfile_csv_data(FILE, DATALINES) reads data for the specified row
% interval(s) of text file FILENAME. Specify DATALINES as a positive
% scalar integer or a N-by-2 array of positive scalar integers for
% dis-contiguous row intervals.
%
% Example:
% o1 = importfile_csv_data("C:\Users\ACER\Desktop\fyp\data\4o.csv", [2, Inf]);
%
% See also READTABLE.
%
% Auto-generated by MATLAB on 06-Jan-2023 14:15:13
%% Input handling
% If dataLines is not specified, define defaults
if nargin < 2
dataLines = [2, Inf];
end
%% Set up the Import Options and import the data
opts = delimitedTextImportOptions("NumVariables", 11);
% Specify range and delimiter
opts.DataLines = dataLines;
opts.Delimiter = ",";
% Specify column names and types
opts.VariableNames = ["Times", "ECG_DATA170", "ETAG20", "PTAG20", "ECGmV", "ECGFilteredmV", "FilterType", "LDOFF_PH", "LDOFF_PL", "LDOFF_NH", "LDOFF_NL"];
opts.VariableTypes = ["double", "double", "double", "double", "double", "double", "categorical", "string", "string", "string", "string"];
% Specify file level properties
opts.ExtraColumnsRule = "ignore";
opts.EmptyLineRule = "read";
% Specify variable properties
opts = setvaropts(opts, ["LDOFF_PH", "LDOFF_PL", "LDOFF_NH", "LDOFF_NL"], "WhitespaceRule", "preserve");
opts = setvaropts(opts, ["FilterType", "LDOFF_PH", "LDOFF_PL", "LDOFF_NH", "LDOFF_NL"], "EmptyFieldRule", "auto");
% Import the data
o1 = readtable(filename, opts);
end
and then call the function in the command window/editor as follows:
% calling the function
o1 = importfile_csv_data("C:\Users\ACER\Desktop\fyp\data\4o.csv", [2, Inf]);
ECGmvdata = o1.ECGmV;
plot(ECGmvdata)
Please check the variable "opts.VariableNames" in the function file above. The fifth column is named "ECGmV".
Solution 2: By Generating a script
If you generate a script, it would look like as given below. Please check the variable "opts.VariableNames" in the code. The fifth column is named "ECGmV".
%% Import data from text file
% Script for importing data from the following text file:
%
% filename: C:\Users\ACER\Desktop\fyp\data\4o.csv
%
% Auto-generated by MATLAB on 06-Jan-2023 12:40:58
%% Set up the Import Options and import the data
opts = delimitedTextImportOptions("NumVariables", 11);
% Specify range and delimiter
opts.DataLines = [2, Inf];
opts.Delimiter = ",";
% Specify column names and types
opts.VariableNames = ["Times", "ECG_DATA170", "ETAG20", "PTAG20", "ECGmV", "ECGFilteredmV", "FilterType", "LDOFF_PH", "LDOFF_PL", "LDOFF_NH", "LDOFF_NL"];
opts.VariableTypes = ["double", "double", "double", "double", "double", "double", "categorical", "string", "string", "string", "string"];
% Specify file level properties
opts.ExtraColumnsRule = "ignore";
opts.EmptyLineRule = "read";
% Specify variable properties
opts = setvaropts(opts, ["LDOFF_PH", "LDOFF_PL", "LDOFF_NH", "LDOFF_NL"], "WhitespaceRule", "preserve");
opts = setvaropts(opts, ["FilterType", "LDOFF_PH", "LDOFF_PL", "LDOFF_NH", "LDOFF_NL"], "EmptyFieldRule", "auto");
% Import the data
o = readtable("C:\Users\ACER\Desktop\fyp\data\4o.csv", opts);
%% Clear temporary variables
clear opts
ECGmvdata = o1.ECGmV;
plot(ECGmvdata)

その他の回答 (1 件)

Muhammad Hadi Qureshi
Muhammad Hadi Qureshi 2023 年 1 月 6 日
編集済み: Muhammad Hadi Qureshi 2023 年 1 月 6 日
hey i used the code but it is not exctracting the coloumn.It is givng the following error.i am attaching screenshot.
  5 件のコメント
Muhammad Hadi Qureshi
Muhammad Hadi Qureshi 2023 年 1 月 6 日
hey i am uploading the csv file.
Rahul
Rahul 2023 年 1 月 6 日
I have re-edited the answer above. Please check and contact if you have any issues.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by