From: Ruben on
Hi,

I would like to perform a fast fourier transform of my measurement data. I used the script below, but I doubt if it is correct. The plot is not what I expected: I was expecting to see a big disturbance of the electric power at 50 Hz (due to a nearby machine), but I see the big disturbance at 100 Hz, 200 Hz and 300 Hz. Therefore I assume that something in my script is not correct. Could anyone tell me what it is? Or is it correct? Thanks for reply!

Ruben


% 'a' is data row 1:40496
a=data(1:40496);

% fast fourier transform of data
b=abs(fft(a));

% calculate length of 'a'
n=length(a);

% bins are seperated by df
% 1600 Hz=sampling frequency
df=1600/n;

% time domain
t=0:df:1600/2;

% plot fft and t
plot(t,b(1:n/2+1));
From: Stefan on
You could try first with self-made sine signals and verify the correctness of the code.

Regards,
Stefan


Ruben <rubenregterschot(a)hotmail.com> wrote in message <380155788.362453.1268313453494.JavaMail.root(a)gallium.mathforum.org>...
> Hi,
>
> I would like to perform a fast fourier transform of my measurement data. I used the script below, but I doubt if it is correct. The plot is not what I expected: I was expecting to see a big disturbance of the electric power at 50 Hz (due to a nearby machine), but I see the big disturbance at 100 Hz, 200 Hz and 300 Hz. Therefore I assume that something in my script is not correct. Could anyone tell me what it is? Or is it correct? Thanks for reply!
>
> Ruben
>
>
> % 'a' is data row 1:40496
> a=data(1:40496);
>
> % fast fourier transform of data
> b=abs(fft(a));
>
> % calculate length of 'a'
> n=length(a);
>
> % bins are seperated by df
> % 1600 Hz=sampling frequency
> df=1600/n;
>
> % time domain
> t=0:df:1600/2;
>
> % plot fft and t
> plot(t,b(1:n/2+1));
From: Wayne King on
Ruben <rubenregterschot(a)hotmail.com> wrote in message <380155788.362453.1268313453494.JavaMail.root(a)gallium.mathforum.org>...
> Hi,
>
> I would like to perform a fast fourier transform of my measurement data. I used the script below, but I doubt if it is correct. The plot is not what I expected: I was expecting to see a big disturbance of the electric power at 50 Hz (due to a nearby machine), but I see the big disturbance at 100 Hz, 200 Hz and 300 Hz. Therefore I assume that something in my script is not correct. Could anyone tell me what it is? Or is it correct? Thanks for reply!
>
> Ruben
>
>
> % 'a' is data row 1:40496
> a=data(1:40496);
>
> % fast fourier transform of data
> b=abs(fft(a));
>
> % calculate length of 'a'
> n=length(a);
>
> % bins are seperated by df
> % 1600 Hz=sampling frequency
> df=1600/n;
>
> % time domain
> t=0:df:1600/2;
>
> % plot fft and t
> plot(t,b(1:n/2+1));

Hi Ruben, I don't see anything obviously wrong (although it's a little confusing that you are labeling your frequency variable, t, and have it commented as the time domain). Are you sure you have the sampling frequency correct? Just as a sanity check do:

H = spectrum.periodogram('hamming');
Hpsd = psd(H,a,'Fs',1600);
plot(Hpsd)

Do you still see peaks at 100, 200, etc?

Wayne
From: Rune Allnor on
On 11 Mar, 14:17, Ruben <rubenregtersc...(a)hotmail.com> wrote:
> Hi,
>
> I would like to perform a fast fourier transform of my measurement data. I used the script below, but I doubt if it is correct. The plot is not what I expected: I was expecting to see a big disturbance of the electric power at 50 Hz (due to a nearby machine), but I see the big disturbance at 100 Hz, 200 Hz and 300 Hz. Therefore I assume that something in my script is not correct. Could anyone tell me what it is? Or is it correct? Thanks for reply!

I can't see anything obviously wrong, but you are a factor 2
off expectations, and a factor 2 is easily missed.

This is how I usually do these things:

Nfft = length(x); % x is data.
Fs = 1600; % sampling frequency
fv = (0:Nfft-1)*Fs/Nfft;
plot(fv,abs(fft(x)))

This will plot the full spectrum, but avoids that nuisance
factor 2. And it gives the obvious consistecy check, where
you easily recognize the sampling frequency, the Nyquist
frequency etc. Once you are happy that the numbers match,
you can start chopping off the redundant parts from the
spectrum.

Rune
From: Ruben on
Hi Wayne, thanks for fast reply. I performed the check and it gives indeed peakes at the same frequencies. Highest peak at 100 Hz, decreasing at 200 Hz, 300 Hz etc.

Therefore I assume that my original code was correct. I am checking the sampling frequency, but I think it's the right frequency.

Ruben
 |  Next  |  Last
Pages: 1 2
Prev: retreive data
Next: serial data plotting