Filtering in matlab is not doing what I want it to do. It’s only doing half, or a quarter, of what I want it to do. The saddest part of this is that I graduated with my BSE in electrical engineering.
Anyway, so I created a filter using the nice fdatool that I think is part of the signal analysis toolbox. It uses the firpm function to create my filter. I created a bandpass filter that’s pretty strict, so N > 1000; It filters my signal just fine, but it cuts off the first half of the signal. Thus the first half of the output signal is essentially 0, while the second half looks like it’s filtered correctly. I tried a lowpass filter of order 633, and now it only cuts out half. I called up my much more knowledgable friend who actually still does this stuff, and he said I have to window my data first. Then he had to go, so I couldn’t really ask him what he meant by that.
Any help on this? To implement the filter, I’m just using the filter function.
This is a pretty easy one - your filter (implemented as an FIR) is starting with zero initial conditions. It takes 1000 data points for your first filter to “fill up” at which point you get good filtered results. Your order-633 filter has 633 coefficients (or is it 634?) so it takes fewer samples running through it to set the initial conditions. You probably shouldn’t use a filter of that order for such a small data set - or you can just do your filter in the frequency domain, in which case initial conditions are not an issue. By that I mean do an fft on your input data, multiply by the conjugate of your filter (you’ll need to intepolate to match lengths), and then do an ifft (if you are using a real input stream, take the real-values from the ifft, but you’ll have to scale the input to keep the output power the same).
That makes much more sense than the windowing business. Can I zero-pad the beginning of my dataset so as to fill it up before the real data comes in? Or will this throw off the rest of the filter?
Don’t feel bad…I too have my BSE in EE, with a concentration in DSP, and I would need a week or two of big time studying to refamiliarize myself with Matlab. Of course, having done absolutely nothing related to engineering in the 5+ years since I graduated could be the reason.
I would think that if your data record is so short, that you may be better off filtering in the frequency domain - you can call the function fftfilt with your time-domain filter to make this happen. Or, you can use the function filtfilt, this runs your data through in forward and reverse orders to reduce startup and ending transients. In any case, I often find it helpful to process a known data record (such as a sum of sinusoids or a white Gaussian noise sequence), and then look at the spectrum (use pwelch) to make sure that the filter is doing what you want it to do. Hope this helps.
I tried the fftfilt method first, but it returned the exact same thing as using the filter. Then I tried the filtfilt, but the signal must have at least 3 times as many samples as the filter order. I think I just need to use a much smaller filter length. Thanks for the replies! I can’t believe how much I’ve forgotten.