www.gusucode.com > phased 案例源码 matlab代码程序 > phased/PlotCorrelationsFromGCCEstimatorExample.m

    %% Plot Correlations from GCC Estimator
% Estimate the direction of arrival of a signal using GCC-PHAT. The
% receiving array is a 5-by-5-element URA microphone array with elements
% spaced 25 centimeters apart. Choose 10 element pairs to compute the arrival
% angle. Assume the speed of sound in air is 340 meters/second. The
% arriving signal is a sequence of wideband sounds. Assume the signal
% arrives from 54 degrees azimuth and five degrees elevation. Estimate the
% arrival angle, and then plot the correlation function versus lag for a
% pair of elements.

% Copyright 2015 The MathWorks, Inc.


%%
% Load the signal and extract a small portion for computation.
load gong;
y1 = y(1:100);
%%
% Set up the receiving array.
N = 5;
d = 0.25;
sMic = phased.OmnidirectionalMicrophoneElement;
sURA = phased.URA([N,N],[d,d],'Element',sMic);

%%
% Simulate the arriving plane wave using the |WidebandCollector| System
% object(TM).
c = 340.0;
arrivalAng = [54;5];
sWBC = phased.WidebandCollector('Sensor',sURA,...
    'PropagationSpeed',c,...
    'SampleRate',Fs,...
    'ModulatedInput',false);
signal = step(sWBC,y1,arrivalAng);
%%
% Estimate direction of arrival. Choose 10 sensors to correlate with
% the first element of the URA.
sensorpairs = [[2,4,6,8,10,12,14,16,18,20];ones(1,10)];
sGCC = phased.GCCEstimator('SensorArray',sURA,...
    'PropagationSpeed',c,'SampleRate',Fs,...
    'SensorPairSource','Property',...
    'SensorPair',sensorpairs,...
    'DelayOutputPort',true','CorrelationOutputPort',true);
[estimatedAng,taus,R,lags] = step(sGCC,signal);
%%
% The estimated angle is:
disp(estimatedAng)
%%
% Plot the correlation between sensor 8 and sensor 1. This pair corresponds to the fourth
% column of the correlation matrix. The estimated value of tau (in milliseconds) for this
% pair is:
disp(1000*taus(4))
plot(1000*lags,real(R(:,4)))
xlabel('Time lags (msec)')
ylabel('Correlation')