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
1 回表示 (過去 30 日間)
古いコメントを表示
Bahaa Algebory
2016 年 10 月 22 日
回答済み: Alexandra Harkai
2016 年 10 月 24 日
%% 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
0 件のコメント
採用された回答
Alexandra Harkai
2016 年 10 月 24 日
One way of doing it would be to maintain an array of max_run(i) values.
max_run(i) = min(indexmin)
Instead of
max_run = min(indexmin)
Of course it is then a good idea to initialise max_run before the loop to be an all zeros array to allocate sufficient memory.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で BPSK についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!