caculate frequency from signal data
8 次查看(过去 30 天)
显示 更早的评论
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?
Regards.
0 个评论
采纳的回答
Star Strider
2017-5-24
11 个评论
Star Strider
2017-5-25
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})
figure(k1)
plot(Fv, FTdata_vector)
grid
end
end
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.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!