how to find max frequency of a signal in matlab?
48 views (last 30 days)
Show older comments
Answer of this question is very important for my project.plz help me.
1 Comment
Jason Christensen
on 10 Mar 2023
% Example from: https://www.mathworks.com/help/matlab/ref/fft.html
% At the end I use max() to determine the max frequency of the signal
Fs = 1000; % Sampling frequency
T = 1/Fs; % Sampling period
L = 1500; % Length of signal
t = (0:L-1)*T; % Time vector
S = 0.7*sin(2*pi*50*t) + sin(2*pi*120*t);
X = S + 2*randn(size(t));
plot(1000*t(1:50),X(1:50))
title("Signal Corrupted with Zero-Mean Random Noise")
xlabel("t (milliseconds)")
ylabel("X(t)")
Y = fft(X);
P2 = abs(Y/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = Fs*(0:(L/2))/L;
plot(f,P1)
title("Single-Sided Amplitude Spectrum of X(t)")
xlabel("f (Hz)")
ylabel("|P1(f)|")
Y = fft(S);
P2 = abs(Y/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
plot(f,P1)
title("Single-Sided Amplitude Spectrum of S(t)")
xlabel("f (Hz)")
ylabel("|P1(f)|")
[MaxValue, MaxIndex] = max(P1);
max_freq = f(MaxIndex)
Answers (4)
Walter Roberson
on 2 Mar 2017
You can only find the maximum frequency in a signal under limited conditions that do not often apply in real life.
To be able to find the maximum frequency of a signal, the signal needs to be exactly representable as the sum of sines or sum of cosines (so it has to be theoretically periodic), and the maximum frequency of the sines or cosines must not exceed half of the sampling frequency.
These conditions do not apply for human speech, for example: human speech has a lot of sudden onsets and sudden stops of sound, and the maximum frequency involved in a sharp sound boundary is infinite.
Likewise, if someone were to play you a pure tuning-rod A440 for 10 seconds, and then were to silence it and you had 5 seconds silence, then that sharp end of sound involves frequencies beyond anything you are likely to be recording with.
Star Strider
on 2 Mar 2017
In a sampled signal, the maximum frequency you can use is the Nyquist frequency defined as half the sampling frequency. Analog-to-digital converters routinely use hardware anti-aliasing filters (generally Bessel design) to prevent any frequencies higher than the Nyquist frequency from being sampled.
For communications purposes, the human voice spectrum is considered to be 0 to 6 kHz.
1 Comment
Walter Roberson
on 2 Mar 2017
Digital Telephony is designed around 8000 samples per second at either 7 or 8 bits per sample, leading to either 56000 bits per second or 64000 bits per second (the 8th bit is used for timing in the 7 bit cases). This is the ISDN rate, with lines being defined in terms of multiples of that rate. This does imply that nothing over 4kHz might get transmitted.
But the communications line restriction is not the same as what the maximum frequency is. You can, though, figure out what the maximum frequency of conveyed by a particular sampled signal is, using fft and knowledge of the sampling frequency. But even then for practical reasons you usually end up having to quantize to account for round off error.
UET Hussain
on 27 Nov 2018
I think I got what you want.
The easiest way is to use small section of data (like if your data is of 10 seconds, get 40 or 80 equal sections of the data, hence each section will be of 250 or 125ms). Now you may use meanfreq or medfreq function (available in Matlab 2015 onwards), to get the mean frequency of 125ms data section. store the 80 values in an array and take maximum from that.
I think it should work for most of the cases. Otherwise, as mentioned by other experts, usually the highest frequency is half the sampling rate.
0 Comments
See Also
Categories
Find more on Spectral Measurements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!