How can I get the first zero maximum in my program?

조회 수: 1 (최근 30일)
Georges Theodosiou
Georges Theodosiou 2021년 1월 5일
편집: Georges Theodosiou 2021년 1월 5일
Ladies, Gentlemen,
Please let me ask you on how I can get the first zero maximum in following code. I'm beginner in MATLAB. I use b(3) for I see that 3rd element in peaks is the first zero element. But it's bad way. I ask your suggestion for some good way, according to your experience with MATLAB.
I need this code for get fundamental frequencies. I apply my method First Absolute Least Sum.
With regards and friendship, Georges Theodosiou
format short
SamplFreq = 96000;
Segm = (1:9600);
% Harmonics
HarmFreq1 = 150;
HarmPhase1 = 0.2*pi;
HarmAngle1 = Segm*HarmFreq1*2*pi/SamplFreq;
HarmSin1 = sin(HarmAngle1);
HarmFreq2 = 2*HarmFreq1;
HarmPhase2 = 1.2*pi;
HarmAngle2 = Segm*HarmFreq2*2*pi/SamplFreq;
HarmSin2 = sin(HarmAngle2);
HarmFreq3 = 3*HarmFreq1;
HarmPhase3 = 2.2*pi;
HarmAngle3 = Segm*HarmFreq3*2*pi/SamplFreq;
HarmSin3 = sin(HarmAngle3);
Xn = HarmSin1+HarmSin2+HarmSin3;
a = 2000;
Sum = ones(1,a);
for k = 1:a;
Sum(k) = sum(Xn(1:k));
end
[a,b] = findpeaks(-abs(Sum));
fundFreq = SamplFreq/b(3)

채택된 답변

Mischa Kim
Mischa Kim 2021년 1월 5일
편집: Mischa Kim 2021년 1월 5일
Georges, you could use something like this to find your first zero:
b(find((abs(a)<1e-12),1))
Of course, this is assuming, for example, that your zeros are sufficiently small/close to zero (I used 1e-12 as a measure).
  댓글 수: 2
Georges Theodosiou
Georges Theodosiou 2021년 1월 5일
편집: Georges Theodosiou 2021년 1월 5일
Mr. Mischa Kim,
Please accept my many thanks for you answered my question and that immidiately. some "zeros" are of the level 1e-13 but some of 1e-7. For example for fundamental frequency (HarmFreq1) 90 Hz, first "zero" is 0.0039 so I put 1e-2. I can work on it.
With regards and friendship, Georges Theodosiou
Mischa Kim
Mischa Kim 2021년 1월 5일
Your very welcome. As long as you know how small the "zeros" are you can pick an adequate number to replace the 1e-12 in my code snippet.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spectral Measurements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by