Is my matlab code for the sinc signal below correct.
Mostra commenti meno recenti
I want to create and plot the signal equation below in matlab. The Coefficients ak are uniformly distributed in [−1, 1]. c is a constant.

Here is my code:
%************ Variable declaration******************
t = -20:0.1:20;
p = -10:1:10
data = 0;
signal = zeros(1,length(t)); %for spped allocations
c = 25 % constant
ak = -1 + 2*rand(1,21); % numbers in the interval (a,b) with the formula r = a + (b-a).*rand(N,1).
count = 1;
%********************************************************************************************
for i = t
for k = p
data = data + c*ak(k+11)*sinc(i-k);
end
signal(counter) = data;
counter = counter + 1;
end
plot(t,signal);
Thanks in advance.
Risposta accettata
Più risposte (1)
%************ Variable declaration******************
t = -20:0.1:20;
p = -10:1:10;
signal = zeros(1,length(t)); %for spped allocations
c = 25; % constant
ak = -1 + 2*rand(1,21); % numbers in the interval (a,b) with the formula r = a + (b-a).*rand(N,1).
%********************************************************************************************
for i = 1:length(t)
data = 0;
for k = 1:length(p)
data = data + c*ak(k)*sinc(t(i)-p(k));
end
signal(i) = data;
end
plot(t,signal);
6 Commenti
Afuaab Koohg
il 5 Ott 2022
ak = -1 + 2*rand(1,21);
The above line generate different random numbers for each run so that you will see different results. If you want to have same results:
rng('default'); % this will reset the seed number for random number generator
ak = -1 + 2*rand(1,21);
Afuaab Koohg
il 5 Ott 2022
In the code above, "data" has to be reset to 0 after the k-loop.
Further
data = data + c*ak(k)*sinc(t(i)-p(k));
instead of
data = data + c*ak(k)*sinc(i-p(k));
Otherwise the code is wrong.
Afuaab Koohg
il 6 Ott 2022
Categorie
Scopri di più su Graphics Performance in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

