How to code following equation in MATLAB ?

2 visualizzazioni (ultimi 30 giorni)
charu shree
charu shree il 22 Giu 2023
Risposto: Divyajyoti Nayak il 23 Giu 2023
Hello all, I am trying to code the following equation but not getting it correctly.
--- (1)
where , , , f is complex Gaussian random variable (rv) with variance 1 and is also complex Gaussian rv with variance 1. Assume ,
Here basically we have to find for each .
Any help in this regard will be highly appreciated.
  3 Commenti
charu shree
charu shree il 22 Giu 2023
@MANIK, Thank you so much for your reply. ζ is not an integral sign but basically its a constant with values between 0 and 1 so we may assume it as 0.5.
charu shree
charu shree il 22 Giu 2023
I tried with the code in two different ways :
My query is which is the correct way and can we do it without using for loop.
%% First Way
clc;
clear all;
close all;
% Initialization
N = 256;
zeta = 0.5;
M = 10^3;
sn = sqrt(1/2)*(randn(1,N)+1i*randn(1,N)); % This is s(n)
f = sqrt(1/2)*(randn(1,1)+1i*randn(1,1)); % This is f
cn = [];
for m = 1: M
B = 1;
cn_1 = zeta*f*sn*B;
cn = [cn,cn_1]; % This is c(n)
end
%% Second Way
clc;
clear all;
close all;
% Initialization
N = 256;
zeta = 0.5;
M = 10^3;
sn = sqrt(1/2)*(randn(1,N)+1i*randn(1,N)); % This is s(n)
f = sqrt(1/2)*(randn(1,1)+1i*randn(1,1)); % This is f
for m = 1: M
B = 1;
cn = zeta*f*sn*B; % This is c(n)
end

Accedi per commentare.

Risposte (1)

Divyajyoti Nayak
Divyajyoti Nayak il 23 Giu 2023
Hi Charu,
There are a few issues with both your methods and I also have some doubts about the equation. Is B(m) a function of m and you are assuming B(m) = 1 but want the code to also work for other functions? If so then the lhs of the equation should be c(m,n) not c(n). If B is a constant then it should be just B and not B(m).
In your first method:
You are placing an array inside another array and doing that in a loop.
So after first iteration, cn = [ [], cn1(1)], after second iteration cn = [[ [], cn1(1)], cn1(2)] and so on.
Also in both methods you are not using the index m anywhere inside the loop so the loop is kind of redundant.
In your second method:
Firstly, cn is not an array so you will get only one value at the end (i.e. c(M)).
Secondly, you want N elements in cn but are looping from 1 to M so cn will only be calculated M times not N.
Solution:
I'm giving 2 solutions for getting c(n) and c(m,n).
N = 256;
zeta = 0.5;
M = 10^3;
sn = sqrt(1/2)*(randn(1,N)+1i*randn(1,N)); % This is s(n)
f = sqrt(1/2)*(randn(1,1)+1i*randn(1,1)); % This is f
%If B is a constant
B = 1;
cn = zeta*f*sn*B;
%If B(m) is a function of m
Bm = ones(M,1); %I have taken B(m) = 1, if it is some other function you have to calculate the values
cmn = zeta*f*Bm*sn;
In MATLAB the * operator by default does matrix multiplication so you don't have to loop through elements.

Categorie

Scopri di più su Mathematics and Optimization in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by