Understanding this FFT Graph

63 views (last 30 days)
David Kendal
David Kendal on 23 May 2022
Commented: Star Strider on 24 May 2022
I have plotted a graph using FFT function; using a sweep sine wave.
The code is generic NFFT = 2^nextpow2(L) and using absolute values to plot FFT values on the Y axis.
My question is; what would the label be for the Y-axis and secondly, is the X axis just frequency in the time domain?
Any help greatly appreciated.
T=5; %size of window
fs=44100; %sampling frequency
df=1/T; %frequency res
dt=1/fs; %time resolution
t=(0:+dt:T-dt); %time vector
df_t=500; %swept rate (Hz/seconds)
% pre-allocate size of t:
sweptsin = zeros(size(t));
for i=1:+1:length(t)
%i=i+1;
if(i==1) %initialise f and t.
f=20; ti=0;
else
ti=ti+dt; %time increment
f=f+df_t*dt; %freq increment
end
w=2*pi*f; %omega
sweptsin(i)=sin(w*ti); %swept sine wave
end
sound(sweptsin, fs)
figure
y = cos(2*pi*f*t)+randn(size(t));
L = 1000;
NFFT = 2^nextpow2(L);
Y = abs(fft(y,NFFT))/L;
f = fs/2*linspace(0,1,NFFT/2+1);
plot(f,2*abs(Y(1:NFFT/2+1)))
xlim([0 22050])
ylim([0 0.8])

Accepted Answer

Star Strider
Star Strider on 24 May 2022
My question is; what would the label be for the Y-axis and secondly, is the X axis just frequency in the time domain?
The Y-axis here would be labeled ‘Amplitude’. It represents the amplitude of the signal components at each frequency. (If it were in decibels, it would be either 'dB' or 'Power (dB)' since converting it to decibels implicitly squares the amplitude creating units of power, and then takes the base-10 logarithm of it.)
The X-axis is the frequency axis, and the units are in cycles/(time unit). The frequency vector is calculated to extend from D-C (zero cycles/(time unit)) to the Nyquist frequency (one-half the sampling frequency), the highest frequency that can be uniquely determined in a sampled signal. The sampling frequency (samples/(time unit)) is the inverse of the sampling interval ((time units)/sample), relating the time vector to the frequency vector.
In a ‘normalised’ signal, the frequency extends from zero to π randians/(time unit). The frequency vector is calculated with respect to the length of the fft result, so that each element of the fft result is assigned a specific frequency between zero and the Nyquist frequency (or π). If the time unit is in units of seconds, the frequency vector is units of Hz.
T=5; %size of window
fs=44100; %sampling frequency
df=1/T; %frequency res
dt=1/fs; %time resolution
t=(0:+dt:T-dt); %time vector
df_t=500; %swept rate (Hz/seconds)
% pre-allocate size of t:
sweptsin = zeros(size(t));
for i=1:+1:length(t)
%i=i+1;
if(i==1) %initialise f and t.
f=20; ti=0;
else
ti=ti+dt; %time increment
f=f+df_t*dt; %freq increment
end
w=2*pi*f; %omega
sweptsin(i)=sin(w*ti); %swept sine wave
end
sound(sweptsin, fs)
figure
y = cos(2*pi*f*t)+randn(size(t));
L = 1000;
NFFT = 2^nextpow2(L);
Y = abs(fft(y,NFFT))/L;
f = fs/2*linspace(0,1,NFFT/2+1);
plot(f,2*abs(Y(1:NFFT/2+1)))
xlim([0 22050])
ylim([0 0.8])
xlabel('Frequency')
ylabel('Amplitude')
.

More Answers (1)

David Kendal
David Kendal on 24 May 2022
I did assume it was amplitude earlier on Y. I’m getting very tired it’s late here and I don’t code well when I’m falling asleep 😆…on note to your reply - that’s very informative and given me a few things to think about in terms of the Nyquist frequency. Thanks again.

Categories

Find more on Programming 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!