%Esercitazione richiami analisi segnali %Definizione dei segnali t=[1:1000]; x=cos(0.5*t); x1=cos(0.25*t); x2=x+x1; w=randn(size(t)); x3=x1+w; %sommato con rumore gaussiano x4=cos(0.5*t+w); % rumore sommato sulla fase %DFT DFTx=fft(x); %NB: è un numero complesso DFTabsX=abs(DFTx); figure; plot(DFTabsX); n=length(DFTx); plot(DFTabsX(n/2-1:length(DFTx))); DFTx1=fft(x1); DFTabsX1=abs(DFTx1); plot(DFTabsX1(n/2-1:length(DFTx1))); figure;plot(DFTabsX1(n/2-1:length(DFTx1))); figure;plot(DFTabsX1); DFTx2=fft(x2); DFTabsX2=abs(DFTx2); figure;plot(DFTabsX2); DFTx3=fft(x3); DFTx4=fft(x4); DFTabsX3=abs(DFTx3); DFTabsX4=abs(DFTx4); hold on; plot(DFTabsX3,'r'); hold on; plot(DFTabsX4,'k') figure; plot(DFTabsX,'r'); hold on; plot(DFTabsX4,'k') figure; plot(DFTabsX1,'r'); hold on; plot(DFTabsX3,'k') %autocorrelazione [acfX,lagX]=autocorr(x,100); figure; plot(lagX,acfX,'b');hold on; plot(-lagX,acfX,'b'); [acfX2,lagX2]=autocorr(x2,100); figure; plot(lagX2,acfX2,'b');hold on; plot(-lagX2,acfX2,'b'); [acfw,lagw]=autocorr(w,100); figure; plot(lagw,acfw,'b');hold on; plot(-lagw,acfw,'b'); [acfX3,lagX3]=autocorr(x3,100); figure; plot(lagX3,acfX3,'b');hold on; plot(-lagX3,acfX3,'b'); [acfX4,lagX4]=autocorr(x4,100); figure; plot(lagX4,acfX4,'b');hold on; plot(-lagX4,acfX4,'b'); %crosscorrelazione [ccfX2X3,lagC]=crosscorr(x2,x3,100); figure; plot(lagC,ccfX2X3); [ccfX1X3,lagC]=crosscorr(x1,x3,100); [ccfXX3,lagC]=crosscorr(x,x3,100); figure; plot(lagC,ccfX1X3);hold on; plot(lagC,ccfXX3,'r'); %Spettro di potenza - periodogramma fs=512; t2=[0:1/fs:60]; w2=randn(size(t2)); y=cos(2*pi*35*t2)+cos(2*pi*60*t2)+w2; [Pyy,W]=periodogram(y); [Pyy,f]=periodogram(y,hanning(length(y)),length(y),fs); nfft=512; [PyyW,F] = pwelch(y,hanning(nfft),0,nfft,fs); %Cross-spettro w3=randn(size(t2)); y2=5*cos(2*pi*35*t2)+cos(2*pi*115*t2)+cos(2*pi*60*t2)+w3; [Pxy,Fx] = cpsd(y,y2,hanning(nfft),0,nfft,fs); [Cxy,Fc] = mscohere(y,y2,hanning(nfft),0,nfft,fs); figure; plot(Fx,abs(Pxy)); figure; plot(Fc,abs(Cxy));