Загрузка данных


clc;
clear;
close all;

len = 20000;
ampl = 10;
SNR = 25;

% Генерация сигнала QAM16
table = [-3-3j; -3-1j; -3+1j; -3+3j; ...
         -1-3j; -1-1j; -1+1j; -1+3j; ...
          1-3j;  1-1j;  1+1j;  1+3j; ...
          3-3j;  3-1j;  3+1j;  3+3j];

p = randi([1;16], len, 1);
out = table(p) * ampl;

res = resample(out, 20, 1);
res2 = awgn(res, SNR, 'measured');

step = 16;
win = 1024;
Fs = 10000;

for i = 1:step:length(res2)-win

    res3 = res2(i:win+i-1);

    % 1. Созвездие
    subplot(2,2,1);
    plot(real(res3), imag(res3), '.');
    title('Созвездие QAM16');
    xlabel('Real');
    ylabel('Imag');
    grid on;

    % 2. Сигнал
    subplot(2,2,2);
    plot(real(res3), 'r');
    hold on;
    plot(imag(res3), 'b');
    hold off;
    title('Сигнал QAM16');
    xlabel('Отсчёты');
    ylabel('Амплитуда');
    legend('Real', 'Imag');
    grid on;

    % 3. Спектр
    subplot(2,2,3);
    SP = 20*log10(abs(fftshift(fft(res3))) + eps);
    f = (-win/2:win/2-1)*(Fs/win);

    plot(f, SP);
    hold on;
    [a, ind] = max(SP);
    plot(f(ind), a, '*r');
    text(f(ind), a, [' Max = ', num2str(a, '%.2f'), ' dB']);
    hold off;
    title('Спектр QAM16');
    xlabel('Частота, Гц');
    ylabel('Амплитуда, dB');
    grid on;

    % 4. Спектрограмма
    subplot(2,2,4);
    spectrogram(res3, 128, 96, 256, Fs, 'yaxis');
    title('Спектрограмма QAM16');

    drawnow;
    pause(0.1);
end