How do I normalize this signal

I have a noisy data set that I am trying to find peaks for (I am using the peakfinder function). The function works great when the baseline of the signal does not change, but when it does it no longer finds peaks well - I was thinking of filtering the data, but was unsure what kind of filter would actually help. Any help would be greatly appreciated. A sample below:

 采纳的回答

Star Strider
Star Strider 2014-5-13

0 个投票

I suggest a low-order bandpass filter, perhaps Butterworth 3 or 4. That will eliminate your baseline drift and most of the noise, making it much easier for findpeak to work.

6 个评论

I tried using butterworth, but I couldn't get it to work because I don't know what values I should be using. I tried changing the values around, but essentially I have no idea what I should be doing with it:
Wp = ?; Ws = ?;
[x,Wn] = buttord(Wp,Ws,?,?);
If you have any further thoughts I would be more than happy to try it, medfilt is just the only one that I got to work. Thanks again.
The filter functions use the frequency normalised to the Nyquist frequency. Without access to your data, I can only suggest a design, but this may be what you need:
% Design Filter:
[b, a] = butter(4, [0.2 0.8]);
% Display normalised frequency response:
figure(1)
freqz(b, a, 100)
You might be able to use this design as it exists here without modification. Use the filtfilt function to get a phase-neutral (no phase delay) filtered signal.
This is the analysis part of the code I'm using: t = (data_eeg.time{1}); x = (data_eeg.trial{1}(channel, :)); [b, a] = butter(4, [0.4 0.8]); x = filtfilt(b,a,x); peakfinder(x);
I tried it but it gives me a strange result that I'm not sure what to do with:
It would be easier if I had your signal to work with, since I have some experience processing EEG signals.
There’s more high-frequency noise than I anticipated. In EEG, there is rarely much clinical information above 20Hz, if I remember correctly, so experiment with the filter by lowering the upper passband limit by 0.05 in steps until you either get rid of the noise or encounter filter instability. Don’t raise the lower limit too much, or you’ll eliminate some of the valid low-frequency information in the EEG.
If the filter becomes unstable (see ‘Limitations’ in the butter documentation), since you have the Signal Processing Toolbox, it could be necessary to convert the filter to second-order-section representation. (It’s probably a good idea to do that now, for that matter.) Use the tf2sos function to do the conversion. You can still use filtfilt, but with a slightly different argument list.
awesome! thanks so much, I think I can use this.

请先登录,再进行评论。

更多回答(2 个)

Greg Dionne
Greg Dionne 2014-5-13

1 个投票

Since your peaks appear well-defined and are spaced far enough apart, I would suggest estimating the baseline by using medfilt1().

6 个评论

Medfilt1 seems excellent, the only issue I am running into is that there is a spike at the beginning that's ruining the peakfinder function - I suspect it's an artifact created as a result of the filtering. Do I remove it with padding? I'm not totally sure how to do it - thank you for the help.
Just filter it manually:
filteredSignal(1) = filteredSignal(2);
Have you tried a larger window? Also have you tried my suggestion of sgolayfilt() with a variety of window sizes?
From my experience, especially with biomedical signals, the bandpass filter is the easiest and most effective way of dealing with these problems.
Oh, well.
Something doesn't look quite right with the removal. If you have removed the baseline, your spikes should be mostly positive. Try something like:
findpeaks(x-medfilt1(x,100),'MinPeakHeight',.01e4)
the findpeaks you used doesn't seem to be working. the spikes are "negative" because the data is a negative electrical signal, but they are trending towards positive, which is what I want.
what I am trying to figure out is how to basically pad the data so that it begins after the artifact created by the filtering - I just want to start the analysis a couple of seconds forward from the data...
OK. It might be helpful to post your data file.
If you're not comfortable posting your data... maybe try something like:
[~,locs] = findpeaks(x-medfilt1(x,100),'MinPeakHeight',.01e4)
x(locs)

请先登录,再进行评论。

Image Analyst
Image Analyst 2014-5-13

0 个投票

Some of those peaks are just barely above other peaks that don't have the red circle. Are you setting some threshold for how much a peak must exceed the "baseline" signal before it can be called a peak? What about using sgolayfilt() in the Signal Processing Toolbox. I have a demo available upon request.

2 个评论

My issue with sgolayfilt() is similar to my issue with butterworth; namely, that I can't really use it because I don't understand the parameters in terms of my own data: for example, I have no idea what the window length is. But again I appreciate the help.
Sounds like you don't even have an interest in even trying to understand, and have decided in advance that you "can't really use it" without understanding it. For example, you haven't attached your data file to let anyone help you by trying things.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 EEG/MEG/ECoG 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by