One simpler approach may be to simply take the FFT and zero frequency components other than the specific range that may interest you, and then invert the FFT to return to the time domain.
Keep in mind that you will have to zero out the positive frequency and the negative frequency in order to maintain that the signal in the frequency domain is conjugate symmetrical with respect to 0 frequency. If you do not, you will receive a complex signal when calculating the inverse FFT.
EDIT: For example, the following code creates two sine waves in the time domain corresponding to a DFT (calculated using FFT), and then one of the peaks is deleted.
t = 0:0.01:0.999; x = sin(t*2*pi*4) + cos(t*2*pi*8); subplot(2,2,1); plot(x) title('time domain') subplot(2,2,2); xf = fft(x); plot(abs(xf)) title('frequency domain'); subplot(2,2,3); xf(9) = 0; xf(93) = 0; % manual removal of the higher frequency plot(abs(xf)); title('freq. domain (higher frequency removed)'); subplot(2,2,4); plot(ifft(xf)); title('Time domain (with one frequency removed)')
A few things to note. The frequency domain in the DFT has several different ranges: constant bias (constant), which is a frequency of 0; a positive frequency range, which (for a long N source signal) is from 1 to N / 2; negative frequency range, which is entries from N / 2 to N-1; Please note that this is not a typo, the highest frequency (one in N / 2) is duplicated and is the same value for both positive and negative frequencies. (Some people use fftshift to show this, as a person can plot it, but it's really just for the sights / understanding.)
As for the frequencies that need to be removed, you have to figure it out yourself, but I can give you a hint. The highest frequency (at frequency position N / 2) will correspond to the highest frequency represented by your system, i.e. fs / 2, where fs is your sampling rate. You can scale to determine which ones should be denied.
If you do not deny the corresponding negative frequencies correctly, you will get an imaginary signal with the opposite fft.
Last comment. This method will only work if you have the luxury of having your entire signal ahead of time, since you need to use the DFT on the entire signal. If you want to do this in real time, you will need to create some kind of filter, as you did before.