% Routine for computing coherence function. % % Syntax: [gam,cxy] = cohrnce(x,y) % % by D. Holmgren, Aug 10 94. holmgren@phobos.astro.uwo.ca function [gam,cxy] = cohrnce(x,y) wx = zeros(2048,1); wy = wx; nx = length(x); ny = length(y); wx(1:nx) = x; wy(1:ny) = y; X = fft(wx); Y = fft(wy); % shift and smooth spectra... Xs = fftshift(X); Ys = fftshift(Y); Xsm = smooth(Xs); Ysm = smooth(Ys); % compute various power spectra... Gxy = Xsm .* conj(Ysm); Gxx = Xsm .* conj(Xsm); Gyy = Ysm .* conj(Ysm); % compute coherence... gam = Gxy ./ sqrt(Gxx .* Gyy); cxy = gam .* conj(gam);