Need help/ideas solving a problem
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(3 个)
Geoff
2012-5-1
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 个评论
Image Analyst
2012-5-10
You know what really helps explain it better? A picture. Can you upload an image, screenshot, plot, whatever, to tinypic.com?
Image Analyst
2012-5-1
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 个评论
Geoff
2012-5-1
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
2012-5-1
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 ...
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Simulation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!