PN Sequence Generator Code (2003)

8 visualizaciones (últimos 30 días)
Anorld Mkombwe
Anorld Mkombwe el 4 de Jun. de 2023
Editada: DGM el 4 de Jun. de 2023
%Please assist covert this to run in R2023a Matlab Version:
pntaps = [0 0 1 0 0 0 0 0 0 1];
pninitial = [0 0 0 0 0 0 0 0 0 1];
pndata = zeros(1,1023);
samp per sym = 1;
pnregister = pninitial;
n = 0;
kk = 0;
while kk == 0
n = n+1;
pndata(1,n) = pnregister(1,1);
feedback = rem((pnregister*pntaps’),2);
pnregister = [feedback,pnregister(1,1:9)];
if pnregister == pninitial; kk = 1; end
end
text = [‘The period is ’,num2str(n,15),‘.’];
disp(text)
pndata=replicate(pndata,samp per sym);
kn = n*samp per sym;
pndata = 2*pndata - 1;
a = fft(pndata);
b = a.*conj(a);
Rm = real(ifft(b))/kn;
x1 = (0:length(Rm)-1)/samp per sym;
x2 = 0:100;
subplot(3,1,1)
plot(x1,Rm,‘.k’); ylabel(‘R[m]’)
subplot(3,1,2)
stem(x2,Rm(1:101),‘.k’); ylabel(‘Partial R[m]’)
subplot(3,1,3)
stem(x2,pndata(1:101),‘.k’); ylabel(‘First 100 outputs’)
axis([0 100 -1.5 1.5]);

Respuestas (1)

DGM
DGM el 4 de Jun. de 2023
Editada: DGM el 4 de Jun. de 2023
I don't see anything that's version-dependent here. I just see a bunch of problems likely caused by copying and pasting code from a website somewhere.
  • MATLAB does not support curly quotes. Use a regular straight single quote mark.
  • Variable and function names cannot have spaces.
  • AFAIK, there is no MATLAB function called replicate(). Maybe that's supposed to be remat(), or maybe something else.
The first two problems (pretty quotes and stripping underscores) end up happening when code is blindly subjected to automated formatting.
pntaps = [0 0 1 0 0 0 0 0 0 1];
pninitial = [0 0 0 0 0 0 0 0 0 1];
pndata = zeros(1,1023);
samp_per_sym = 1;
pnregister = pninitial;
n = 0;
kk = 0;
while kk == 0
n = n+1;
pndata(1,n) = pnregister(1,1);
feedback = rem((pnregister*pntaps'),2);
pnregister = [feedback,pnregister(1,1:9)];
if pnregister == pninitial; kk = 1; end
end
text = ['The period is ',num2str(n,15),'.'];
disp(text)
pndata=repmat(pndata,samp_per_sym);
kn = n*samp_per_sym;
pndata = 2*pndata - 1;
a = fft(pndata);
b = a.*conj(a);
Rm = real(ifft(b))/kn;
x1 = (0:length(Rm)-1)/samp_per_sym;
x2 = 0:100;
subplot(3,1,1)
plot(x1,Rm,'.k'); ylabel('R[m]')
subplot(3,1,2)
stem(x2,Rm(1:101),'.k'); ylabel('Partial R[m]')
subplot(3,1,3)
stem(x2,pndata(1:101),'.k'); ylabel('First 100 outputs')
axis([0 100 -1.5 1.5]);

Community Treasure Hunt

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

Start Hunting!

Translated by