Can I set a range for spectrogram Analysis

52 views (last 30 days)
Hi All,
my signal data has a variable frequency(around 50HZ). Can I set a frequency range for spectrogram analysis?
I want to determine the exact frequency according to time
My code is listed below.
Thank you ALL!
Ivy
clear all;
clc;
Fs=1000;
T=1/Fs;
L=1000;
t=(0:L-1)*T;
for i=1:1:10000 %variable frquency signal.
x(i)=0.7*sin(2*pi*(50+rand)*T*(i-1));
end
NFFT =1024;
[S,F,T,P] = spectrogram(x,1024,1000,1024,1E3);
[c,index]=max(P);
surf(T,F,10*log10(P),'edgecolor','none'); axis tight;
view(0,90);

Accepted Answer

Rick Rosson
Rick Rosson on 1 Aug 2011
Hi Ivy,
There are several issues with the code that you have posted. Each of these issues falls into one of two broad categories:
  1. Issues with how the code generates the source signal x(t), and
  2. Issues with how the code attempts to analyze and visualize the signal using the spectrogram function.
The most important issue is related to category #2. The sampling rate Fs is 1000 samples per second, while the number of samples in each FFT is 1024 samples. As a result, the frequency resolution of the spectrogram is nearly 1 hertz:
dF = Fs/NFFT = 1000/1024 = 0.9766 hertz
The frequency of the source signal is 50+rand hertz. Since the rand function generates a uniformly distributed random value between 0 and 1, the frequency of the signal will vary between 50 and 51 hertz, which is a range of only 1 hertz. This range is only just slightly larger than the resolution of the spectrogram, so that most of the time the spectrogram will not be able to detect it.
So to address this issue, you can either increase NFFT to a larger value, or increase the range of frequencies in the source signal.
As I mentioned, there are other issues in the code, but the frequency resolution is probably the most important one.
HTH.
Rick

More Answers (1)

Daniel Shub
Daniel Shub on 1 Aug 2011
You cannot set the frequency range for spectrogram analysis using the spectrogram function. You can, however, perform a short-time Fourier analysis with the freqz function. The freqz function lets you focus your NFFT frequency bins where you want them, as opposed to uniformly throughout the entire frequency range. This approach would require you to write code for the windowing of your signal.

Categories

Find more on Time-Frequency Analysis 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!