plotting PPG signal using PWL source

13 views (last 30 days)
abd-elRaoof
abd-elRaoof on 17 Oct 2023
Edited: Prasanna on 21 Oct 2024
hello sir ,
i want to plot PPG signal .csv or xlsx file using PWL source to plot ,
  • i have imported the datasheet to the editor ,how can we make variables that can be seen by simulink , PWL source ??
  • COULD the PWL source accept variables ?
i bulit the circiut consisting of : (PWL source - voltage sensor - PS simulink - scope ) to show the waveforn but it doesn't work -need solver config-
is there any another solution ??
excue me for my weak english
thanks

Answers (1)

Prasanna
Prasanna on 21 Oct 2024
Edited: Prasanna on 21 Oct 2024
Hi abd-elRaoof,
To plot a PPG signal from a source file using a piecewise linear (PWL) source in Simulink, you can do the following steps:
  • Load the PPG signal data file into MATLAB using ‘readmatrix and extract the corresponding time and signal values from the data.
  • After preparing the data for PWL source where the first column is time and second column is the signal value, configure the PWL source in Simulink and set the PWL vector of time-value pairs parameter to the PWL data.
  • Add a solver configuration block, connect the PWL source to the rest of the circuit and run the simulation to visualize the PPG result.
A sample code assuming the data is present in a file named ‘data.csv’ with the first column as time and second column as signal and a Simulink model with the name sim_model’ is given below:
% Load data
data = readmatrix('data.csv');
time = data(:, 1);
signal = data(:, 2);
% Prepare PWL data
pwl_data = [time, signal];
% Open Simulink model
open_system('sim_model');
% Set PWL Source data
set_param('sim_model/PWL Source', 'PWLVector', 'pwl_data');
% Run the simulation
sim('sim_model');
Some other points you can check if the waveform doesn’t show is to check the solver configuration connections and making sure that the ‘pwl_data’ variable is in the MATLAB workspace when running the Simulink model. If the PWL source is problematic, consider using a From Workspace block to import data directly into Simulink. For more information on the functions used, refer the following documentations:

Categories

Find more on Simscape in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!