1+ function [frequenciesIEC , spectrumIEC , spreadIEC , directionsIEC ] = convertOOIToIEC(spectrumDataOOI , directionBins , plotFlag )
2+
3+ directionBins = wrapTo180(directionBins );
4+ if any(directionBins == 180 ) && any(directionBins == - 180 )
5+ warning(' Directions include both -180 and 180. Removing -180 to avoid duplicate directions.' )
6+ directionBins(directionBins == - 180 ) = [];
7+ end
8+ if length(unique(mod(directionBins + 180 , 360 ) - 180 )) < length(directionBins )
9+ error(' Duplicate directions were found.' )
10+ end
11+
12+ frequenciesOOI = spectrumDataOOI(: ,1 );
13+ spectrumOOI = spectrumDataOOI(: ,2 );
14+ directionsOOI = spectrumDataOOI(: ,3 );
15+ spreadOOI = spectrumDataOOI(: ,4 );
16+
17+ % convert to IEC:
18+ directionsIEC = directionBins(: );
19+ frequenciesIEC = frequenciesOOI ;
20+ spectrumIEC = spectrumOOI ;
21+ spreadIEC = zeros(length(frequenciesIEC ),length(directionsIEC ));
22+
23+ % for spread, we need to apply gaussian distribution
24+ for ii = 1 : length(frequenciesOOI )
25+ % convert to IEC spread calculation
26+ directions = deg2rad(wrapTo180(directionBins - wrapTo180(directionsOOI(ii ))));
27+ energySpread = (1 ./(deg2rad(spreadOOI(ii )).*sqrt(2 * pi ))) .* exp(-(directions .^ 2 ) ./ (2 .* deg2rad(spreadOOI(ii )).^2 ));
28+ checkSum = trapz(deg2rad(directionBins ),energySpread );
29+ if checkSum < 0.95 % if this is true, then less than 95% of the initial energy at this frequency is contained over the considered directions.
30+ warning(' Number of directional bins inadequate at frequency number %i . Directional approximation weak. \n \r ' , ii );
31+ end
32+ energySpread = energySpread ./ checkSum ;
33+ spreadIEC(ii ,: ) = energySpread ;
34+ end
35+
36+ if plotFlag == 1
37+ spectrumFullDir = spreadIEC .* spectrumIEC ;
38+ meanDirection = sum(wrapTo180(directionsOOI ).*spectrumOOI )/sum(spectrumOOI );
39+
40+ [plotDirs ,plotFreqs ] = meshgrid(directionsIEC ,frequenciesIEC );
41+
42+ figure()
43+ polarscatter(deg2rad(plotDirs(: )),plotFreqs(: ),4 ,spectrumFullDir(: ),' filled' )
44+ hold on
45+ polarplot(deg2rad([meanDirection meanDirection ]), [0 max(plotFreqs(: ))], ' k--' ); %
46+ c = colorbar ;
47+ c.Label.String = ' Spectrum (m^2/Hz/deg)' ;
48+ title(' Elevation variance spectrum' );
49+ legend(' spectrum' ,' approx. mean direction' ,' Location' ,' northwest' )
50+ end
51+ end
0 commit comments