How to fill a large gap in a sine wave?

4 views (last 30 days)
Hi, this is a follow up to a previous question of mine. I am trying to fill a gap in a sine wave using the fillgaps function as described here - https://uk.mathworks.com/help/signal/examples/reconstructing-missing-data.html#ReconstructingMissingDataExample-6
I have tried to do this but as you can see in my image below, it is not working for me. It is drawing a straight line instead of correctly predicting the wave.
Below is an image of the code I am using in matlab:
Could someone please advise me on what I might be doing wrong? Do I need to use another function instead? Thanks in advance for your help.
MATLAB release version: 9.5.0.1298439 (R2018b) update 7
  3 Comments
carolina
carolina on 23 Jul 2020
I see, thanks for your reply. Do you know what the maximum gap that can be filled is?
KSSV
KSSV on 23 Jul 2020
If the data is periodic ... one can replace the missing data with existing ...

Sign in to comment.

Accepted Answer

Roger J
Roger J on 23 Jul 2020
You can try something like the following:
temp_reconstructed = fillgaps(tablecomplete.table_temperature,80,50);
Where I have maximum prediction-sequence length of 80 samples and a model order of 50. I don't know what you will use for your data, but you can play around with it.
  3 Comments
carolina
carolina on 27 Jul 2020
Thanks for your help. I have some long gaps with 8000 samples covering approximately two months from some weather stations. I specified the maximum number of samples and the model order with the function fillgaps() and it does work with my datasets. I decided not to interpolate weather stations with long gaps of more than 8000 samples.
I have another question about when I specify the model order - how can I determine it correctly when I have a long gap and a short gap with few samples in the same signal?
neil jerome
neil jerome on 27 Jul 2020
this will get a bit philosophical! for a small and large gap in the same data, if you find an acceptable answer for the long gap then it should also fill the short gap satisfactorily, although this would be vastly overpowered compared to what you would need if there were only the small gap. but you should probably use the same parameters for both gaps, since you are (probably) implicitly assuming that the data has the same underlying properties throughout. but some might argue that you should try to use the minimum necessary assumptions to create an answer, which would mean a reduced order/points for small gaps. again, i would use known data, deliberately blank out sections of your choice, and then try to recreate using different strategies and then compare back to the truth. but then you would ideally try this for all combinations of missing data and gap size, so you can easily get into a mess. the important thing is to explicitly recognise which assumptions you're making :)
so when you say 'correctly' determine, that might be a wild goose chase, so be careful. the bottom line is that the missing data simply isn't there, so you cannot ever know what is actually correct. something strange might have happened in the weather that day and you will never know! what you are doing is artificially creating data that 'doesnt look wrong', but not more than that! it doesn't - cannot - add more information than you already have, and in the worst case could be misleading (if something weird really did happen that day, and you recreated a normal day to sit in its place). if your analysis can't cope with missing data, adding in artificial data that is based on the extant data can only ever mimic the information already there, so what are you really adding? anyway, you see what i mean about getting philosophical! the criteria for 'success' are yours to decide, so in the end it depends what your goal is, and as long as you state exactly what you did (and why).
just my thoughts :)

Sign in to comment.

More Answers (0)

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!