Reversing a function at the Receiver side

2 次查看(过去 30 天)
Hello all, I have the following code:
%%%%%%Reciver
intial_value = 0;
x_hat = [];
%% Predictator
%%OLD
if p == 1
for i3 = 1:numel(d_k)
x_ind = intial_value +dq_tx(i3);
x_hat = [x_hat x_ind];
intial_value = x_ind;
end
end
which is a demodulation at the reciever side, from the following modulation
%% x_k is the message signal
x_kdelay = [0 x_k(1:end-1)]; %Delay by 1 unit
if p == 1
d_k = x_k - x_kdelay;
Now I wrote this function to modulate the input signal in the case of p=2
elseif p == 2
for i5= 1: numel(x_k)
if i5 <=1
d_k(i5) = x_k(i5) - (x_kdelay(i5));
else
d_k(i5) = x_k(i5) - (x_kdelay(i5)+x_kdelay(i5-1));
end
end
And I want to write a similar function at the reciever side that de-modulates that, any help would be apprechiated.

回答(1 个)

Yash
Yash 2023-8-29
Hi Abdelrhman,
As I can see, you have a modulator at the transmitter side, and you want a demodulator at the receiver side to reproduce the original signal.
For this, you need to model the inverse of the modulation function.
Please see the code below (for p=2):
prev=0;
for i = 1:numel(d_k)
if i <= 1
x_ind = d_k(i) + prev;
else
x_ind = d_k(i) + x_hat(i-1) + prev;
prev = x_hat(i-1);
end
x_hat(i) = x_ind;
end
Here d_k is the modulated signal and x_hat is the demodulated signal.
Below is the full script integrated with your modulation code:
%% Initialize the variables
p=2;
x_k = [1 2 3 4 5]; % Original Signal
d_k = zeros(1,length(x_k)); % Modulated Signal
x_hat = zeros(1,length(x_k)); % Demodulated Signal
%% Modulation
% x_k is the message signal
x_kdelay = [0 x_k(1:end-1)]; %Delay by 1 unit
if p == 1
d_k = x_k - x_kdelay;
elseif p == 2
for i5 = 1:numel(x_k)
if i5 <=1
d_k(i5) = x_k(i5) - (x_kdelay(i5));
else
d_k(i5) = x_k(i5) - (x_kdelay(i5)+x_kdelay(i5-1));
end
end
end
d_k
d_k = 1×5
1 1 0 -1 -2
%% Demodulation
prev = 0;
if p == 1
for i3 = 1:numel(d_k)
x_hat(i3) = prev + d_k(i3);
prev = x_hat(i3);
end
% Function that is required
elseif p==2
for i = 1:numel(d_k)
if i <= 1
x_ind = d_k(i) + prev;
else
x_ind = d_k(i) + x_hat(i-1) + prev;
prev = x_hat(i-1);
end
x_hat(i) = x_ind;
end
end
x_hat
x_hat = 1×5
1 2 3 4 5
You can see that the original signal is reproduced. You can change the value of p to check the signal is reproduced for p=1 as well.
Note that I have made a small change in demodulation code for p=1 as well. This was because in the code provided by you the size of array x_hat was changing for each loop iteration. I have preallocated the space to make it faster.

产品

Community Treasure Hunt

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

Start Hunting!

Translated by