caculate frequency from signal data
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
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.
採用された回答
Star Strider
2017 年 5 月 24 日
11 件のコメント
neamah al-naffakh
2017 年 5 月 24 日
Dear @Star Strider i have already used FFT function but actully i'm not good with frequency domain component.
i only need to find the frequency for each segment , but findpeaks will determine the the local maxima (peaks) and im looking for the frequency not the peaks!
please could you help me with it? each segment contains 300 values
so far i have written this code
NFFT=size(Acc_TD_Segments{1},1); % NFFT (lenght of segment) and Acc_TD_Segments(Time domain signal)
Fss=30; % the sampling frequency of the input signal
Acc_FD_Signal{nn,1}=fft(Acc_TD_Segments{nn},NFFT)/NFFT; % nn (number of segments which is =10)
if my code is correct what is the next step to find the frequecny of each segment?
if not please could you help me to correct my code?
Star Strider
2017 年 5 月 24 日
Fir each segment of your data, use the code between the first (top) two plot figures in the fft documentation in the link, in order to analyse and plot your frequency domain data.
Then use the amplitude and frequency vectors you used for the plot as arguments to the findpeaks function. With both vectors, findpeaks returns the amplitudes of the peaks and the frequencies of the peaks. Ask for the first two outputs from findpeaks.
You will have to experiment with the name-value pair arguments in findpeaks to get thr result you want. See the documentation for findpeaks for details.
Example —
SegmentData = ... ; % Data For Each Segment
Fs = ...; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
L = 300; % Length Of Data Vectors
FTdata = fft(SegmentData)/L; % Fourier Transform
Fv = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector
Iv = 1:length(Fv); % Index Vector
FTdata_vector = abs(FTdata(Iv))*2; % Fourier Transform Vector For ‘plot’ & ‘findpeaks’
figure(1)
plot(Fv, FTdata_vector)
grid
[PeakAmplitudes, Frequencies] = findpeaks(FTdata_vector, Fv);
The ‘PeakAmplitudes’ variable has the amplitudes of the peaks, and ‘Frequencies’ has the matching frequencies of the peaks.
neamah al-naffakh
2017 年 5 月 25 日
dear @Star Strider. thank you so much again
when i run your code, i have multiple frequencies for each segment ( but actully i want one frequency for each segment!)
so do you think i should take average of frequencies for each segment?
Star Strider
2017 年 5 月 25 日
My pleasure.
No. Do not take the average.
Please read the documentation on findpeaks, specifically with respect to the 'MinPeakHeight' and 'MinPeakDistance' name-value pairs. These are generally the most useful, and there are several others that could apply to your signal.
Experiment to get the result you want.
neamah al-naffakh
2017 年 5 月 25 日
編集済み: neamah al-naffakh
2017 年 5 月 25 日
dear Sir, I really approciate your help. i have followed your advise as followes
SegmentData=Acc_Segments{nn};
Fs = 30; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
L = size(Acc_Segments{1},1); % Length Of Data Vectors
FTdata = fft(SegmentData)/L; % Fourier Transform
Fv = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector
Iv = 1:length(Fv); % Index Vector
FTdata_vector = abs(FTdata(Iv))*2; % Fourier Transform Vector For ‘plot
[PeakAmplitudes, Frequencies] = findpeaks(FTdata_vector, Fv);
Amp{nn}= PeakAmplitudes;
Freq{nn}= Frequencies;
now i have an array called Freq ( 1*108 cells), each cell contains multiple Frequencies (e.g. the first cell have 10 Frequencies and the second 8 Frequencies). However, I want one Frequency for each segment. This is because I'd like to have two data subsets, the first contains segments with low Frequencies while the second includes segments with high Frequencies
please could you help me with the next step?
I have attached my data
Kind Regards
Star Strider
2017 年 5 月 25 日
My pleasure.
When I read your file with:
AccSegments = xlsread('neamah al-naffakh Test3.csv');
it is a (34640x7) matrix. (I renamed it because I discovered two other files of yours with similar names.) This does not match your description of 300-element vectors.
It would be easier if you attached a ‘.mat’ file of the 300-element vector data you want to analyse, since you have already divided it to be as you want it.
neamah al-naffakh
2017 年 5 月 25 日
that's very kind of you Sir,
please find the attached file,
the attached file contains 108 segments, each segment contains 300 values.
please note the attached data in time domain.
let me give you a conclusion of what i would like to achieve.
the attached data is the walking data of one user. Nevertheless, I dont know if the user walk fast or slow!
So, I decided to calculte the frequency for each segment ( as i mentioned that each segment contains 300 values).
Then, all segments that have high Frequencies will be stored in one array but i also want to keep the index of that segment.
for example: two columns: first column is the Frequency value (e..g., 4) and the second column is the segment index (e.g., 5).
Similarly, the second dataset includes segments that have low Frequencies with the index of that segment.
as always, really approciate your help and support
Star Strider
2017 年 5 月 25 日
The 108 segments are each (300x1) vectors.
What is the matching time vector or sampling frequency or interval? Is it the same for all?
neamah al-naffakh
2017 年 5 月 25 日
sampling frequency =30 and yeah it is the same for all . Each segment contains data of 10 seconds and the sampling frequency is 30 for each second. Therefore, 300 values per each segment
neamah al-naffakh
2017 年 5 月 25 日
dear Sir,
why the frequencies value for each segment are arranged from small value to big value?
i was thinking they will be randomly arranged? please see the attached pic!

let's make it easy. i just want to calculte the frequency for each segment and store it in an array!
forget about the index and high and low frequencies
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 件)
カテゴリ
ヘルプ センター および File Exchange で Descriptive Statistics についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
