%% R is the signal data points extracted from the timetable Datos03 %% tiempo is the signal time points. %% L is the number of data points (Length of the signal) %Time domain plot(Datos3.Time,Datos3.VarName1) R=Datos3.VarName1; tiempo=seconds(Datos3.Time); % FFT Fs=10240; % Sampling frequency T=1/Fs; % Sampling period a=size(tiempo) % Number of points L = a(1,1) % Length of signal Y = fft(R); P2 = abs(Y/L); P1 = P2(1:L/2+1); P1(2:end-1) = 2*P1(2:end-1); f = Fs*(0:(L/2))/L; plot(f,P1) xlim([0 400]) title('FFT') %PSD [SignalSpectrum,SignalFrequencies] = periodogram(R, ... [],[],Fs); plot(SignalFrequencies,SignalSpectrum) xlim([0 400]) title('PSD')
y = sin(2*pi*(0:9)/10) % correct but y = sin(2*pi*(0:10)/10) % incorrect
The code below gives two peaks, one at +160 kHz and one at -160 kHz for any number of fft points (above a minimum number), any number of complete oscillations in the time window and any amplitude. The abs(amplitude) of each peak is A/2, consistent with cos(w*t) = (1/2)(exp(i*w*t)+exp(-i*w*t)). If you want, as is common for plotting purposes, you could ignore the negative freqencies and double the height of the positive frequency peak.
f0 = 160e3; ncyc = 23; % number of cycles in time window A = 6; % amplitude psi = pi/6; % arbitrary phase angle N = 1299; % need N >2*ncyc to avoid aliasing t0 = 1/f0; T = ncyc*t0; % time window delt = T/N; t = (0:N-1)*delt; y = A*cos(2*pi*f0*t+psi); figure(1) plot(t,y);grid on delf = 1/(delt*N); % golden rule for fft if rem(N,2) ==0 f = (-N/2:N/2-1)*delf; else f = (-(N-1)/2:(N-1)/2)*delf; end z = fftshift(fft(y))/N; % fftshift to put f=0 in the middle figure(2) stem(f,abs(z),'o-');grid on
Matlabsolutions.com provides guaranteed satisfaction with a
commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain
experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support
to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been
empanelled after extensive research and quality check.
Matlabsolutions.com provides undivided attention to each Matlab
assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services
include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work
done at the best price in industry.