MATLAB: Fourier-Frequency analyse

fourierfrequency analyse

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])

Best Answer

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?