Reading Excel XY Data and Interpolate

조회 수: 3 (최근 30일)
João
João 2014년 10월 16일
댓글: Matt Tearle 2014년 10월 16일
Hello,
I have +60k of X(time) and Y(position) data of a wave in excel. To read them I used xlsread comand. X=xlsread('A1Wave','A3:A65554'); Y=xlsread('A1Wave','B3:B65554');
I now need to interpolate them to find the function that goes through those points. How do I do this? What function do I use?
I also have to get the wave periods. Is there a way to have matlab calculate them? I mean, give me the list of values of when the function goes from negative to positive?
Thanks

채택된 답변

Matt Tearle
Matt Tearle 2014년 10월 16일
This is a pretty huge question -- it really depends what you're assuming about the data and, consequently, what you're trying to fit to it. In general, though, if the data represents a wave signal, you probably want to do an FFT to get the frequencies.
If, however, you know it's just a single frequency wave, then, to answer your specific question about getting the periods, you can do something like this:
% Generate some data (a single-frequency wave)
w = rand;
x = linspace(0,20,501);
y = sin(2*pi*w*x);
plot(x,y)
% Find where the signal goes from positive to negative
zerocross = (y(1:end-1)>0) & (y(2:end)<0);
periods = diff(x(zerocross))
% Get the mean period and compare to what it should be
disp(mean(periods))
disp(1/w)
One last side point: two calls to xlsread is unnecessarily slow. Get x and y together and split them in MATLAB:
data = xlsread('A1Wave','A3:B65554');
X = data(:,1);
Y = data(:,2);
  댓글 수: 2
João
João 2014년 10월 16일
Thanks, I'll look into what you've written. I'm not that good with matlab. However, you have generated data from a "known" wave function. I need to find the function from my data first. But I got the idea of what to do once i get the function.
Matt Tearle
Matt Tearle 2014년 10월 16일
Right. Without having your data, I just created something with a single frequency. But, as I said, doing what I did really requires an assumption that your data does come from a single-frequency source (with unknown frequency that you can figure out). Otherwise, you should use an FFT to determine the dominant frequencies in the signal. After that, if you wanted to, you could model the signal by fitting a particular Fourier series to the data. Once you know the frequencies in your model, that becomes a linear regression problem, and you can use \ in base MATLAB or regress in Statistics Toolbox.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Correlation and Convolution에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by