I am trying to plot the frequency spectrum of a sinewave with frequency 77.5 kHz and amplitude 2. Only the zero-point is not correct, it is shifted to the left. My code:
f1=77.5e3; % frequency of the sinewave
a1=2; % amplitude of the sinewave
Fs = 1.55e6; % sampling frequency
dt=1/Fs; % step size
maxtime = 5*(1/f1);
t=0:dt:maxtime; % time interval in which we want to plot
x=a1*sin(2*pi*f1*t); % the values for the sinewave
N=length(t); % this is how many samples we have in the time-domain
X=fft(x)/N;
X=fftshift(X);
f=[-N/2:1:N/2-1]*Fs/N; % creates a frequency axis
figure(1)
plot(f,abs(X))
title('Magnitude Spectrum of x(t)')
xlabel('Frequency [Hz]')
ylabel('|X(f)|')
When I run this code I get an incorrect frequency spectrum. Can anyone help me out?
Edit: the figure I get when running this code:
Besides the incorrect zero-point I also get an incorrect frequency when I count it out myself from the plot. I'm just not sure how I should plot such a sinewave with frequency 77.5kHz, amplitude 2 and sampling frequency 1.55 MHz
fftshift
?? why not justfft(x,N)/N
? – Rashidfftshift
necessary? – B_sfft(x,N)
– Rashid