フィルターのクリア

Why is frequency of graph differing?

1 回表示 (過去 30 日間)
Niklas Kurz
Niklas Kurz 2021 年 1 月 17 日
回答済み: Mathieu NOE 2021 年 1 月 19 日
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 件のコメント
Niklas Kurz
Niklas Kurz 2021 年 1 月 18 日
can you post this as answere pls so I can accept .
Mathieu NOE
Mathieu NOE 2021 年 1 月 19 日
will do

サインインしてコメントする。

採用された回答

Mathieu NOE
Mathieu NOE 2021 年 1 月 19 日
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 件)

カテゴリ

Help Center および File ExchangeSpectral Estimation についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by