I'm trying to obtain the power in a certain band, but I want to do this in the time domain and not in the frequency domain. The problem - the bands are very tight and therefore using simple filters create overlapping "tails".
Let [a1 a2]Hz is the band I would like to calculate the power for. I can imagine I'm multiplying the frequency domain by a rectangle signal, and therefore I can get it's ifft in time so I may do a convolution in time.
The code is: (matlab) for x - the signal in time, X=fft(x), W - the window in frequency, w=ifft(W)
filteredX=X.*W;
Fx=ifft(filteredX);
Fx2=conv(x,w,'same');
The results of the signals are different. While the filteredX shows the correct spectrum, the fft of Fx2 (the results of the convolution) is completely different.
Any suggestions?
EDIT:
As suggested by EitanT (thanks), I've played around with the following code:
im = fix(255 * rand(500,1));
mask = ones(4,1) / 16;
% # Circular convolution
resConv = conv(im, mask);
% # Discrete Fourier transform
M = size(im, 1) + size(mask, 1);
resIFFT = ifft(fft(im, M) .* fft(mask, M));
% # Not needed any more - resIFFT = resIFFT(1:end-1); % # Adjust dimensions
% # Check the difference
max(abs(resConv(:) - resIFFT(:)))
Which works fine, but I can't use it so I had to change the parts that are concerned with size issues and got the following (please see comments):
im = fix(255 * rand(500,1));
mask = ones(4,1) / 16;
% # Circular convolution
resConv = conv(im, mask,'same'); % # instead of conv(im, mask)
% # Discrete Fourier transform
M = size(im, 1) % # Instead of: M = size(im, 1) + size(mask, 1);
resIFFT = ifft(fft(im, M) .* fft(mask, M));
resIFFT = resIFFT(1:end-1); % # Adjust dimensions
% # Check the difference
max(abs(resConv(:) - resIFFT(:)))
If though I would expect to get the same results, now the difference is much higher.
fft
andconv
instead offft2
andconv2
, respectively. – Eitan Tconv
function filters in the forward direction, so the "extra" time points are being added to the end of the original samples. See my answer below for a more detailed breakdown. – cjh