Is my matlab code for the sinc signal below correct.

1 Ansicht (letzte 30 Tage)
Afuaab Koohg
Afuaab Koohg am 5 Okt. 2022
Kommentiert: Afuaab Koohg am 6 Okt. 2022
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.

Akzeptierte Antwort

Torsten
Torsten am 5 Okt. 2022
Bearbeitet: Torsten am 5 Okt. 2022
%************ Variable declaration******************
rng('default')
t = -20:0.1:20;
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)
T = t(i);
data = 0;
for k = -10:1:10
data = data + ak(k+11)*sinc(T-k);
end
signal(i) = c*data;
end
plot(t,signal)

Weitere Antworten (1)

Chunru
Chunru am 5 Okt. 2022
Bearbeitet: Chunru am 6 Okt. 2022
%************ 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 Kommentare
Chunru
Chunru am 6 Okt. 2022
@Torsten Yes. You are right. Corrected.
Afuaab Koohg
Afuaab Koohg am 6 Okt. 2022
Thanks so much @Torsten and @Chunru: I accept the solutions that you have provided.
Are you able to help my other question please?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Spectral Analysis finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by