How do I interpolate the remaining part of my signal?

6 次查看(过去 30 天)
I am working on this side project, which involves removing the artefact of a given nerve conduction signal. It's going quite well; I have implemented the a butterford signal and extract the the major onset artefact. However, now I would like to repair the signal which has been extracted.
Here's comparison between the singal before (blue) and after(orange) it has been filtered.
I figured that I can solved this issue by via interpolation. However, I keep getting the same error about how "X must be a vector of double or single". Any suggestions how I can resolve this issue . Also, I am still learning and my experience is only surface level. So any suggestions to make the function more efficient would be greatly apreciated.
Here is my function so far.
function[wave1, wave2] = NCS(file)
%Allowing the user to take the raw data of a Nerve Conduction Study
%And Plots it out in the form of a wavefunction
data = xlsread(file,1, 'B12:B651');
data = -data;
%This program assumes certain settings
%Please ensure that the study have
%settings as follows Amplitude Sensitivity = 60µV Timebase = 20msec
xt =(linspace(0,0.3008,640)')*100;
%Multiplies x by 100 to convert the x-axis to msec
y = data;
%First plots the signal, unfiltered
wave1 = plot(xt,y); xlabel('Time (msec)'), ylabel('Amplitude (µV)'),
title('Sural Nerve Conduction Study'), xlim([0 20]);
%holds it for comparison
hold on
Fs = 640; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
%Butterworth bandpass filter
fcutlow = 3;
fcuthigh = 60;
[b,a] = butter(2,[fcutlow,fcuthigh]/(Fn), 'bandpass');
Data = detrend(data);
Fy = Data;
Fy = filter(b,a,y);
%Knowing the latency is never later than 2msecs, this line
%implemented to elimate the onset artefact
Fy (xt>0 & xt<2.2)=nan;
%Attempt to interpolate
xs = ~isnan(xt);
ys = ~isnan(Fy);
yi = interp1(xs,ys,xt, 'spline');
%plots filtered data
wave2 = plot(xt,yi);
end

采纳的回答

Star Strider
Star Strider 2021-7-9
If you have R2016b or later, see if the fillmissing function will do what you want.
.
  2 个评论
Karol Dunne
Karol Dunne 2021-7-9
Thank you. I also changed it to Linear to make it more aesthetically pleasing.
Star Strider
Star Strider 2021-7-9
As always, my pleasure!
Aesthetics are definitely important!
.

请先登录,再进行评论。

更多回答(1 个)

KSSV
KSSV 2021-7-9
These lines:
xs = ~isnan(xt);
ys = ~isnan(Fy);
yi = interp1(xs,ys,xt, 'spline');
should be:
% xs = ~isnan(xt);
idx = ~isnan(Fy);
yi = interp1(xs(idx),ys(idx),xt, 'spline');

Community Treasure Hunt

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

Start Hunting!

Translated by