There is quadrature detector which receive radio signal and return its amplitude and instantaneous phase after performing hilbert transformation and transferring the signal to zero frequency. The main purpose of this device is save information about phase of received signal after digitizing (here is example of such receiver). Simplified structure of such detector shown below:
The following octave code try emulating the detector (I'm not sure that is correct):
% Prepare to work.
close all;
clear all;
clc;
% Main constant.
frequency_local_oscillator = 30e6;
frequency_intermediate = frequency_local_oscillator;
frequency_sampling = frequency_intermediate * 4;
time_begin = 0;
time_end = 10e-4;
time = linspace (time_begin, time_end, frequency_sampling * (time_end - time_begin) );
size = length (time);
% Pulse.
magnitude_pulse = 1.0;
phase_pulse = 0;
carrier_pulse = magnitude_pulse * cos (2 * pi * frequency_intermediate .* time + phase_pulse);
timeshift_pulse = time_begin + (time_end - time_begin) / 4;
duration_pulse = (time_end - time_begin) / 2;
envelope_pulse = zeros (1, size);
envelope_pulse = envelope_pulse + heaviside (time - timeshift_pulse) .* heaviside (duration_pulse - time + timeshift_pulse);
signal_pulse = carrier_pulse .* envelope_pulse;
if 0 % Make signal more realistic.
% Noise.
magnitude_noise = 0.01;
carrier_noise = magnitude_noise * randn (1, size);
signal = signal_pulse + carrier_noise;
else
signal = signal_pulse;
end
% Moving to zero frequency and and quadrature detection.
signal_i = signal .* cos (2 * pi * frequency_local_oscillator * time);
signal_q = -signal .* sin (2 * pi * frequency_local_oscillator * time);
% LPF.
[b a] = ellip (4, 0.1, 60, 0.1);
signal_i_filtered = filter (b, a, signal_i);
signal_q_filtered = filter (b, a, signal_q);
% Decimation (performed at two stages with common ratio: 15 х 16 = 240).
signal_i_decimated = decimate (signal_i_filtered, 15);
signal_q_decimated = decimate (signal_q_filtered, 15);
signal_i_decimated = decimate (signal_i_decimated, 16);
signal_q_decimated = decimate (signal_q_decimated, 16);
% Time scale after decimation.
time_decimated = linspace (time_begin, time_end, length (signal_i_decimated) );
% Magnitude and instantaneous phase.
signal_magnitude = sqrt (signal_i_decimated .^ 2 + signal_q_decimated .^ 2);
signal_phase = atan2 (signal_q_decimated, signal_i_decimated);
% Display signal.
figure;
grid on;
subplot (2, 1, 1);
plot (time, signal, 'b');
hold on;
plot (time, envelope_pulse, 'r');
title ("Input signal.");
xlabel ("Time [s].");
ylabel ("Magnitude [V].");
subplot (2, 2, 3);
plot (signal_magnitude, 'b');
title ("Magnitude of the signal.");
xlabel ("Sample number.");
ylabel ("Magnitude [V].");
subplot (2, 2, 4);
plot (signal_phase, 'g');
title ("Phase of the signal.");
set (gca, 'YTick', -pi: pi / 2: pi)
set (gca, 'YTickLabel',{'-pi', '-pi / 2', '0', 'pi / 2','pi'})
xlabel ("Sample number.");
ylabel ("Phase [rad].");
Here is result of the code which looks in my opinion more or less real:

Question:
I have records of two different signals from output of the detector (desired signal and noise). And now I'd like to adding those signals (combine as if they was received simultaneously). Is it possible to do it and how can I do this?
The main purpose of this task is performing measurements of the the once recorded signal with different calibrated noises.
My attempts:
About possibility I think it's possible if all stages of the detector are linear. If it is true this allows swap processing stages.
In my opinion add together magnitudes and phases of signals is wrong. I think that this task can be solved with the following steps:
- revert conversion at I and Q;
- get sum of components of two signals;
- convert I and Q to magnitude and phase again.
Am I right?
