Search code examples
matlabsignal-processingfftifft

Fourier transform of multiple rows


I want to take FFT of 10 measurements. That means I have 10 rows in my data with each row having dimension [1*2000]. In the code below, I am doing in a wrong way. Can anybody tell me what mistake I am making?

load('fb2010');                                   % loading the data
x = fb2010(3:1:15,:);
y_filt = filter(b,a,x);                           % filtering the received signal
%%%%%%%  Fourier transform
nfft = length(y_filt);
for i = 1:10
res(i,:) = fft(y_filt(i,:),nfft)/ nfft;         %%%% Taking first fft and normalizing it
end
res2 = res(:,1:nfft/2+1);                   %%%% taking single sided spectrum
f = fs/2*linspace(0,1,nfft/2+1);            % choosing correct frequency axes
figure, plot(f,abs(res2));

Solution

  • The function filter applies the transfer function along the first dimension by default. So you filter your columns instead of your rows. To get the correct result, use the following line:

    filter(b,a,x,[],2);
    

    Then you can omit the loop by using fft with a third argument to specify the dimension it operates along. This would be the following line:

    res = fft(y_filt,nfft,2);