Interpolation using max peak value and curve after optical filter

3 visualizaciones (últimos 30 días)
Seejal Padhi
Seejal Padhi el 31 de Oct. de 2022
Respondida: Gokul Nath S J el 26 de Mayo de 2023
If I have the max peak value in the desired integration time of the spectral data through a linear trend, and the spectral data of the desired integration time with an optical filter, how do I interpolate to get the area under the curve using those 2 data?

Respuestas (1)

Gokul Nath S J
Gokul Nath S J el 26 de Mayo de 2023
Hi Seejal,
To interpolate the area under the curve from the peak values using MATLAB, you can use the 'trapz' function to numerically integrate the data in the desired integration time interval. Here's an example code that demonstrates how to do this:
% Define the integration time interval
t_start = 0; % Start time (s)
t_end = 1e-3; % End time (s)
sampling_rate = 1e6; % Sampling rate (Hz)
t = linspace(t_start, t_end, (t_end-t_start)*sampling_rate);
% Define the spectral data with linear trend
y_linear = 1e-3*t + 0.1*randn(size(t));
% Define the spectral data with filter
y_filtered = randn(size(t));
[b, a] = butter(2, [1e4, 5e4]/(sampling_rate/2));
y_filtered = filter(b, a, y_filtered);
% Find the maximum peak value in the integration time
[t_peak_linear, idx_peak_linear] = max(y_linear(t>=t_start & t<=t_end));
[t_peak_filtered, idx_peak_filtered] = max(y_filtered(t>=t_start & t<=t_end));
% Interpolate the data in the integration time interval
y_linear_int = interp1(t, y_linear, t_start:1/sampling_rate:t_end);
y_filtered_int = interp1(t, y_filtered, t_start:1/sampling_rate:t_end);
% Compute the area under the curve
area_linear = trapz(y_linear_int);
area_filtered = trapz(y_filtered_int);
% Display the results
fprintf("Linear trend: peak value = %f, area = %f\n", t_peak_linear, area_linear);
fprintf("Filtered signal: peak value = %f, area = %f\n", t_peak_filtered, area_filtered);
In this example, the integration time interval is defined between t_start and t_end, and the time vector t is created at a high sampling rate using linspace. Two sets of spectral data are defined: y_linear with a linear trend and y_filtered with a filter.
The max function is used to find the maximum peak value of each data set in the integration time interval, along with its corresponding index. Then, the interp1 function is used to interpolate the data sets onto a regular grid with sample rate of 1/sampling_rate.
Finally, the trapz function is used to integrate the interpolated data sets over the integration time interval to obtain the area under the curve. The results are displayed using the fprintf function.
with regards,
Gokul Nath S J

Categorías

Más información sobre Electrophysiology en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by