clear all;
addpath(genpath('.'));
load('D:\mat_workspace\Signal_Processing\data\mnist_uint8.mat');
x_tr1=train_x(1,:);
t=1:1:784;
data = x_tr1;
x=data;
Fs=50;
L=length(x);
NFFT = 2^nextpow2(L);
f = Fs/2*linspace(0,1,NFFT/2+1);
figure,plot(t,x_tr1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Y = fft(x,NFFT)/L;
figure,plot(f,2*abs(Y(1:NFFT/2+1)))
title('Single-Sided Amplitude Spectrum of y(t)')...
,xlabel('Frequency (Hz)')...
,ylabel('|Y(f)|');
X=fftshift(fft(x,NFFT));
Px=X.*conj(X)/(NFFT*L); %Power of each freq components
fVals=Fs*(-NFFT/2:NFFT/2-1)/NFFT;
figure,plot(fVals,10*log10(Px),'b');
title('Power Spectral Density');
xlabel('Frequency (Hz)')
ylabel('Power');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Y = fft(x,NFFT);
Pyy = Y.*conj(Y)/NFFT;
f = 1000/NFFT*(0:127);
figure,plot(f,Pyy(1:128))...
,title('Power spectral density')...
,xlabel('Frequency (Hz)');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% % Power spectrum is computed when you pass a 'power' flag input
% [P,F] = pwelch(x,ones(SegmentLength,1),0,NFFT,Fs,'power');
%
% helperFrequencyAnalysisPlot2(F,10*log10(P),'Frequency in Hz',...
% 'Power spectrum (dBW)',[],[],[-0.5 200]);
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% % Power spectral density is computed when you specify the 'psd' option
% [PSD,F] = pwelch(x,ones(SegmentLength,1),0,NFFT,Fs,'psd');
% pwr_band1 = bandpower(PSD,F,[50 70],'psd');
% pwr_band_dBW1 = 10*log10(pwr_band1); % dBW