A FIR ‘comb’ filter is perfect for this sort of problem! The problem with IIR filters (such as the Butterworth design) is that it is necessary to put them in series to get the desired result.
See if this does what you want:
Fs = 1000;
fcomb = [[47 49.5 50.5 52], [47 49.5 50.5 52]+50, [47 49.5 50.5 52]+100, [47 49.5 50.5 52]+150];
mags = [[1 0 1], [0 1], [0 1], [0 1]];
dev = [[0.5 0.1 0.5], [0.1 0.5], [0.1 0.5], [0.1 0.5]];
[n,Wn,beta,ftype] = kaiserord(fcomb,mags,dev,Fs);
hh = fir1(n,Wn,ftype,kaiser(n+1,beta),'noscale');
figure
freqz(hh, 1, 2^20, Fs)
producing this Bode plot:
I wrote the code so that adding more stopbands should be straightforward. To add more of them, simply add more ‘sections’ to ‘fcomb’, ‘mags’ and ‘dev’. I made the stopbands sufficiently narrow so as not to delete excessive data from your signal that you will likely want to keep. (This is a ‘long’ filter — the order is 560 — however if it is only necessary to run it once for each record, it should still be fairly efficient.) Experiment with it to get different results.
Use the filtfilt function to do the actual filtering. .
Best Answer