ep_mean is a 26xN matrix of a single trial, recorded through 26 electrodes, over N time points (roughly 220 points sampled)
I applied the sgolayfilt function to try to smooth the signal. I run into the problem that I don't know what values of the two parameters for sgolayfilt, the order and the frame length, are optimal for the filtering process. I also don't know if this is a technical or a philosophical question.
So I tried a grid sweep of parameter combinations using the following code:
snr_mat = ;
for i1 = 1:99
if mod(i1,2) == 0
c = i1+1;
c = i1+2;
for i2 = c:2:101
rd = i1;
fl = i2;
filt = sgolayfilt(ep_mean,rd,fl,,2);
snr_mat(i1,i2) = snr(ep_mean,ep_mean-filt);
snr_mat(snr_mat>300) = 0;
y = sgolayfilt(ep_mean,3,21,,2);
title('rd = 3; fl = 21','fontsize',16)
x = sgolayfilt(ep_mean,11,41,,2);
title('rd = 11; fl = 41','fontsize',16)
[M1,I1] = max(snr_mat);
[M2,I2] = max(M1);
rd = I1(I2);
fl = I2;
z = sgolayfilt(ep_mean,rd,fl,,2);
title(['rd = ' num2str(rd) '; fl = ' num2str(fl)],'fontsize',16)
To produce these figures:
The first figure plots the magnitude of the SNR after using each pair of order (rd) and framelength (fl) parameters. It seems the higher both are, and the closer they are to each other, the better then SNR. But the second figure clarifies what I think to be happening, which is that higher values for rd and fl do not necessarily filter better, they just more closely match the unfiltered signal so the snr function calculates a lower noise and higher ratio. This feels quite stupid to me, what I did I mean.
So my question becomes how to identify the optimal parameters (rd, fl) in the sgolayfilt function to filter a given signal. What metric can I employ to assess the performance of the filtering process? And is a grid sweep the best way to test different parameter combinations?
Thanks for your help!