How to save a loop data
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Bahaa Algebory
el 22 de Oct. de 2016
Comentada: Walter Roberson
el 24 de Oct. de 2016
Hi guys, I have a for loop, but every iteration overwrites the variable(max_run), and I have only the final data left. How can I save data from every loop? I saw some other questions like my issue, but I always get an error"Improper assignment with
%%BPSK Generation
clear all; close all; clc;
N = 2*10^4; % number of bits or symbols
ip = rand(1,N)>0.5; % generating 0,1 with equal probability
s = 2*ip-1; % BPSK modulation 0 -> -1; 1 -> 1
%%Prepare transmitted signal
m=2; % oversampling factor
beta=0.3; % rolloff parameter for SRRC
l=100; % 1/2 length of pulse shape (in symbols)
chan=[1]; % T/m "channel"
toffset=-0.5; % initial timing offset
pulshap=srrc(l,beta,m,toffset); % SRRC pulse shape
sup=zeros(1,N*m); % upsample the data by placing...
sup(1:m:end)=s; % ... p zeros between each data point
hh=conv(pulshap,sup); % ... and pulse shape
r1=conv(hh,chan); % ... to get received signal
%%Noise Generation
SNRdB=1:2:13; % Signal to Noise Ratio
SNR=10.^(SNRdB/10);
for cv=1:length(SNR);
no=sqrt((1/SNR(cv)))*randn(1,40400); % Noise generation
r=r1+no; % Adding the noise to the received signal
%%Matched Filter & Convolution process
matchfilt=srrc(l,beta,m,0); % filter = pulse shape
x=conv(r,matchfilt); % convolve signal with matched filter
%%Run clock recovery algorithm
tnow=2*l*m+1; tau=0; xs=zeros(1,N); % initialize variables
tausave=zeros(1,N); tausave(1)=tau; i=0;
mu=0.05; % algorithm stepsize
delta=0.1; % time for derivative
while tnow<length(x)-2*l*m % run iteration
i=i+1;
xs(i)=interpsinc(x,tnow+tau,l); % interpolated value at tnow+tau
x_deltap=interpsinc(x,tnow+tau+delta,l); % get value to the right
x_deltam=interpsinc(x,tnow+tau-delta,l); % get value to the left
dx=x_deltap-x_deltam; % calculate numerical derivative
tau=tau+mu*dx*xs(i); % alg update (energy)
tnow=tnow+m; tausave(i)=tau; % save for plotting
indexmin = find(tausave >= 0.5); % finding iteration value..
max_run = min(indexmin) % automaticlly
end
% Plot results
figure, subplot(2,1,1), plot(xs(1:i-2),'b.');
legend([ 'SNR=' int2str(SNR(cv))]); % plot constellation diagram
title('constellation diagram');
ylabel('estimated symbol values')
subplot(2,1,2), plot(tausave(1:i-2))
ylabel('offset estimates'), xlabel('iterations')
legend([ 'SNR=' int2str(SNR(cv))]);
end
1 comentario
Walter Roberson
el 23 de Oct. de 2016
Are you getting srrc() from http://www.gaussianwaves.com/2011/04/square-root-raised-cosine-filter-matchedsplit-filter-implementation-2/ ?
Respuesta aceptada
Walter Roberson
el 23 de Oct. de 2016
max_run(i) = min(indexmin);
4 comentarios
Bahaa Algebory
el 24 de Oct. de 2016
Editada: Walter Roberson
el 24 de Oct. de 2016
Walter Roberson
el 24 de Oct. de 2016
Your line
xs(i)=interpsinc(x,tnow+tau,l); % interpolated value at tnow+tau
uses an undefined routine interpsinc . I grabbed interpsinc from the File Exchange but you appear to be asking to interpolate all the x values at time tnow+tau and you have over 40000 x values so the result is over 40000 results, which do not fit into the single location xs(i)
Más respuestas (0)
Ver también
Categorías
Más información sobre Spectral Analysis en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!