fft - find the main frequency

3 visualizaciones (últimos 30 días)
izap
izap el 24 de En. de 2017
Respondida: Walter Roberson el 24 de En. de 2017
Hi!
I try to check frequency of my signals. I have dot a file with my data. First column is sample number, the second and third are my signal (fourth column doesn't interest me). Sampling time is 50us. I would like to find frequency of these signal, but when I check it by using fft the answer is thet my frequency is zero, but it is impossible.
Please help me!
I attached my code below and the file with data.
clear all; close all;
clc;
load d2_r6__001.txt -ascii;
dane=d2_r6__001;
t_ = 0:50e-6:(length(dane(:,1))-1)*50e-6;
figure(1)
plot(t_,dane(:,2),t_, dane(:,3));grid
Ts=50e-6;
Fs=1/Ts;
Y=fft(dane(:,2));
f=(0:length(dane(:,2))-1)*Fs/length(dane(:,2));
plot(f,abs(Y),'*')

Respuestas (2)

Star Strider
Star Strider el 24 de En. de 2017
I don’t know exactly what you want.
This calculates the fft of your signals, finds the first 3 peaks, and plots the fft and marks the peaks. This should give you the information you want. You can then do what you wish with it.
The findpeaks function is in the Signal Processing Toolbox. It returns the amplitude of the peaks in ‘pks1’ and ‘pks2’, and their respective frequencies in ‘frqs1’ and ‘frqs2’.
The Code
fidi = fopen('d2_r6__001.txt');
D = textscan(fidi, '%f%f%f%*f', 'CollectOutput',1);
s = D{:}(:,2:3);
Ts = 5E-5; % Sampling Interval (sec)
Fs = 1/Ts; % Sampling Frequency (Hz)
Fn = Fs/2; % Nyquist Frequency (Hz)
t = D{:}(:,1)*Ts; % Time Vector
L = length(t); % Vector Length
FTs = fft(s-mean(s))/L; % Fourier Transform (Subtract d-c Offset)
Fv = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector
Iv = 1:length(Fv); % Index Vector
[pks1,frqs1] = findpeaks(abs(FTs(Iv,1))*2, Fv, 'MinPeakHeight',0.05);
[pks2,frqs2] = findpeaks(abs(FTs(Iv,2))*2, Fv, 'MinPeakHeight',0.05);
figure(1)
plot(Fv, abs(FTs(Iv,:))*2)
hold on
plot(frqs1, pks1, '^b')
plot(frqs2, pks2, '^r')
hold off
grid
axis([0 1000 ylim])

Walter Roberson
Walter Roberson el 24 de En. de 2017
You forgot to account for the fact that frequency 0 corresponds to the mean of the data (times the number of points -- so it is sum of the data.) You have a positive mean for column 2 so you get a peak at frequency 0. You have a negative mean for column 3, which also leads to a peak at frequency 0 if you are looking at abs()
The actual frequency peak for your column 2 is the next bin over; the next few bins are fairly full as well. You need to pretty much ignore the first 5 bins to start to see the kind of peaking that you are probably expecting.
Column 3 is easier to analyze.

Categorías

Más información sobre Fourier Analysis and Filtering en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by