% IEE2620 Lab 2 % DL synchronization signals: SS/PBCH %Fig.1 grid for normal CP %Fig.2 grid for extended CP %Fig.3 DL waveform for normal CP %Fig.4 DL waveform for extended CP clc clear %variables mu=2;% NR numerology, 0,1,2,3,4 SCS=15*2^mu; %kHz NumRBs=20; %frequency scale CPref1="normal"; %cyclic prefix CPref2="extended"; %cyclic prefix BWPSize=NumRBs*SCS*12*0.001; %used BW size in MHz FR='FR1'; % 'FR1' or 'FR2'; frequency range ncellid=1; %% create grid for slot % normal CP: carrier1 = nrCarrierConfig("CyclicPrefix",CPref1,"SubcarrierSpacing",SCS,"NSizeGrid",NumRBs,'NSlot',1); % extended CP: carrier2 = nrCarrierConfig("CyclicPrefix",CPref2,"SubcarrierSpacing",SCS,"NSizeGrid",NumRBs,'NSlot',1); grid1=nrResourceGrid(carrier1); info1 = nrOFDMInfo(carrier1); % Get OFDM information for the specified carrier configuration. numSym1=info1.SlotsPerFrame*info1.SymbolsPerSlot; %number of total symbols in frame %display grid1 figure(1) clf imagesc([0 carrier1.SymbolsPerSlot-1],[0 carrier1.NSizeGrid*12-1],abs(grid1(:,:,1))); axis xy;title("Resource grid (Normal CP)");ylabel("Subcarrier");xlabel("OFDM Symbol") colorbar('Ticks',[0,1,2,3,4],... 'Ticklabels', {'','', '','',''},... 'Location', 'eastoutside'); grid2=nrResourceGrid(carrier2); info2 = nrOFDMInfo(carrier2); % Get OFDM information for the specified carrier configuration. numSym2=info2.SlotsPerFrame*info2.SymbolsPerSlot; %number of total symbols in frame %display grid2 figure(2) clf imagesc([0 carrier2.SymbolsPerSlot-1],[0 carrier2.NSizeGrid*12-1],abs(grid2(:,:,1))); axis xy;title("Resource grid (Extended CP)");ylabel("Subcarrier");xlabel("OFDM Symbol") colorbar('Ticks',[0,1,2,3,4],... 'Ticklabels', {'','', '','',''},... 'Location', 'eastoutside'); %% create grid for frame figure(1) clf RBgrid1 = []; for nslot = 0:(info1.SlotsPerFrame - 1) carrier1.NSlot = nslot; slotGrid = nrResourceGrid(carrier1); % ind = nrSRSIndices(carrier,srs); % sym = nrSRS(carrier,srs); % slotGrid(ind) = sym; RBgrid1 = [RBgrid1 slotGrid]; end imagesc([0 (carrier1.SymbolsPerSlot*carrier1.SlotsPerFrame)-1],[0 carrier1.NSizeGrid*12-1],abs(RBgrid1(:,:,1))); axis xy;title("Resource grid for Frame (Normal CP)");ylabel("Subcarrier");xlabel("OFDM Symbol") colorbar('Ticks',[0,1,2,3,4],... 'Ticklabels', {'','', '','',''},... 'Location', 'eastoutside'); figure(2) clf RBgrid2 = []; for nslot = 0:(info2.SlotsPerFrame - 1) carrier2.NSlot = nslot; slotGrid = nrResourceGrid(carrier2); % ind = nrSRSIndices(carrier,srs); % sym = nrSRS(carrier,srs); % slotGrid(ind) = sym; RBgrid2 = [RBgrid2 slotGrid]; end imagesc([0 (carrier2.SymbolsPerSlot*carrier2.SlotsPerFrame)-1],[0 carrier2.NSizeGrid*12-1],abs(RBgrid2(:,:,1))); axis xy;title("Resource grid for Frame (Extended CP)");ylabel("Subcarrier");xlabel("OFDM Symbol") colorbar('Ticks',[0,1,2,3,4],... 'Ticklabels', {'','', '','',''},... 'Location', 'eastoutside'); %% waveform SCScarrier=nrSCSCarrierConfig("NSizeGrid",NumRBs,"SubcarrierSpacing",SCS); bwp1 = nrWavegenBWPConfig("NSizeBWP",NumRBs,'NStartBWP',SCScarrier.NStartGrid+0,"SubcarrierSpacing",SCS,"CyclicPrefix","normal"); bwp2 = nrWavegenBWPConfig("NSizeBWP",NumRBs,'NStartBWP',SCScarrier.NStartGrid+0,"SubcarrierSpacing",SCS,"CyclicPrefix","extended"); %% Physical channels and signals for waveform ssb=nrWavegenSSBurstConfig("Enable",0); pdcch = nrWavegenPDCCHConfig("Enable",0); pdsch = nrWavegenPDSCHConfig("Enable",0); %csirs = nrCSIRSConfig; pusch = nrWavegenPUSCHConfig("Enable",0); pucch = nrWavegenPUCCH0Config("Enable",0); srs = nrWavegenSRSConfig("Enable",0); figure(3) clf RBgridDL1=nrDLCarrierConfig("SCSCarriers",{SCScarrier},"BandwidthParts",{bwp1},'SSBurst',ssb,'PDCCH',{pdcch},'PDSCH',{pdsch},'FrequencyRange',FR);%,'CSIRS',{csirs}) [waveformDL,DLinfo1] = nrWaveformGenerator(RBgridDL1); nfftDL1=DLinfo1.ResourceGrids(1).Info.Nfft; samplerateDL1 = DLinfo1.ResourceGrids(1).Info.SampleRate; spectrogram(waveformDL(:,1),ones(nfftDL1,1),0,nfftDL1,'centered',samplerateDL1,'yaxis','MinThreshold',-130); title('Spectrogram of NR DL Waveform (Normal CP)',strcat('BW=',num2str(BWPSize),' MHz, ', num2str(info1.SymbolsPerSlot),' OFDM symbols')); figure(4) clf RBgridDL2=nrDLCarrierConfig("SCSCarriers",{SCScarrier},"BandwidthParts",{bwp2},'SSBurst',ssb,'PDCCH',{pdcch},'PDSCH',{pdsch},'FrequencyRange',FR);%,'CSIRS',{csirs}) [waveformDL,DLinfo2] = nrWaveformGenerator(RBgridDL2); nfftDL2=DLinfo2.ResourceGrids(1).Info.Nfft; samplerateDL2 = DLinfo2.ResourceGrids(1).Info.SampleRate; spectrogram(waveformDL(:,1),ones(nfftDL2,1),0,nfftDL2,'centered',samplerateDL2,'yaxis','MinThreshold',-130); title('Spectrogram of NR DL Waveform (Extended CP)',strcat('BW=',num2str(BWPSize),' MHz, ', num2str(info2.SymbolsPerSlot),' OFDM symbols')); figure(5) %%single block clf colorbar('Ticks',[0,1,2,3,4],... 'Ticklabels', {'','', '','',''},... 'Location', 'eastoutside'); %% tasks % [1] Synchronization Signal Blocks and Bursts [MATLAB] https://se.mathworks.com/help/5g/gs/synchronization-signal-blocks-and-bursts.html % step-by-step update figures 1-4 % 1) PSS ssblock=zeros([240 4]); pssSymbols=nrPSS(ncellid); pssIndices=nrPSSIndices; ssblock(pssIndices)=1*pssSymbols; figure(5) % ssblock (4x240) clf imagesc(abs(ssblock)); clim([0 5]); axis xy; xticks(1:4); xticklabels({'0','1','2','3'}); yticks([1 57 183 240]); yticklabels({'0','56','182','240'}); xlabel('OFDM symbol (relative)'); ylabel('Subcarrier (relative)'); title('SS/PBCH block containing PSS'); colorbar('Ticks',[0,1,2,3,4],... 'Ticklabels', {'Unassigned','PSS', '','',''},... 'Location', 'eastoutside'); % 2) SSS sssSymbols = nrSSS(ncellid); sssIndices = nrSSSIndices; ssblock(sssIndices) = 2 * sssSymbols; figure(5) % ssblock (4x240) clf imagesc(abs(ssblock)); clim([0 5]); axis xy; xticks(1:4); xticklabels({'0','1','2','3'}); yticks([1 57 183 240]); yticklabels({'0','56','182','240'}); xlabel('OFDM symbol (relative)'); ylabel('Subcarrier (relative)'); title('SS/PBCH block containing PSS and SSS'); colorbar('Ticks',[0,1,2,3,4],... 'Ticklabels', {'Unassigned','PSS', 'SSS','',''},... 'Location', 'eastoutside'); % 3) PBCH cw = randi([0 1],864,1); v = 0; pbchSymbols = nrPBCH(cw,ncellid,v); pbchIndices = nrPBCHIndices(ncellid); ssblock(pbchIndices) = 3 * pbchSymbols; figure(5) imagesc(abs(ssblock)); clim([0 5]); axis xy; xticks(1:4); xticklabels({'0','1','2','3'}); yticks([1 57 183 240]); yticklabels({'0','56','182','240'}); xlabel('OFDM symbol (relative)'); ylabel('Subcarrier (relative)'); title('SS/PBCH block containing PSS, SSS and PBCH'); colorbar('Ticks',[0,1,2,3,4],... 'Ticklabels', {'Unassigned','PSS', 'SSS','PBCH',''},... 'Location', 'eastoutside'); % 4) DM-RS ibar_SSB = 0; dmrsSymbols = nrPBCHDMRS(ncellid,ibar_SSB); dmrsIndices = nrPBCHDMRSIndices(ncellid); ssblock(dmrsIndices) = 4 * dmrsSymbols; figure(5) imagesc(abs(ssblock)); clim([0 5]); axis xy; xlabel('OFDM symbol'); ylabel('Subcarrier'); title('SS/PBCH block containing PSS, SSS, PBCH and PBCH DM-RS'); colorbar('Ticks',[0,1,2,3,4],... 'Ticklabels', {'Unassigned','PSS', 'SSS','PBCH','DM-RS'},... 'Location', 'eastoutside');