📄 trigger.m
字号:
function [index_power_burst,index_block0,w_SNR_vec]=trigger(receive,sync,window_length,fs,T)% [index_power_burst,index_block0,w_SNR_vec]=trigger(receive,sync,window_length,fs,T)%% Output:% index_power_burst - start-index for the block in which the powerburst is found % index_block0 - start-index for the first block% w_SNR_vec - vector with the SNR for each window%% Input:% receive - the received signal after channel % sync - the sync vector as sent in the transmitter% window_length - the length of each block % fs - sampling frequency % T - symbol period%% Short Theoretical Background for the Function:%% The trigger is used to know when a transmission starts and to synchronize the received % blocks with the transmitted block. % Each transmission is split into a number of blocks and begins with a powerburst (a block of ones) % followed by a gard and a known synchronization sequence.% The trigger searches for the powerburst and when the powerburst is found it knows in % wich block the powerburst starts. Then it correlates the following two blocks with the known % synchronization sequence to find the beginning of the first symbolblock. The receiver now knows% when the first symbolblock arrives and samples the received signal according to this.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% Function part of simulation for Space-Time%%% coding project, group Grey-2001.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Author: Fredrik & Karl% Date: 2001-04-27% Version: 1.0% Revision (Name & Date & Comment):%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%flag =1;n = 0;gard_length = window_length;noise_power = mean(abs(receive(1:window_length).^2)); index_power_burst = 0;index_block0 = 0;w_SNR_vec =[];sum_sync1 =[];sum_sync2 =[]; ref_burst = ones(1,fs*T*(window_length+10)); ref = carrier(ref_burst,2500,fs,T); treshold = mean(ref.^2)/6; while n < length(receive)/window_length - 1 % steps through each block window = receive(n*window_length+1:(n+1)*window_length); % the current block window_SNR = (mean(abs(window.^2)))- noise_power; w_SNR_vec = [w_SNR_vec window_SNR]; n = n + 1; if window_SNR > treshold & flag == 1 % in case the powerburst is found index_power_burst = (n-1)*window_length; flag = 0; % since this loop is to be entered once only window_corr1 = [zeros(1,length(sync)) receive((n+1)*window_length+1:(n+2)*window_length) zeros(1,length(sync))]; % the first block with zeros in beginning and end for(m=1:1:(window_length + length(sync))) % m = sync_start slides from beginning of block to length(block) + length(sync). sum_sync1 = [sum_sync1 (window_corr1(m : length(sync) + m-1) * sync')]; end window_corr2 = [zeros(1,length(sync)) receive((n+2)*window_length+1:(n+3)*window_length) zeros(1,length(sync))]; % the second block for(m=1:1:(window_length + length(sync))) % m = sync_start slides from beginning of block to length(block) + length(sync). sum_sync2 = [sum_sync2 (window_corr2(m : length(sync) + m-1) * sync')]; end [corr_max1,sync_start1] = max(abs(sum_sync1)) [corr_max2,sync_start2] = max(abs(sum_sync2)) ref_sync = sync(1:window_length)*sync(1:window_length)' ref_factor = 3; if corr_max1 < (ref_sync / ref_factor) & corr_max2 < (ref_sync / ref_factor) disp('No valid power burst'); break elseif corr_max1 > corr_max2 % if sync is found in the first block correction = sync_start1; % the difference between the start of the transmitted block and the start of the sampled block of the received signal %index_block0 = (n+1)*window_length + correction + gard_length; % startindex for the first symbolblock index_block0 = (n+1)*window_length + correction + length(sync); else correction = sync_start2; % if sync is found in the second block %index_block0 = (n+2)*window_length + correction + gard_length; % startindex for the first symbolblock index_block0 = (n+2)*window_length + correction + length(sync); end endend
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -