2

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));
Luis Mendo
  • 110,752
  • 13
  • 76
  • 147
Mayank Lakhani
  • 193
  • 1
  • 13

2 Answers2

3

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);
Matt
  • 12,848
  • 2
  • 31
  • 53
2

doc fft:

Y = fft(X,n,dim) where dim is the dimension. I suppose you want dim = 2. This will get rid of the loop and should work. I just used it myself.

TheodorBecker
  • 249
  • 1
  • 17
  • Why 2? my dimesion of each row is 1*2000 and i am having such 10 rows. – Mayank Lakhani Jul 31 '15 at 07:42
  • Sorry, I was a bit too fast and tired this morning. You are right, the fft works, it's the filter that is giving the problem. Still, this `dim` argument will save you from using the loop. See Matt's answer! – TheodorBecker Jul 31 '15 at 07:44