Determining the maximum value of a function between a certain range.
3 ビュー (過去 30 日間)
古いコメントを表示
Hi,
In a problem that extends from a question I asked here: (<http://www.mathworks.com.au/matlabcentral/answers/45543-returning-coordinates-from-a-plot-function>)
I want to determine the maximum value at the point indicated on the plot attached below. How do I get Matlab to only search for a maximum value of variance (black line) after 5000 Hz? The early peak as seen in the plot is valid so I cannot simply get rid of it so that matlab does't detect it.
Thanks very much in advance.

0 件のコメント
回答 (1 件)
Wayne King
2012 年 8 月 10 日
編集済み: Wayne King
2012 年 8 月 10 日
Presumably you have your data in a vector in the MATLAB workspace. Since you know the correspondence between indices in your vector and frequencies, you can subset your vector and search for the maximum in the reduced vector.
Fs = 25000;
t = 0:1/Fs:1-1/Fs;
x = cos(2*pi*100*t)+sin(2*pi*8000*t)+randn(size(t));
[Pxx,Fxx] = periodogram(x,rectwin(length(x)),length(x),Fs);
% spacing between frequency bins is Fs/length(x)=1 here
Pxx_reduced = Pxx(501:end); % get just the info from 500 Hz on
[val,I] = max(Pxx_reduced);
Iwhole = I+500;
fprintf('The maximum above 500 Hz is located at %2.2f Hz.\n',Fxx(Iwhole));
In the above I've used periodogram, which requires Signal Processing Toolbox. If you do not have that toolbox, you can do the same thing easily with fft()
xdft = fft(x);
freq = 0:Fs/length(x):Fs/2;
xdft = xdft(1:length(x)/2+1);
xdft_reduced = xdft(501:end);
[val,I] = max(xdft_reduced);
Iwhole = I+500;
fprintf('The maximum above 500 Hz is located at %2.2f Hz.\n',freq(Iwhole));
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!