Info

This question is closed. Reopen it to edit or answer.

Finding x value of local extrama

3 views (last 30 days)
ryan Chappell
ryan Chappell on 18 Nov 2015
Closed: MATLAB Answer Bot on 20 Aug 2021
hello,
Below is my sample of code. In the code, Im taking a simple cos wave and transforming it to the frequency domain. Then, my goal is to find the fundamental frequency of that wave by examining the plot of the FFT.
I am able to find the magnitude of the peak (the y coordinate) in the FFT, however, I cant get the computer to spit out the x coordinate. In the example below, if max_x = 751, freq should equal 500.667. I can not produce the 751.
Thank you for your help, RC
clc; clear all; close all
fs = 50000
t = 0 : 1/fs : 1.5-1/fs;
f1= 500;
x = cos(2*pi*f1*t);
plot(x);
title('inputed signal'); % title of figure
xlabel('Time'); % x-axis lable
ylabel('amplitude'); %y-axis lable
%fourier transform of signal
X = fft(x);
%finding mag. information from signal
y = abs(X);
figure (2);
plot(y);
title('Frequency Domain'); % title of figure
xlabel('Bins (related to freqency)'); % x-axis lable
ylabel('Magnitude'); %y-axis lable
%finding peak y value in freqency domain
amp = max(y)
%finding coresponding bin value to that max
max_x =
%relating the bin value to a freqency
freq = (max_x * 50000)/ 7.5e4

Answers (1)

Guillaume
Guillaume on 18 Nov 2015
The second return value of max is the index at which this maximum is found, so:
[map, max_x] = max(y)

Community Treasure Hunt

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

Start Hunting!