need help Matrix dimensions must agree error
1 view (last 30 days)
Show older comments
% This code modulates a 4-ary FSK signal, extracts channel response data
% from Bounce-Bellhop Eigenray outputs, applies multipath arrivals to
% original signal, demodulates the received signal, and counts the
% errors.
% Functions Called:
% mfskcoder - Converts sequence of encoded symbols into a sequence of
% channel symbols
% mfskdemod - Demodulates received signal into a sequence of received
% channel symbols
% mfskdecoder - Converts sequence of received channel symbols into a
% sequence of received encoded symbols
%
% William Jenkins
% Naval Postgraduate School, Monterey, California, May 2010
clear all
load impulsedata5
%load wgnnoise
%% Signal Generation
encsym = 2; % Encoded Symbols per Channel Symbol
Tfactor = 1; % Time/Frequency Scaling Factor
Tsw = 0.025; % Seaweb Pulse Duration (sec)
fc = 45000; % Carrier Frequency (Hz)
% Arbitrary Sequence of Encoded Symbols
msg = [0 0 0 1 1 0 1 1 1 1 1 0 0 1 0 0 ...
0 0 0 1 1 0 1 1 1 1 1 0 0 1 0 0];
msg = [msg msg msg msg];
N = length(msg)/2; % Number of Transmitted Channel Symbols
kn = mfskcoder(msg); % Symbol Vector
M = 2^encsym; % Number of Unique Channel Symbols
T = Tfactor*Tsw; % Pulse Duration (sec)
fs = 4*(fc+3/T); % Sampling Frequency (Hz)
Ts = 1/fs; % Sampling Period (sec)
T0 = floor(T/Ts);
t = Ts*(0:(T0-1));
tvec = Ts*(0:N*length(t)-1); % Time Vector
A = 1; % Amplitude
freqM = kn/(2*T);
freqtx = kron(freqM,ones(1,T0)); % Transmitted Frequency Vector
% Transmitted Signal
sig = A*0.5*(exp(1i*2*pi*(fc+freqtx).*tvec)...
+exp(-1i*2*pi*(fc+freqtx).*tvec));
% Loop over Source-Receiver Depths
% 1 >>> z = 5m
% 2 >>> z = 50m
% 3 >>> z = 100m
% 4 >>> z = 150m
% 5 >>> z = 200m
geom = [1 2 3 4 5];
for zzz = 1:length(geom)
%% Multipath Arrival & Noise Addition
Range = zeros(1,length(time));
errors = zeros(1,length(time));
percent = zeros(1,length(time));
SNRdB = zeros(1,length(time));
% Loop over Source-Receiver Ranges
for nnn = 1:length(time)
delay_ind = zeros(1,length(time{nnn,geom(zzz)}));
prx = zeros(1,length(Prx{nnn,geom(zzz)}));
phase = zeros(1,length(phaserad{nnn,geom(zzz)}));
% Synchronization with First Arrival:
tvec = tvec+min(time{nnn,geom(zzz)});
for dd = 1:length(time{nnn,geom(zzz)})
if time{nnn,geom(zzz)}(dd) > max(tvec)
delay_ind(1,dd) = 0;
prx(1,dd) = 0;
phase(1,dd) = 0;
else
delay_vec = find(tvec >= time{nnn,geom(zzz)}(dd),1);
delay_ind(1,dd) = min(delay_vec);
prx(1,dd) = Prx{nnn,geom(zzz)}(dd);
phase(1,dd) = phaserad{nnn,geom(zzz)}(dd);
end
end
clear delay_vec
multi = zeros(length(time{nnn,geom(zzz)}),length(sig));
for dd = 1:length(delay_ind)
if delay_ind(dd) == 0
multi(dd,:) = zeros(1,length(sig));
else
multi(dd,:) = [zeros(1,delay_ind(dd)-1)...
prx(dd)*0.5*(exp(1i*2*pi*(fc+freqtx(delay_ind(dd):...
length(freqtx))).*tvec(delay_ind(dd):length(tvec)))...
*exp(1i*phase(dd))+exp(-1i*2*pi*...
(fc+freqtx(delay_ind(dd):length(freqtx))).*tvec...
(delay_ind(dd):length(tvec)))*exp(-1i*phase(dd)))];
end
end
sigrow = find(time{nnn,1}(:) == min(time{nnn,1}(:)));
txsig = multi(sigrow,:);
multi(sigrow,:) = [];
noise = sum(multi);
rxsig = txsig + noise;
%% Demodulation - FFT
% Demodulate received signal into received channel symbols:
knrx = mfskdemod(rxsig1,N,fs,fc,T,Tfactor);
% Demodulate received channel symbols into received encoded
% symbols:
[msgrx] = mfskdecoder(knrx);
%% Error Count
errvec = zeros(size(msg));
for mm = 1:length(msg)
if msg(mm) == msgrx(mm)
errvec(mm) = 0;
else
errvec(mm) = 1;
end
end
% Total Encoded Symbols in Error:
errors(nnn) = sum(errvec);
% Percentage of Encoded Symbols in Error:
percent(nnn) = 100*errors(nnn)/length(msg);
% SNR at the Receiver (Input SNR)
% Average Power of the Transmitted Signal (Watts):
PIs = sum(abs(txsig.^2))/length(txsig);
% Average Power of the Noise (Multipath) (Watts):
PIn = sum(abs(noise.^2))/length(noise);
SNRdB(nnn) = 10*log10(PIs/PIn);
disp([' Multipath SNR = ',num2str(SNRdB(nnn)),' dB'])
disp([num2str(errors(nnn)),...
' Errors Counted - Multipath'])
Range(nnn) = 49+nnn;
end
filename = ['Geometry',num2str(zzz),'_T',num2str(T*1000)];
save(filename,'errors','percent','SNRdB')
end
error at "tvec = tvec+min(time{nnn,geom(zzz)});"
0 Comments
Answers (0)
See Also
Categories
Find more on Waveform Generation 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!