How to save a loop data
Show older comments
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 Comment
Walter Roberson
on 23 Oct 2016
Are you getting srrc() from http://www.gaussianwaves.com/2011/04/square-root-raised-cosine-filter-matchedsplit-filter-implementation-2/ ?
Accepted Answer
More Answers (0)
Categories
Find more on Spectral Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!