normalize data matlab
My Friend,
see my experement below:
x=ones(1,5)
x =
1 1 1 1 1
>> s=fft(x)
s =
5 0 0 0 0
>> ifft(s)
ans =
1 1 1 1 1
as shown above, Matlab did a complete conversion and inverse conversion with out need to do any normalization, I mean , that i do not need any normalization, while the Pdf file said that we must use the normalization. From which i conclude that this document is not correct.
Now, for your quiation "what is the adv of using a scaling factor in fft and ifft???", please see my answere below;
when we represent a signal within matlab, we usually use two vectors, one for the x-data and one for the y-data. The FFT command only operates on the y-data (converting the y-data from time domain to the frequency domain). So it is up to the user to determine what the x-data in the frequency domain will be!
Now let us to take an example:
y(t)=2cos( 2 Π fo t )
-------------------------
fo=4;
Fs=100;
Ts=1/Fs;
t=0:Ts:1-Ts;
n=length(t) ;
y=2*sin(2*pi*fo*t) ;
plot(t,y) ;
when we take the fft of this curve, we would ideally expect to get the following spectrum in the frequency domain , we expect to see one peak of amplitude 1 at -4 Hz, and another peak of amplitude 1 at +4 Hz. So, let us use matlab's built in function fft to see the results.
yfr=fft
;
stem(abs(yfr ) ) ;
from the figure above, it does not quite look like what we predicted above. If we notice there are acouple of things that are missing:
1. The x-axis gives us no information on the frequency. How can we tell that the peaks are in the right place?
2. The amplitude is all the way up to 100.
3. The spectrum is not centered around zero.
To solve these problems, we must normalize the data and use the matlab function FFTshift after the function FFT as follows;
function [X freq]=centeredFFT(x,Fs)
N=length(x) ;
if mod(N,2) ==0
k=-N/2:N/2-1;
else
k=-(N/2)/2: (N-1)/2;
end
T=N/Fs;
freq=k/T; % The Frequency axis.
X=fft(x)/N; % Normalize the data.
X=fftshift(X); % shift the fft data so that it is centered.
the o/p of the above function will be correct frequency range and the transformed signal.
let's use this function in example:
[yfDom,frange]=centeredFFt(y,Fs);
stem(frange,abs(yfDom ) ) ;
as we can see from the plot above, the information within the frequency spectrum is entirely symmetric.
Hope this is clear.
Montadar