I am having trouble smoothing my data.

3 visualizzazioni (ultimi 30 giorni)
daniel
daniel il 4 Mar 2015
Commentato: daniel il 5 Mar 2015
I have some data I need to do a bit of analysis on but I am having trouble getting it in the correct form. I have attached a fig for your viewing pleasure.
As you can see I have two set of data, one is beautiful (relatively smooth and continuous in red) the other is all over the place. The spikes you see are do to gap fills and I am not sure why it behaves this way but it seems that these "gap-fills" are interpolated data but scaled up. I need to connect the higher "gap-fills" with the lower values but I am not sure how to go about it. I have tried a few things but nothing is working as well as I'd like. First I got rid of the spikes and replaced them with NaN's then interpolated those gaps but it was not what I needed. Any help is appreciated! Thanks!

Risposte (1)

Image Analyst
Image Analyst il 4 Mar 2015
Why do you need the gaps filled instead of just removing them?
newSignal = signal(signal<6500);
newTimes = times(signal<6500);
plot(newTimes, newSignal);
If you really need the new, repaired signal at all the same times that the old signal has (for some reason, but why???), then use interp1
goodSignal = signal(signal<6500);
goodTimes = times(signal<6500);
repairedSignal = interp1(goodTimes, goodSignal, times);
  5 Commenti
Image Analyst
Image Analyst il 5 Mar 2015
daniel, let me try to make my case to you. I tried to recreate your signal by making a sine wave and then adding huge spiky noise to it. Then I removed the spikes and interpolated what's left. It gave a pretty darn good representation of the perfect cosine wave signal. It is not "very unrealistic", at least to my eyes. I think it looks great. What do you think?
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
times = 1 : 600;
signal = 50*cosd(times) + 6100;
% Add noise
randomLocations = randperm(length(signal), 100);
signal(randomLocations) = 8200;
% Plot it.
subplot(2, 1, 1);
plot(signal, 'b-', 'LineWidth', 2);
title('Original, Corrupted Signal', 'FontSize', fontSize);
grid on;
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Find "good" parts of the signal.
goodSignal = signal(signal<6500);
goodTimes = times(signal<6500);
repairedSignal = interp1(goodTimes, goodSignal, times);
subplot(2, 1, 2);
plot(repairedSignal, 'b-', 'LineWidth', 2);
grid on;
title('Repaired Signal', 'FontSize', fontSize);
daniel
daniel il 5 Mar 2015
This is isn't a pissing contest if you don't like my explanation it's cool, I am not here to get into an argument. I came on here to get some help, which I did. This isn't randomly generated data this is real life, I need as much of the original signal as possible. If you don't understand "why" I am sorry, enjoy your day ;)

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by