How to scale a dataset to fit an other dataset?

I am working on a filter for a heartbeat sensor. Therefore I want to fit a 'perfect' heart beat graph (without noise) onto a signal with noise. Is there a function in matlab to scale the 'perfect' data such that it fits onto the signal with noise?
Since a heart rate is not constant, the perfect graph needs to be scaled in both amplitude and time/frequency in order to fit it onto the signal with noise.

 采纳的回答

Hi,
I recently found about Savitzky-Golay filter, which I think you will like it very much for your application.
Have a look at MATLAB help for
doc sgolay
Hope this helps.

9 个评论

Thank you for your answer. However, this Savitzky-Golay filter is a smoothing filter which is not what I am looking for.
The current problem I am facing is that the sensor loses contact occasionally and thus intruduces a change in the signal (motion noise). This changes the graph and does not introduce 'regular' noise like gausian or white noise.
You could see it as a sine function that flatlines for the timespan of one period of the the sine. I was hoping that there is a matlab function where you could use two datasets as an input (in this case a regular sine and the sine that flatlines at a certain point in time) that fits them together and returns the parameters with which it changed one of the datasets.
Humm!
Sounds like a curve fitting problem?! Is it like you want to extract the frequency of the semi sine wave generated by the detaching effect? Or you want to detect when the sensor is detached based on the sinusoidal pattern that you get in the signal?
Yes it is a fitting problem. I know how to fit a curve generated by a function, but this time the curves aren't generated by a function, but by a set of data.
The goal is to extract the frequency. If I could fit a perfect heart beat signal onto the signal with motion artifacts, I could use the parameters that are used to fit the curves to calculate the frequency/heart rate.
@Thomas
I'm not sure if interp1 is the solution.
@rolest
Still a bit unclear for me what you want to do, does your heart beat signal has a particular shape that can be described by some mathematical functions?!
If you want to measure the heart bit, you can extract a single heart bit manually and find the correlation between the extracted heart bit pulse with the rest of your data.
As a result of this you will get an output which is maximum when you have a similar signal in your data. And then you have to extract the maximums.
Is this satisfying?
It could be possible to recreate a heart beat signal with a mathematical function, but since the shape of such function could differ between different persons this is not an ideal solution.
I am writing a matlab script that first records a heart beat signal without moving the sensor and retrieve the heart rate from that signal. Then, when one goes for a walk during the measurements for example, the sensor will obviously move and thus introduce unwanted artifacts. That is where the fitting comes in: I want to fit the steady recorded signal with the signal that has the artifacts and retrieve the parameters with which the steady signal has been changed in order to fit.
I created a simulated heartbeat signal with
if true
x = linspace(0,200,400)
A = %horizontal scale
B = %vertical scale
C = %vertical offset
D = %horizontal offset
signal = B*sin((x+D)*A)+B*0.75*sin(2*(x+D)*A)+C;
end
Now if I plot this signal together with the measured data we get this plot (with some guessed values for A, B, C and D): http://imgur.com/SOq7gqB
Here black is the measured signal and blue the result of the signal function.
I want to write a program that automatically defines the values A, B, C and D such that this plot is the result (I did this manually): http://i.imgur.com/x9Uyd67.png
Cool! It's getting interesting now! And the more I amaze there are more chances that I actually won't be able to help.
Thanks so much for the graphs! I like them.
So let me review what I learned.
D determines the phase shift of the sin waves, and A is the frequency. I believe you can ignore D, unless you really wanna fit the data, which I think you just want to measure the heart bits.
A can be found either by taking an fft of the signal and observe its frequency spectrum which gives you the A or, even easier, you can get two consecutive peaks and measure the time in between peaks which give you T (period of the sin wave).
For this specific case, two sin waves are orthogonal so when one is max the other one is zero! One has a frequency twice the other one. So if you find max and min of the signal, their difference divided by two will corresponds to B. And I guess C is the max + min of the signal.
If you need D for sure, you have to define a source in time, lets say phaseshift is relative to the peak you can get the total number of samples before the first max or mean, this time can be converted to phase shift.
BTW, this is not a MATLAB question really!!
Give it a try.
Thank you a lot!
It started out as a MATLAB question as I was wondering whether there was a function that defines all the parameters A, B, C, and D (or something similar) automatically by creating the best possible overlap. But it seems that such function is not available in MATLAB and needs to be created by myself.
The biggest problem is still finding the value for A as the fft gives multiple peaks and I need to figure out a way to automatically select the one I need. Looking at the difference between two peaks in the measured data is not an option as the motion artifacts screw up that data.
Again thank you for your advise, it has helped me a lot!
Dear Roelst,
I'm glad that it helped.
If you have curve fitting toolbox, you may wanna have a loot at the fitting options, type cftool in command window and you will see the GUI
cftool
As far as I remember there are built in sin wave fittings, using multiple sins, you can even define your own custom function if you like.
Have a look at that, it may help you with the fitting.

请先登录,再进行评论。

更多回答(1 个)

Community Treasure Hunt

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

Start Hunting!

Translated by