Filtering out spikes in data at n*60 +1

4 views (last 30 days)
Hello,
I have been working on a spectogram figure for some time now and have been unsuccessful in eliminating spikes in the data that occur at every 60 plus 1 i.e. 61, 121,181, ... etc. I have tried treating my data with a notch filter, filtfilt, medfilt1, and sgolay filt. In the past, I tried whitening it and using an fft to no advantage. Ideally, I would like to use something like butter or fir1 but this is a recorded data set with 64 channels and not a set frequency. What would be the best way to go about filtering this? Aside from the sgolay figure, the results are identical.
Sgolay: third order, framelength of 61
All of the other filters:
Below are the notch filters:
%% Notch Filter: Did not work
% method 1:
wo = 61/(30000/2); %removes 60Hz tome from a signal at 30,000 Hz
bw = wo/35; % Q factor of 35, this can be modified for varied results
[b,a] = iirnotch(wo,bw); % output's num and dom but we are not workign with a function to which they can be applied
% method 2: design butterworth notch filter
% d = designfilt('bandstopiir','FilterOrder',2, ...
% 'HalfPowerFrequency1',60,'HalfPowerFrequency2',62, ...
% 'DesignMethod','butter','SampleRate',samplingRate);
% dataFilt = filtfilt(d,lfp.data);
dataFilt = filtfilt(b,a,lfp.data);
Below are the other filters:
%% Median Filter: did not work
dataFilt = medfilt1(lfp.data,3);
%% Standard Filter: requires the inpouts of numerator and denominator functions 'filter(n,d,X)' where X is the data set, we are not trying to match this data to a filter
% did not work
dataFilt = filter(61,1,lfp.data); % the 1/1 is just a test
%% Savitzky - Golay Filter:
order = 3;
framelength = 61;
dataFilt = sgolayfilt(lfp.data, order, framelength);
%% FIR - Bandpass filter
dataFilt = fir1(lfp.data,60);
Thank you for taking a look at this. There must be a simple way to accomplish this.

Accepted Answer

Image Analyst
Image Analyst on 29 Nov 2021
If you know the indexes, how about just setting them to zero, or the median of neighboring values.
smoothy = movmedian(y, 5); % Smooth it
index = find(x == 181);
y(index) = smoothy(index); % Replace with median.
  3 Comments
Emma Walker
Emma Walker on 29 Nov 2021
Thank you very much. This would have been a better approach. What do you mean by 'x' here instead of just having the index within the parentheses?

Sign in to comment.

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!