フィルターのクリア

Fourier-Frequency analyse

1 回表示 (過去 30 日間)
Robin Beene
Robin Beene 2012 年 1 月 20 日
I need to do next: Draw a frequency image of following signal: t=0:0.0001:0.05; y=square(5*pi*50*t);
also it's required to draw real and imaginary part of frequency spectrum.
There is mine solution, so can anyone check it out
t=0:0.0001:0.05; y=square(5*pi*50*t); N=length(t); deltaf=1/0.05; f=(0:N-1)*deltaf;
disp('Efektivna vrijednost') Yef=sqrt(sum(y.*y)/N)
disp('Frekvencijska slika') F=(fft(y))*2/N;
figure, plot(f,F) axis([0 1200 -0.5 1])
figure, subplot(3,1,1)
plot(f,20*log10(real(F)/max(abs(F)))) axis([0 1200 -80 10])
subplot(3,1,2) plot(f,20*log10(imag(F)/max(abs(F)))) axis([0 1200 -80 10])
subplot(3,1,3) plot(f,20*log10(F/max(abs(F)))) axis([0 1200 -80 10])

採用された回答

Robin Beene
Robin Beene 2012 年 1 月 20 日
Hey, It shows error here: y_freq = fftshift(fft(y))*dt;
because matrix dimensions doesn't agree here: f = -Nyq : df : Nyq;
I bypass that somehow, and I saw that our sinals in frequency spectrum looks exactly the same(I draw it without logarithm scale and for positive frequencies, thats why I multiply with 2 here F=(fft(y))*2/N;), but only difference is that ur values are 20 times smaller, for same frequency u get 20 times lower amplitudes. Why?
  1 件のコメント
Dr. Seis
Dr. Seis 2012 年 1 月 20 日
Sorry, made a mistake when writing my example code. Try with the changes above. It will work better if you have an even time series.
You multiply the amplitudes in the frequency domain by "dt" because the FFT assumes your sample rate is unity (i.e, 1 sample per second). Therefore, the discrete integral that is calculated during the FFT is off by a factor of 1/dt (the area under a discrete section of curve is effectively the height*width, where height is amplitude and width is the number of seconds between each sample).

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

その他の回答 (3 件)

Dr. Seis
Dr. Seis 2012 年 1 月 20 日
You need to make a few changes:
If,
dt = 0.0001;
t = 0:dt:(0.05-dt);
N = length(t);
y_time = square(5*pi*50*t);
Then,
df = 1 / (N*dt);
Nyq = 1 / (2*dt);
f = -Nyq : df : Nyq-df;
y_freq = fftshift(fft(y_time))*dt;
Now you can plot the correct amplitudes with the correct frequencies:
plot(f,real(y_freq),'b-',f,imag(y_freq),'r-');
  1 件のコメント
Robin Beene
Robin Beene 2012 年 1 月 20 日
Thank You very much

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


Robin Beene
Robin Beene 2012 年 1 月 20 日
I thought I need to divide it with N=length(y_time)[because Amplitudes seems to me more realistic] not to multiply with dt but I guess I was wrong.
  1 件のコメント
Dr. Seis
Dr. Seis 2012 年 1 月 20 日
Think of Parseval's theorem, the energy in the time domain is equal to the energy in the frequency domain. If this condition is not met, then it is a flag that something has gone wrong.

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


Robin Beene
Robin Beene 2012 年 1 月 20 日
And One more question if I may: How to draw it on logarithmic scale
maybe like this? plot(f,20*log10(imag(y_freq)/max(abs(y_freq))),'r-');
  2 件のコメント
Dr. Seis
Dr. Seis 2012 年 1 月 20 日
To have just the y-axis plotted on logarithmic scale, try:
semilogy(f, imag(y_freq));
If you want just the x-axis plotted on logarithmic scale, then:
semilogx(f, imag(y_freq));
If you want x- and y-axis plotted on logarithmic scale, then:
loglog(f, imag(y_freq));
Robin Beene
Robin Beene 2012 年 1 月 20 日
thx a lot

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

カテゴリ

Help Center および File ExchangeGet Started with Signal Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by