# Signal Simulation

This example shows how to apply the basic toolbox workflow to the following scenario: Assume you have a single isotropic antenna operating at 4 GHz. Assume the antenna is located at the origin of your global coordinate system. There is a target with a nonfluctuating radar cross section of 0.5 square meters initially located at (7000,5000,0). The target moves with a constant velocity vector of (-15;-10;0). Your antenna transmits ten rectangular pulses with a duration of 1 μs at a pulse repetition frequency (PRF) of 5 kHz. The pulses propagate to the target, reflect off the target, propagate back to the antenna, and are collected by the antenna. The antenna operates in a monostatic mode, receiving only when the transmitter is inactive.

### Waveform Model

To create the waveform, use the `phased.RectangularWaveform` System object™ and set the properties to the desired values.

```waveform = phased.RectangularWaveform('PulseWidth',1e-6, ... 'PRF',5e3,'OutputFormat','Pulses','NumPulses',1);```

See Rectangular Pulse Waveforms for more detailed examples on creating waveform.

### Antenna Model

To model the antenna, use the `phased.IsotropicAntennaElement` System object. Set the operating frequency range of the antenna to (1,10) GHz. The isotropic antenna radiates equal energy for azimuth angles from -180° to 180° and elevation angles from -90° to 90°.

`antenna = phased.IsotropicAntennaElement('FrequencyRange',[1e9 10e9]);`

### Target Model

To model the target, use the `phased.RadarTarget` System object. The target has a nonfluctuating RCS of 0.5 square meters and the waveform incident on the target has a carrier frequency of 4 GHz. The waveform reflecting off the target propagates at the speed of light. Parameterize this information in defining your target.

```target = phased.RadarTarget('Model','Nonfluctuating','MeanRCS',0.5, ... 'PropagationSpeed',physconst('LightSpeed'),'OperatingFrequency',4e9);```

### Antenna and Target Platforms

To model the location and movement of the antenna and target, use the `phased.Platform` System object. The antenna is stationary in this scenario and is located at the origin of the global coordinate system. The target is initially located at (7000,5000,0) and moves with a constant velocity vector of (-15,-10,0).

```antennaplatform = phased.Platform('InitialPosition',[0;0;0],'Velocity',[0;0;0]); targetplatform = phased.Platform('InitialPosition',[7000; 5000; 0], ... 'Velocity',[-15;-10;0]);```

For definitions and conventions regarding coordinate systems, see Global and Local Coordinate Systems.

Use the `rangeangle` function to determine the range and angle between the antenna and the target.

```[tgtrng,tgtang] = rangeangle(targetplatform.InitialPosition, ... antennaplatform.InitialPosition);```

See Motion Modeling in Phased Array Systems for more details on modeling motion.

### Modeling Transmitter

To model the transmitter specifications, use the `phased.Transmitter` System object. A key parameter in modeling a transmitter is the peak transmit power. To determine the peak transmit power, assume that the desired probability of detection is 0.9 and the maximum tolerable false-alarm probability is $1{0}^{-6}$. Assume that the ten rectangular pulses are noncoherently integrated at the receiver. You can use the `albersheim` function to determine the required signal-to-noise ratio (SNR).

```Pd = 0.9; Pfa = 1e-6; numpulses = 10; SNR = albersheim(Pd,Pfa,10);```

The required SNR is approximately 5 dB. Assume you want to set the peak transmit power in order to achieve the required SNR for your target at a range of up to 15 km. Assume that the transmitter has a 20 dB gain. Use the radar equation to determine the required peak transmit power.

```maxrange = 1.5e4; lambda = physconst('LightSpeed')/target.OperatingFrequency; tau = waveform.PulseWidth; Ts = 290; rcs = 0.5; Gain = 20; dbterm = db2pow(SNR - 2*Gain); Pt = (4*pi)^3*physconst('Boltzmann')*Ts/tau/rcs/lambda^2*maxrange^4*dbterm;```

The required peak transmit power is approximately 45 kilowatts. To be conservative, use a peak power of 50 kilowatts in modeling your transmitter. To maintain a constant phase in the pulse waveforms, set the `CoherentOnTransmit` property to `true`. Because you are operating the transmitter in a monostatic (transmit-receive) mode, set the `InUseOutputPort` property to `true` to record the transmitter status.

```transmitter = phased.Transmitter('PeakPower',50e3,'Gain',20,'LossFactor',0, ... 'InUseOutputPort',true,'CoherentOnTransmit',true);```

See Transmitter for more examples on modeling transmitters and Radar Equation (Radar Toolbox) for examples that use the radar equation.

### Modeling Waveform Radiation and Collection

To model waveform radiation from the array, use the `phased.Radiator` System object. To model narrowband signal collection at the array, use the `phased.Collector` System object. For wideband signal collection, use the `phased.WidebandCollector` System object.

In this example, the pulse satisfies the narrowband signal assumption. The carrier frequency is 4 GHz. For the value of the `Sensor` property, use the handle for the isotropic antenna. In the `phased.Collector` System object, set the `Wavefront` property to `'Plane'` to specify that the incident waveform on the antenna is a plane wave.

```radiator = phased.Radiator('Sensor',antenna,... 'PropagationSpeed',physconst('LightSpeed'),'OperatingFrequency',4e9); collector = phased.Collector('Sensor',antenna,... 'PropagationSpeed',physconst('LightSpeed'),'Wavefront','Plane', ... 'OperatingFrequency',4e9);```

To model the receiver, use the `phased.ReceiverPreamp` System object. In the receiver, you specify the noise figure and reference temperature, which are key contributors to the internal noise of your system. In this example, set the noise figure to 2 dB and the reference temperature to 290 Kelvin. Seed the random number generator to a fixed value for reproducible results.

```receiver = phased.ReceiverPreamp('Gain',20,'NoiseFigure',2, ... 'ReferenceTemperature',290,'SampleRate',1e6, ... 'EnableInputPort',true,'SeedSource','Property','Seed',1e3);```

See Receiver Preamp for more details.

### Modeling Propagation

To model the propagation environment, use the `phased.FreeSpace` System object. You can model one-way or two-propagation by setting the `TwoWayPropagation` property. In this example, set this property to `false` to model one-way propagation.

```channel = phased.FreeSpace(... 'PropagationSpeed',physconst('LightSpeed'), ... 'OperatingFrequency',4e9,'TwoWayPropagation',false, ... 'SampleRate',1e6);```

See Free Space Path Loss for more details.

### Implementing the Basic Radar Model

Having parameterized all the necessary components for the scenario, you are ready to generate the pulses, propagate the pulses to and from the target, and collect the echoes.

The following code prepares for the main simulation loop. Time step between pulses

```T = 1/waveform.PRF; % Get antenna position txpos = antennaplatform.InitialPosition; % Allocate array for received echoes rxsig = zeros(waveform.SampleRate*T,numpulses);```

You can execute the main simulation loop with the following code:

```for n = 1:numpulses % Update the target position [tgtpos,tgtvel] = targetplatform(T); % Get the range and angle to the target [tgtrng,tgtang] = rangeangle(tgtpos,txpos); % Generate the pulse sig = waveform(); % Transmit the pulse. Output transmitter status [sig,txstatus] = transmitter(sig); % Radiate the pulse toward the target sig = radiator(sig,tgtang); % Propagate the pulse to the target in free space sig = channel(sig,txpos,tgtpos,[0;0;0],tgtvel); % Reflect the pulse off the target sig = target(sig); % Propagate the echo to the antenna in free space sig = channel(sig,tgtpos,txpos,tgtvel,[0;0;0]); % Collect the echo from the incident angle at the antenna sig = collector(sig,tgtang); % Receive the echo at the antenna when not transmitting rxsig(:,n) = receiver(sig,~txstatus); end```

Noncoherently integrate the received echoes, create a vector of range gates, and plot the result. The red vertical line on the plot marks the range of the target.

```rxsig = pulsint(rxsig,'noncoherent'); t = unigrid(0,1/receiver.SampleRate,T,'[)'); rangegates = (physconst('LightSpeed')*t)/2; plot(rangegates/1e3,rxsig) hold on xlabel('range (km)') ylabel('Power') xline([tgtrng/1e3,tgtrng/1e3],'r') hold off``` 