필터 지우기
필터 지우기

How to find frequency of wave data

조회 수: 34 (최근 30일)
Marcella Roth
Marcella Roth 2021년 3월 18일
편집: Cris LaPierre 2021년 3월 23일
Hi, I have a set of data (shown below) and I would like to get the frequency of the wave Thank you!
So far I have tried:
a=readmatrix(sprintf('sampledata')) %read in data
x=a(:,2)
t= a(:,1)
z = x(t>171 & t<174.5)
zz = t(t>171 & t<174.5)
% Get sine fit
F = fit(zz, z, 'sin1');
% Plot result
plot(F,zz,z);
grid on;
xlabel('Time (secs)');
ylabel('Amplitude');
title(['Estimated frequency = ', num2str(F.b1/(2*pi)), ' Hz']);
and I get a frequnecy of 0.00075267 Hz
I can see by hand counting that the frequency is about 27-28. Any help is appreciated!

채택된 답변

Cris LaPierre
Cris LaPierre 2021년 3월 18일
I would probably try to use findpeaks. With the right setting, you can use that to count the number of peaks. You could also do this interactively using the find local extrema live task in a live script.
  댓글 수: 7
Cris LaPierre
Cris LaPierre 2021년 3월 22일
You are not using the same window you showed above. Also, you only need to call findpeaks once. Finally, cycles/sec is already Hz. Don't divide by .
Assuming you are interested in the approximate frequency between 171 and 174.5 seconds, only pass the corresponding rows into findpeaks
% load the data
a=readmatrix('sample data.txt');
t= a(:,1);
y=a(:,2);
% Plot result
plot(t,y)
xlim([170 175])
grid on
xlabel('Time (secs)')
ylabel('Amplitude')
% Select rows corresponding to desired time window
ind = t>171 & t<174.5;
[pks,locs] = findpeaks(y(ind),t(ind),'MinPeakProminence',0.5);
% visualizse the selected peaks
hold on
plot(locs,pks,'rv')
hold off
% calculate the approximate frequency
meanCycle = length(pks)/(locs(end)-locs(1))
meanCycle = 27.6002
title("Estimated frequency = " + round(meanCycle,1) + " Hz");
.
Marcella Roth
Marcella Roth 2021년 3월 22일
Thank you so much for your help, I really appreciate it!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by