Having trouble smoothing waveform data
17 views (last 30 days)
Show older comments
So, my problem is as follows: I have an experimentally obtained data set that is sinusoidal in form, with varying frequencies and amplitudes.
My problem is that the waveform has mini-peaks, or jitter, throughout the wave, and I cannot figure out a way to eliminate them. I have tried matlab's cftool and also medfilt1 without luck; the problem is that this jitter is sort of embedded in the wave, which if necessary I can provide a sample of. Essentially, just picture a sin-shaped wave with little parabolic jitters spread throughout the waveform.
Does anyone have any suggestions how I can go about eliminating these?
0 Comments
Answers (2)
Image Analyst
on 22 Mar 2014
Use the Savitkzy-Golay filter with order 3 or 5. It will smooth it right out. Post your data if you want a demo.
As you know, the sine wave can be estimated as a Taylor series so with enough terms and the proper window size in the Savitzky-Golay filter you should be able to get a reasonable sine wave out. The SG filter does a fit to a polynomial in a sliding window, so sliding a 5th order or 3rd order polynomial over a sine wave would be fine.
% Set up parameters.
polynomialOrder = 5;
windowWidth = 9;
% Savitzky-Golay sliding polynomial filter
smoothY = sgolayfilt(y, polynomialOrder, windowWidth);
2 Comments
Image Analyst
on 22 Mar 2014
With your data:
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 = 25;
folder = 'C:\Users\ag123\Documents';
fullFileName = fullfile(folder, 'temp_data1.mat');
s = load(fullFileName);
% Get thea noisy sine wave signal
y = s.temp_data1;
% Get the x data
x = 1 : length(y);
subplot(2,1,1);
plot(x, y, 'b-', 'LineWidth', 2);
grid on;
title('Noisy Signal', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
% Now smooth with a Savitzky-Golay sliding polynomial filter
windowWidth = 161
polynomialOrder = 5 % Try 3 or 5 or 7
smoothY = sgolayfilt(y, polynomialOrder, windowWidth);
subplot(2,1,2);
plot(x, smoothY, 'b-', 'LineWidth', 2);
grid on;
title('Smoothed Signal', 'FontSize', fontSize);
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!