What is the unit of frequency in a spectrogram- Hertz or frequency bins?

Antworten (1)

dpb
dpb am 8 Mär. 2014
The latter and by using your sampling frequency and sample time.

6 Kommentare

How? My sampling time is 2microseconds and my sampling frequency 1/(sampling time).
dpb
dpb am 8 Mär. 2014
Bearbeitet: dpb am 8 Mär. 2014
Bingo. So what would the resulting df vector be (remembering Nyquist)?
If the question is actually how to "tell" Matlab, the output is totally indifferent to it; you manually create/handle an associated frequency axis/variable.
This is my code:
if true
clear all
Array = csvread('Nodefects-63dB.csv');
dt = mean(diff(Array(:,1)));% sampling period
%dt = Array(:, 1);
x = Array(:,2);
Fs = 1/dt;
w = window(@hamming,2800);
[S,F,T,P] = spectrogram(x,w,2400,2800,Fs);
surf(T,F,10*log10(P),'EdgeColor','none');
axis xy; axis tight; colormap(jet); view(0,90);
xlabel('Time (s)');
ylabel('Frequency (Hz)');
end
I have pasted my code here and part of the file that contains the data. For this data, as you can see from the file, the sampling time is 1 microsecond which gives me a sampling frequency of 1000000 Hertz. On running my code and producing a spectrogram, the frequency goes up to 500000 and I don't know how to interpret it in terms of frequency in Hertz.
I'd forgotten about the optional Fs argument to spectrogram, sorry; I don't use it frequently enough.
OK, with a 1 MHz sample rate, what is the Nyquist frequency? Isn't that 500 kHz and doesn't that look suspiciously like your 500000 value?
For Fs as input I'd probably express it in kHz to get smaller integers on the axis. See if that doesn't help.
When I do the FFT of the same signal using the following simple codes
if true
clear all;
Array=csvread('Nodefect-63dB.csv');
t = Array(:, 1);
x = Array(:, 2);
X=fft(x);
X_mag=abs(X);
plot(abs(X))
end
I get the attached figure where the frequency axis finishes in 5000000 (10 times greater than what the spectrogram finishes in- also attached below). All I want is to understand how MATLAB displays the frequency. It's the same signal being analysed. For the FFT, frequency is on the x-axis while for the spectrogram, frequency is on the y-axis. Why is the frequency on the spectrogram from 0-500,000 while that on the FFT plot from 0-5000,000? How do I convert them to Hertz?
Thanks!
Again I reiterate -- fft "knows nuthink" about frequency, it's simply the two-sided DFT of the input in a vector of length N. If you want to plot against a real frequency, you have to create the frequency vector associated with your sampling frequency and sample length. See
doc fft % which shows an example of a PSD and a plot.
Note especially that the DC component is at point N/2+1. Also see
doc fftshift
OTOH, since you used the optional input Fs sample frequency to spectrogram, it normalized the plot to that and handles the display of the single-sided plot automagically for you as a convenience of being a higher-level routine than fft
Read the documentation more carefully and in full on the two specifically and the background information on the FFT in general as well as slowing down and really thinking about what it is that you're actually plotting and computing.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Get Started with Signal Processing Toolbox finden Sie in Hilfe-Center und File Exchange

Gefragt:

Win
am 8 Mär. 2014

Kommentiert:

dpb
am 8 Mär. 2014

Community Treasure Hunt

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

Start Hunting!

Translated by