Need help/ideas solving a problem
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hey all,
I have a problem I would like to solve, but am not even sure how to go about solving it. I have taken real motion data of sine wave form, but obviously the sine wave is not perfect. What I want to do is decompose this measured data so that I can extract a value for the variables (amplitude, phase, etc.) that make up this distorted sine wave. Then I want to find the error value of these variables from the ideal sine wave that I want. I have looked at some regression stuff, but I am not sure how I can use that for my application. So ideally, I would like to take some data and be able to tell exactly how much amplitude, phase error there is. Simple calculating this is not an option as the error coupld be caused by all error sources or combination of errors.
0 comentarios
Respuestas (3)
Geoff
el 1 de Mayo de 2012
You can have a go at using simple function minimisation: best fit
Start with a vector that represents all your shape characteristics: (amplitude, frequency, phase, offset)
x0 = [1, 10, 0, 0];
Make a function that generates a sine wave over a bunch of time values using those characteristics:
waveFn = @(x,t) x(1) * sin(t * 2*pi*x(2) - x(3)) + x(4);
Now you need to make that function into an objective function for minimisation. That is, a sum of square errors. Let's assume you have your motion values in the vector data and the corresponding time values in t. For this example, I'm just going to invent t.
t = 1:length(data);
objFn = @(x) sum( (data - waveFn(x,t)) .^ 2 );
Then you take a 'reasonable' initial guess, which can be quite unreasonable if you like because this is a simple sine-wave with presumably an obvious primary frequency... And you put that into fminsearch() - the bare-bones swiss army knife function solver.
options = optimset( 'MaxFunEvals', 10000, 'MaxIter', 500 );
x = fminsearch( objFn, x0, options );
Out pops your solved wave parameters, and you can generate the wave to test how good it looks. Hopefully it looks good.
dataFit = waveFn( x, t );
plot( [data(:) dataFit(:)] );
legend( 'Original', 'Fitted' );
You can play with your objective function. Declare a real function instead of an anonymous lazy-function, and you can do whatever you like to compare the data with the fit... You might want to do calculations on variance, or maximum error, or any number of things. Whatever number you spit out, remember that smaller means better.
Hope this is a help, and is actually relevant to what you are trying to achieve. =)
4 comentarios
Image Analyst
el 10 de Mayo de 2012
You know what really helps explain it better? A picture. Can you upload an image, screenshot, plot, whatever, to tinypic.com?
Image Analyst
el 1 de Mayo de 2012
I think it's best to avoid the noise in the first place. Not sure how you're acquiring the signal but you may want to consider a lock-in amplifier ( http://en.wikipedia.org/wiki/Lock_in_amplifier) which was invented for precisely this situation.
If you're stuck with the bad signal, you might look at the FFT or PSD (power spectral density) to get those parameters. They're built for that kind of thing, while a regression like polyfit() is not.
3 comentarios
Geoff
el 1 de Mayo de 2012
Perhaps you could post a plot of some of this data, or explain how 'perfect' it is supposed to be. Is it 2-dimensional, or 3-dimensional? If your wave characteristics keep changing over time, then you could determine how many samples make up a single wave cycle (or however many cycles should be expected to be constant), and piece-wise solve your curve in overlapping sections (much the same concept as moving averages), smooth the results, and you'll have a matrix that contains the full evolution of your waveform characteristics from the beginning to the end of your data.
Richard Brown
el 1 de Mayo de 2012
What does the distortion look like? (have you got a picture?) A least squares fit may or may not be appropriate depending on your noise ...
Wes
el 10 de Mayo de 2012
3 comentarios
Geoff
el 24 de Mayo de 2012
Great news! Glad you got it sorted =) I'd appreciate if you accepted my answer to close this question off correctly. If you need any more input on this feel free to send me a message through my user profile or just post another question to the community.
Ver también
Categorías
Más información sobre Simulation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!