cpsd

Compute cross spectral densities.

Syntax

Rxy=cpsd(x,y,window,overlap,Nfft,Fs,range)

[Rxy,freq]=cpsd(...)

Inputs

x
The first signal.
Type: double
Dimension: vector
y
The second signal.
Type: double
Dimension: vector
window
The window size, or the window vector.
Type: double | integer
Dimension: scalar | vector
overlap
The amount of overlap of adjacent windows.
Type: integer
Dimension: scalar
Nfft
The size of the fft.
Type: integer
Dimension: scalar
Fs
The sampling frequency.
Type: double
Dimension: scalar
range
The spectrum type: 'one-sided' or 'two-sided'.
Type: string

Outputs

Rxy
The cross correlation.
Type: vector
freq
The vector of frequencies.
Type: vector

Example

n = 1000;                           
fs = 1000;                             
ts = 1/fs;              
t = [0:ts:(n-1)*ts];
f1 = 10;
f2 = 50;
omega1 = 2 * pi * f1;
omega2 = 2 * pi * f2;
signal1 = 3 + 5 * cos(omega1 * t) + 7 * cos(omega2 * t);
signal2 = 3 + 7 * cos(omega1 * t) + 3 * sin(omega2 * t);
window = ones(1,250);
overlap = 125;
fftSize = 250;
range = 'onesided';
[Rxy,freq]=cpsd(signal1,signal2,window,overlap,fftSize,fs,range)
ans = [ 0.0193237206452513 ; 0.0625983361188996 ; 0.46206619264326 ; 0.431330936312374 ; 0.0454400869591055 ; 0.0148098943008941 ; 0.00818540911974635 ; 0.00481197425945345 ; 0.00303940902467596 ; 0.00453254501418759 ; 0.0100754575719727 ; 0.0288373912908326 ; 0.261821342676756 ; 0.273860673189385 ; 0.0335476053206303 ; 0.0137268497595971 ; 0.00800173657193322 ; 0.0054879812097833 ; 0.00411589476501803 ; 0.0032614952546088 ; 0.00268124528625443 ; 0.00226259202227957 ; 0.00194689690186452 ; 0.00170075801888771 ; 0.00150379344651517 ; 0.00134287000109503 ; 0.00120914460616587 ; 0.00109644359955764 ; 0.00100032494552329 ; 0.000917510055613605 ; 0.000845525812511166 ; 0.000782471317083185 ; 0.000726861403389364 ; 0.00067751894137931 ; 0.000633499030358259 ; 0.000594034564535191 ; 0.000558496443162438 ; 0.000526364017222698 ; 0.000497202820888016 ; 0.000470647571910183 ; 0.000446389039498526 ; 0.000424163789411172 ; 0.000403746096043043 ; 0.000384941505150202 ; 0.000367581667048802 ; 0.000351520157135182 ; 0.000336629070551214 ; 0.000322796228895545 ; 0.000309922874570038 ; 0.000297921756448591 ; 0.000286715531701393 ; 0.000276235424664752 ; 0.000266420095942595 ; 0.000257214684414777 ; 0.000248569992205328 ; 0.000240441788440045 ; 0.000232790212175262 ; 0.000225579258489699 ; 0.000218776334611129 ; 0.000212351875259949 ; 0.000206279008254408 ; 0.000200533262932797 ; 0.000195092315177418 ; 0.00018993576383168 ; 0.000185044934128318 ; 0.000180402704429495 ; 0.000175993353144674 ; 0.0001718024231623 ; 0.000167816601524173 ; 0.00016402361240006 ; 0.000160412121695976 ; 0.000156971651863796 ; 0.000153692505675496 ; 0.000150565697893954 ; 0.000147582893913458 ; 0.000144736354565303 ; 0.000142018886387295 ; 0.000139423796745124 ; 0.000136944853270429 ; 0.000134576247146229 ; 0.000132312559827489 ; 0.000130148732834092 ; 0.000128080040296334 ; 0.000126102063970374 ; 0.000124210670473573 ; 0.000122401990518062 ; 0.000120672399945754 ; 0.000119018502389724 ; 0.000117437113406114 ; 0.000115925245937405 ; 0.000114480096982913 ; 0.000113099035365319 ; 0.000111779590493691 ; 0.000110519442033632 ; 0.000109316410404557 ; 0.000108168448031795 ; 0.000107073631288692 ; 0.000106030153070265 ; 0.000105036315945657 ; 0.000104090525841696 ; 0.000103191286214638 ; 0.000102337192671093 ; 0.00010152692800286 ; 0.000100759257603945 ; 0.000100033025240707 ; 9.93471491489776e-005 ; 9.87006184343808e-005 ; 9.80924897543738e-005 ; 9.75218842624093e-005 ; 9.69879847964897e-005 ; 9.64900332961304e-005 ; 9.60273284331462e-005 ; 9.55992234431177e-005 ; 9.52051241456575e-005 ; 9.48444871427738e-005 ; 9.45168181856756e-005 ; 9.42216707014145e-005 ; 9.39586444715926e-005 ; 9.37273844563331e-005 ; 9.35275797574679e-005 ; 9.335896271558e-005 ; 9.32213081364262e-005 ; 9.31144326427869e-005 ; 9.30381941484637e-005 ; 9.29924914518821e-005 ]