caculate frequency from signal data

28 views (last 30 days)
I have data from the accelerometer sensor and this is an example of my signal
the first step i have divided the data into segment (each segment have 300 values) so in total i have 10 segments.
I need to find the frequency of each segment, which means i would have 10 values (each value represent the frequency of specific segment) .
could you please help me to determine the frequency and store them in an array?

Accepted Answer

Star Strider
Star Strider on 24 May 2017
Use the fft (link) function to transform your time-domain data to the frequency domain.
Use the findpeaks (link) function to find the dominant peaks for each segment and their frequencies.
Star Strider
Star Strider on 25 May 2017
The frequencies increase because of the way the arguments to findpeaks are calculated.
See if this does what you want:
D = load('neamah al-naffakh matlab.mat');
Acc_X_Segments_256 = D.Acc_X_Segments_256;
Fs = 30; % Sampling Frequency (Hz)
Fn = Fs/2; % Nyquist Frequency
L = 300; % Length Of Data Vectors
Fv = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector
Iv = 1:length(Fv); % Index Vector
for k1 = 1:length(Acc_X_Segments_256)
SegmentData = Acc_X_Segments_256{k1}; % Data For Each Segment
SegmentData_mc = SegmentData-mean(SegmentData);
FTdata = fft(SegmentData_mc)/L; % Fourier Transform
FTdata_vector = abs(FTdata(Iv))*2; % Fourier Transform Vector For ‘plot’ & ‘findpeaks’
MaxPk = min([0.2 max(FTdata_vector)*0.99]);
[PeakAmplitudes{k1}, Frequencies{k1}] = findpeaks(FTdata_vector, Fv, 'MinPeakHeight',MaxPk);
if isempty(PeakAmplitudes{k1})
plot(Fv, FTdata_vector)
I subtracted the mean from the data before taking the Fourier transform in order for the 0 Hz signal not to be the predominant peak.
The outputs of findpeaks are stored as cell arrays. For information on working with cell arrays, see the documentation on Cell Arrays (link) if you are not familiar with them.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!