Getting decrease in a sine wave as a function of time
Mostrar comentarios más antiguos
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 comentarios
per isakson
el 24 de Dic. de 2016
Editada: per isakson
el 24 de Dic. de 2016
- 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
el 24 de Dic. de 2016
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
el 24 de Dic. de 2016
Respuesta aceptada
Más respuestas (1)
Roger Stafford
el 24 de Dic. de 2016
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.
1 comentario
Daniel Holmberg
el 24 de Dic. de 2016
Categorías
Más información sobre Digital Filtering en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
