How to remove negative peaks from a signal
13 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
sandhya sandhya
il 7 Set 2018
Modificato: sandhya sandhya
il 17 Set 2018
How to remove negative peaks from a signal
3 Commenti
Image Analyst
il 7 Set 2018
Define negative peaks. Is it everything between positive peaks? What does "remove" mean to you? Set to zero? Draw a line between the tips of the neighboring positive peaks? Delete the elements?
First read this link, then attach your data in a .mat file, and attach a screenshot of your data plotted plus an indication of what you'd like the signal to look like after the negative peaks are removed.
Risposta accettata
Image Analyst
il 8 Set 2018
sandhya, it looks like you didn't even read the comments above since there is no plot of what you are starting with, no plot of what you'd want as an output, and no explanation of what defines a negative peak (valley).
I wrote a program to smooth the data and remove valleys so that the final signal is just lines between the peaks of the noise-reduced signal.
% Custom program for sandhya to remove valleys from a signal.
clc; % Clear the command window.
clearvars;
close all; % Close all figures (except those of imtool.)
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
s = load('s4.mat')
val = s.val
subplot(2, 1, 1);
plot(val, 'b-', 'LineWidth', 2);
grid on;
xlabel('index', 'FontSize', fontSize);
ylabel('val', 'FontSize', fontSize);
caption = sprintf('val vs. index for %d elements', length(val));
title(caption, 'FontSize', fontSize);
% Signal is pretty noisy. Smmoth it with a Savitzky-Golay filter (moving quadratic).
filterWindowWidth = 91;
smoothedSignal = sgolayfilt(val, 2, filterWindowWidth);
subplot(2, 1, 2);
plot(smoothedSignal, 'b-', 'LineWidth', 2);
grid on;
xlabel('index', 'FontSize', fontSize);
ylabel('Smoothed Signal', 'FontSize', fontSize);
caption = sprintf('Smoothed Signal index for %d elements', length(val));
title(caption, 'FontSize', fontSize);
%------------------------------------------------------------------------------
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
% Get rid of tool bar and pulldown menus that are along top of figure.
% set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
% Find peaks in the smoothed signal - requires Signal processing Toolbox.
[peakValues, peakIndexes] = findpeaks(smoothedSignal,'MinPeakProminence', 3, 'Annotate', 'extents'); % Use default parameters
% Tack on first and last points.
peakIndexes = [1, peakIndexes, length(val)];
peakValues = [1, peakValues, val(end)];
% Plot results.
figure;
subplot(2, 1, 1);
plot(smoothedSignal, 'b-', 'LineWidth', 2);
hold on;
plot(peakIndexes, peakValues, 'rv', 'LineWidth', 2, 'MarkerSize', 10);
plot(peakIndexes, peakValues, 'r-', 'LineWidth', 1);
grid on;
xlabel('index', 'FontSize', fontSize);
ylabel('val', 'FontSize', fontSize);
caption = sprintf('Location of %d peaks', length(peakIndexes));
title(caption, 'FontSize', fontSize);
% Interpolate between peaks
allIndexes = 1 : length(val);
yInterp = interp1(peakIndexes, val(peakIndexes), allIndexes);
subplot(2, 1, 2);
plot(val, 'b-', 'LineWidth', 1);
hold on;
plot(allIndexes, yInterp, 'r-', 'LineWidth', 2);
grid on;
xlabel('index', 'FontSize', fontSize);
ylabel('fitted vals', 'FontSize', fontSize);
title('Final Signal in red with negative peaks (valleys) removed', 'FontSize', fontSize);
legend('Original Signal', 'Final, valleys-removed signal');
%------------------------------------------------------------------------------
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
% Get rid of tool bar and pulldown menus that are along top of figure.
% set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
I hope it's what you want. Since you didn't provide specifics, I guess you should be happy with anything that we do. I think I put more time into your problem than you did, so I hope my time was not wasted.
If it's not what you want, then re-read the comments above (under your original question at the top) and fix/improve your question.
10 Commenti
Image Analyst
il 15 Set 2018
OK, maybe if the questions are numbered you will notice them more than if they just ended with question marks:
- I also don't know what you define as a negative peak. Is it everything between positive peaks? If so, setting negative peaks to zero would just zero out the entire signal except for the very tips of the positive peaks, and that doesn't seem any good.
- Is it the part of your signal that is negative (has a value below zero)?
- When you detrend it, what functions and parameters to you use?
- Did you detrend()?
- Or did you use polyfit(), and if so, with what order?
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!