# Why is frequency of graph differing?

2 visualizzazioni (ultimi 30 giorni)
Niklas Kurz il 17 Gen 2021
Risposto: Mathieu NOE il 19 Gen 2021
I like to graph the frequency of 440 Hz and analyse it
I use the following code:
figure(1)
sf = 1000; %sampling
f = 440;
a = 0.5;
t = 0:1/sf:1;
x = a*sin(2*pi*f*t);
sound(x,sf)
figure(1)
plot(t,x) %amplitude-time graph
axis([0 1/f min(x) max(x)])
figure(2) %Fourier analysis
n = length(t);
xhat = fft(x,n);
PSD = xhat.*conj(xhat)/n;
freq = 1/(dt*n)*(0:n);
L = 1:floor(n/2);
colormap jet(20)
plot(freq(L),PSD(L),'LineWidth',2.5)
First of: why is it, that the Frequency of amp-time Graph is jagged? If I increase the sampling frequency, why is, that the actual frequency changing?
##### 6 CommentiMostra 4 commenti meno recentiNascondi 4 commenti meno recenti
Niklas Kurz il 18 Gen 2021
can you post this as answere pls so I can accept .
Mathieu NOE il 19 Gen 2021
will do

Accedi per commentare.

### Risposta accettata

Mathieu NOE il 19 Gen 2021
hi - official answer this time
the PSD concept is valid only for random type signals , not sinus
mathematically speaking, a sinus has a PSD of infinite amplitude and zero bandwith, simply because a sine wave has its energy concentrated only at one discrete frequency and not spread accross a wider freq range
if you test your code with random signals, you should see that the peak amplitude stays the same whatever the sampling frequency. But this does not hold if you test now with a sine wave
for a sine wave , the psd concept must be replaced by power or rms or peak amplitude
in summary , a FFT analyser will operate this way :
it will first compute the ftt.*conj(fft) power spectrum
if you ask for "PSD" (knowing that you are looking at random type signals) , it will do : PSD = power / nfft (as you did)
if you ask for "RMS" (knowing that you are looking at sine / multi sine type signals) , it will do : RMS = sqrt(power) and there is no division by nfft
so I modified a bit your code to test the different scenarios :
sf = 2200; %sampling
f = 440;
a = 0.5;
t = 0:1/sf:1;
% x = a*sin(2*pi*f*t); % to test the PSD = 2*abs(xhat)/n
x = a*randn(size(t)); % to test the PSD = xhat.*conj(xhat)/n
sound(x,sf)
figure(1)
plot(t,x) %amplitude-time graph
axis([0 1/f min(x) max(x)])
figure(2) %Fourier analysis
n = sf; % so df = sf/n = 1 Hz
xhat = fft(x,n);
PSD = xhat.*conj(xhat)/n; % ok for random type signals
% PSD = 2*abs(xhat)/n; % ok for sine type signals
freq = 1/(1/sf*n)*(0:n);
L = 1:floor(n/2);
colormap jet(20)
plot(freq(L),PSD(L),'LineWidth',2.5)
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Spectral Estimation in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by