Clear Filters
Clear Filters

Communications Toolbox - AGC module Matlab script does not yield the same output as Simulink block

4 views (last 30 days)
I'm exploring the AGC module of Communication, however the script does not execute as good as the Simulink models for some reason. I'm testing it with a about 25 times scaled 16-QAM constellation. Injecting the same input to Simulink block and and Matlab script yield 2 different results, that the result from Simulink is far better than Matlab script as following:
Up: from Simulink, Down: from sciprt.
I adjust every properties the same between 2 models. The constellation of Simulink output is draw by:
scatterplot(out.new_agc.Data(:,:,end));
My respective code and Simulink model can be found attached. It's really strange to me, my guess is that AGC module reuse some properties from previous loops, but it's not yet available in my code.

Answers (1)

UDAYA PEDDIRAJU
UDAYA PEDDIRAJU on 13 May 2024
Hi Mason,
The difference between Simulink and MATLAB AGC outputs likely boils down to three things:
  1. Data Check: Make sure the data you use in both environments is loaded and formatted identically.
  2. AGC Settings Match? Double-check that the AGC properties in your MATLAB script are exactly the same as those used in the Simulink block.
  3. Simulink Extras? Your Simulink model might have additional processing steps affecting the AGC output. Consider these if present
I have tried making some changes in your code, you work on this, I am sure you'll able to figure it out.
  • Move AGC Object Creation: Instead of creating a new agc object in each loop iteration, create it outside the loop with desired properties (e.g., "AdaptationStepSize", "DesiredOutputPower").
  • Loop Through Data: Within the loop, simply apply the existing agc object to each data segment to achieve AGC and process/plot the results.
  • Persistent State: This approach allows the agc object's gain value to adapt continuously across the entire data sequence, mimicking the Simulink block's behavior.
  • Optional Release: Releasing the object after the loop is good practice for memory management (optional).
load('out.mat');
% AGC object creation
agc = comm.AGC('AdaptationStepSize', 0.01, ...
'DesiredOutputPower', 0.9, ...
'AveragingLength', 128, ...
'MaxPowerGain', 10);
% Loop through the data
for ii = 1:size(need_gain_data, 3)
txSig = need_gain_data(:,:,ii);
% Apply AGC
rxSig = agc(txSig);
% Plot constellation diagram
figure(1)
scatter(real(txSig(1:end)), imag(txSig(1:end)), '*');
hold on
scatter(real(rxSig(1:end)), imag(rxSig(1:end)), 'or');
title('Constellation Diagram (Before & After AGC)');
xlabel('Real Part');
ylabel('Imaginary Part');
legend('Input of AGC', 'Output of AGC');
hold off;
% Additional processing or analysis (optional)
% ...
end
% Release the object after the loop (optional)
release(agc);

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!