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 CenterFile Exchange에서 Spectral Estimation에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by