필터 지우기
필터 지우기

Omit detrending in certain portion of signal

조회 수: 5 (최근 30일)
Konvictus177
Konvictus177 2022년 3월 22일
댓글: Mathieu NOE 2022년 3월 24일
Hello,
I have a signal with a certain portion that is much higher than the rest of the signal.
How can I avoid applying detrending to this portion but apply detrending to everything to the left and right of this signal? Blue portion should be detrended. Red portion should not be detrended and stay at this or a similar level.
What if I have two of these red portions within my signal? For example the lower peak portion in the middle and the higher portion to the right. Do not detrend both portions?
Thanks.
  댓글 수: 2
Mathieu NOE
Mathieu NOE 2022년 3월 22일
hello
We can better help you if you share data (and code ?)
tx
Konvictus177
Konvictus177 2022년 3월 22일
Here is the signal.
Currently I would do simple detrending but this would detrend the entire signal. I want the portions that are high (red) and the lower peak portion in the middle not to be detrended. Detrending the entire signal elevates my lower peak and lowers the higher portion of the signal. Espcially the poitns surrounding the higher portion.
% detrend signal
signal_detrended = detrend(signal,9);
% plot test signal
figure()
plot(signal)
hold on
plot(signal_detrended)
legend("before detrending","after detrending")

댓글을 달려면 로그인하십시오.

채택된 답변

Mathieu NOE
Mathieu NOE 2022년 3월 23일
hello
may I suggest a small improvement here - this avoid finding manually the samples that shoudn't be detrended
so whatever the amount and x position of the peaks, this code should work :
load('signal.mat');
n = 1:length(signal);
n = n';
signalS = smoothdata(signal,'movmedian',200);
I = abs(signal-signalS) < 5e-3;
signal_detrended = detrend(signal(I), 'SamplePoints', n(I));
signal_combined = zeros(length(signal), 1);
signal_combined(I) = signal_detrended;
signal_combined(~I) = signal(~I);
figure(1), plot(n, signal,n, signalS,n, signal_combined)
legend('raw','smoothed','partial detrend');
  댓글 수: 2
Konvictus177
Konvictus177 2022년 3월 24일
This works fine!
Thank you.
Mathieu NOE
Mathieu NOE 2022년 3월 24일
My pleasure !

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Benjamin Thompson
Benjamin Thompson 2022년 3월 22일
You can use an index vector and the 'SamplePoints' option for the detrend function:
>> n = 1:length(signal);
>>n = n';
>> I = (n < 4000) | ((n > 4500)) & (n < 8500);
>> signal_detrended = detrend(signal(I), 'SamplePoints', n(I));
>> hold off;
>> figure, plot(n, signal)
>> grid on, zoom on
>> hold on
>> plot(n(I), signal_detrended, 'r')
  댓글 수: 2
Konvictus177
Konvictus177 2022년 3월 22일
편집: Konvictus177 2022년 3월 22일
The new signal has the lower peak completely removed and is shorter than the original signal. The higher portion is completely missing.
I want the new signal to still have the lower peak unchanged and the higher portion unchanged. The rest of the signal should be detrended.
Benjamin Thompson
Benjamin Thompson 2022년 3월 22일
This is just some basic MATLAB commands, but here you are. The index vector defines the set of what was detrended and what was not.
>> signal_combined = zeros(length(signal), 1);
>> signal_combined(I) = signal_detrended;
>> signal_combined(~I) = signal(~I);
>> figure, plot(n, signal_combined)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by