2
votes

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));
2
What is wrong now with your code?TDG
it 's giving incorrect fft. By using this for loop, some of the rows having correct fft while some of them having wrong fft results.Mayank Lakhani

2 Answers

3
votes

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);
2
votes

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.