Getting decrease in a sine wave as a function of time
이전 댓글 표시
I am trying to fit an exponential function to the peaks in a decreasing sinusoid:

I tried importing the values for time and position like this because the decimal places are marked with commas in my data that should be dots in MatLab:
% Open data file
fid = fopen('Data.csv');
% Read data file
readData = textscan(fid,'%f %f','HeaderLines',1,'Delimiter',',');
% Extract data from readData
time = readData{1,1}(:,1);
position = readData{1,2}(:,1);
% Plot data
plot (time,position,'bo-')
Is this correct? The plot looks odd. Attached Data.csv if one wanted to check. The file consists of two long columns of values.
Next I'm thinking of using the peakfinder (I am not sure about its input and output at all):
C = vertcat(time, position);
peakfinder(C)
And finally fit the values using polyfit? It should be in the form position = a * exp(-b * time) where a and b are constants. I think I should start something like this:
fit = polyfit(x, log(y), 1)
Where x and y for me are time and position from peakfinder, not sure how to write those at all.
댓글 수: 3
per isakson
2016년 12월 24일
편집: per isakson
2016년 12월 24일
- Concerning the decimal separator see http://uk.mathworks.com/matlabcentral/answers/57276-import-data-file-with-comma-decimal-point#answer_69283. Your code doesn't read the file correctly with R2016a.
- The Import Data tool interprets comma as decimal separator correctly.

 
- "to the peaks in a decreasing sinusoid"   see env_secant(x_data, y_data, view, side) by Andreas Martin
Star Strider
2016년 12월 24일
Thank you, Per. I didn’t realise there is a comma decimal separator. I solved that problem with textscan, then strrep, and str2double.
Daniel Holmberg
2016년 12월 24일
채택된 답변
추가 답변 (1개)
Roger Stafford
2016년 12월 24일
The data you show should probably be fitted with something like:
a*exp(-b*time)*sin(c*time+d)
with the four parameters, a, b, c, and d, to be adjusted. It’s known as an exponentially decaying sinusoidal signal.
카테고리
도움말 센터 및 File Exchange에서 Digital Filtering에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
