Hi Ali,
To add group delay using the “grpdelay” function in MATLAB, you need to design a filter that introduces the desired group delay and then apply this filter to your signal. Below is modified code for the same:
clc;
clear all;
% Parameters
M = 32;
numSymbols = 100e3;
SNR = 27; % Signal-to-noise ratio in dB
groupDelay = 5; % Desired group delay in samples
% Generate random data
x = randi([0 M-1], numSymbols, 1);
% Modulate the data using QAM
y = qammod(x, M);
% Add AWGN noise
ynoisy = awgn(y, SNR, 'measured');
% Design an FIR filter to introduce the desired group delay
b = fir1(2*groupDelay, 0.5); % Low-pass filter with order 2*groupDelay
h = dfilt.dffir(b);
% Apply the filter to introduce group delay
yDelayed = filter(h, [ynoisy; zeros(groupDelay, 1)]);
yDelayed = yDelayed(groupDelay+1:end); % Remove the initial transient
% Scatter plot of noisy signal with group delay
scatterplot(yDelayed), grid on;
title('Noisy QAM Signal with Group Delay');
% Demodulate the delayed signal
z = qamdemod(yDelayed, M);
% Plot transmitted vs. received data
figure(2);
subplot(2,1,1);
stem(x(1:10), 'filled'), grid on;
title('Transmitted Data');
subplot(2,1,2);
stem(z(1:10), 'filled'), grid on;
title('Received Data');
% Calculate symbol error rate
[num, ty] = symerr(x, z);
disp(['Number of symbol errors: ', num2str(num)]);
disp(['Symbol error rate: ', num2str(ty)]);
For detailed information on “qammod” and “qamdemod” refer to the following documentation:
- https://www.mathworks.com/help/comm/ref/qamdemod.html
- https://www.mathworks.com/help/comm/ref/qammod.html
Hope that Helps!