image thumbnail

What's New for Object-Oriented Programming in MATLAB Webinar - Code Examples

by

 

10 Apr 2008 (Updated )

Code examples used in "What's New for Object-Oriented Programming in MATLABĀ®" Webinar

Data=gendata(Targets,NumSensors,NumSamples,SampleRate,Spacing,SNR,c)
function Data=gendata(Targets,NumSensors,NumSamples,SampleRate,Spacing,SNR,c)
% Generates the sensor sample data

% Some parameers
numTargets=size(Targets,1);
orgX=(NumSensors+1)/2;
Data=zeros(NumSamples,NumSensors);

% For each source/target, calculate the amplitue at the array and sum
for tar=1:numTargets
    bearing=0.5*pi-Targets(tar,1);  % Source angle
    range=Targets(tar,2);           % Source range
    A=Targets(tar,3);               % Source amplitude
    freq=Targets(tar,4);            % Source frequency
    tx=range*cos(bearing);          % Source X position
    ty=range*sin(bearing);          % Source Y position
    s=(1:NumSensors);               % Sensors row vector
    d=sqrt((tx+orgX-s*Spacing).^2+(ty)^2);   % Distance to source
    t=d/c;                          % Time delay to source
    for k=1:NumSamples
        Data(k,:)=Data(k,:)+A*exp(j*(t-k/SampleRate)*2*pi*freq);
    end
end

% Add noise
for k=1:NumSamples
    Data(k,:)=noisyvar(Data(k,:).',SNR,numTargets).';
end

function y=noisyvar(x,snr,num)
% Add noise of certain SNR to given signal

A=1;
noise=(A/(sqrt(2)))*randn(length(x),1)+(A/(sqrt(2)))*j*randn(length(x),1);
powx=(x'*x)/length(x)/num;
pown=(noise'*noise)/length(x);
rwant=10^(snr/10);
nwant=(noise/sqrt(pown))*sqrt(powx/rwant);
y=x+nwant;

Contact us