├── Simulation Results.png ├── .gitattributes ├── README.md └── BER_vs_SNR_OFDM_with_BPSK.m /Simulation Results.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pikipity/OFDM-with-BPSK/HEAD/Simulation Results.png -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Simulation: OFDM System with BPSK Modulation 2 | 3 | Simulate the OFDM system with BPSK modulation method and plot the figure of BER vs. SNR. 4 | 5 | ## Optional Inputs 6 | 7 | 1. BitPerSymbol: Bits per symbol, default is 1 8 | 2. NoSymbol: Number of symbols, default is 10^6 9 | 3. NoSub: Number of subcarriers, default is 64 10 | 4. LenCyclic: Length of cyclic prefix, default is 16 11 | 5. SNR: SNR range for simulations, default is 0:2:30 12 | 6. BPSKNum: Number of phase for BPSK, default is 2. Mapping the bit 0 and the bit 1 as -1 and 1 13 | 14 | ## Example 15 | 16 | `BER_vs_SNR_OFDM_with_BPSK('NoSymbols',10^6,'SNR',0:15);` 17 | 18 | ## Simulation Results 19 | 20 | Parameters are all default values 21 | 22 | ![Simulation Results](https://raw.githubusercontent.com/pikipity/OFDM-with-BPSK/master/Simulation%20Results.png) 23 | -------------------------------------------------------------------------------- /BER_vs_SNR_OFDM_with_BPSK.m: -------------------------------------------------------------------------------- 1 | function BER_vs_SNR_OFDM_with_BPSK(varargin) 2 | % Plot the relationship between the bit-error-rate (BER) and 3 | % signal-to-noise ratio (SNR) for OFDM system with BPSK modulation method 4 | % BER_vs_SNR_OFDM_with_BPSK(ParameterName1, ParameterValue1,... 5 | % ParameterName2, ParameterValue2,...) 6 | % Parameters: 7 | % BitPerSymbol: Bits per symbol, default is 1 8 | % NoSymbol: Number of symbols, default is 10^6 9 | % NoSub: Number of subcarriers, default is 64 10 | % LenCyclic: Length of cyclic prefix, default is 16 11 | % SNR: SNR range for simulations, default is 0:2:30 12 | % BPSKNum: Number of phase for BPSK, default is 2. Mapping the bit 0 and 13 | % the bit 1 as -1 and 1 14 | % Example: 15 | % BER_vs_SNR_OFDM_with_BPSK('NoSymbols',10^6,'SNR',0:15); 16 | 17 | %% Input parametes 18 | % default parameters 19 | Detect=0; 20 | BitPerSymbol=1; % bit/symbol 21 | NoSymbols=10^6; % symbol numbers 22 | NoSub=64; % Subcarries number 23 | LenCyclic=16; % Length of Cyclic prefix 24 | SNR=30:-2:0; 25 | BPSKNum=2; % Phase number of BPSK 26 | % User's parameter 27 | for i=1:2:length(varargin) 28 | switch lower(varargin{i}) 29 | case 'detect' 30 | Detect=varargin{i+1}; 31 | case 'bitpersymbol' 32 | BitPerSymbol=varargin{i+1}; 33 | case lower('NoSymbols') 34 | NoSymbols=varargin{i+1}; 35 | case lower('NoSub') 36 | NoSub=varargin{i+1}; 37 | case lower('LenCyclic') 38 | LenCyclic=varargin{i+1}; 39 | case lower('SNR') 40 | SNR=varargin{i+1}; 41 | case lower('BPSKNum') 42 | BPSKNum=varargin{i+1}; 43 | otherwise 44 | disp(['Unknown input: ' varargin{i}]) 45 | return 46 | end 47 | end 48 | %% Transmiter Side 49 | % Gnerate Data Sequence 50 | NoBits=NoSymbols*BitPerSymbol; 51 | data=randi([0 1],1,NoBits); 52 | % Separate data to different path 53 | path=reshape(data,NoSub,NoBits/NoSub); 54 | % BPSK 55 | BPSKpath=dpskmod(path,BPSKNum); 56 | % ifft 57 | ifftpath=ifft(BPSKpath,NoSub); 58 | % Add cyclic prefix 59 | Tranpath=zeros(size(ifftpath,1)+LenCyclic,size(ifftpath,2)); 60 | Tranpath(1:LenCyclic,:)=ifftpath((end-LenCyclic+1):end,:); 61 | Tranpath((1+LenCyclic):end,:)=ifftpath; 62 | %% Transmit and Receiver 63 | % Transmit 64 | BER=zeros(size(SNR)); 65 | for SNRNo=1:length(SNR) 66 | %% Channel Side 67 | % Add additive Gaussian white noise 68 | Repath=awgn(Tranpath,SNR(SNRNo),'measured'); 69 | %% Receiver Side 70 | % Detect signal 71 | if Detect 72 | Detectpath=zeros(size(Repath)); 73 | for i=1:25:size(Repath,2) 74 | disp(i) 75 | Resignal=Repath(:,i:(i+25-1)); 76 | Resignal=reshape(Resignal,size(Resignal,1)*size(Resignal,2),1); 77 | compare=reshape(Tranpath,size(Resignal,1)*size(Resignal,2),size(Tranpath,2)/25); 78 | error=sum(abs(Resignal(:,ones(1,size(compare,2)))-compare).^2,1); 79 | [~,I]=min(error); 80 | Detectpath(:,((I-1)*25+1):((I-1)*25+25))=Repath(:,i:(i+25-1)); 81 | end 82 | else 83 | Detectpath=Repath; 84 | end 85 | % Remove cyclic prefix 86 | ReCyclicpath=Detectpath((1+LenCyclic):end,:); 87 | % fft 88 | fftpath=fft(ReCyclicpath,NoSub); 89 | % inverse BPSK 90 | demodpath=dpskdemod(fftpath,BPSKNum); 91 | % Reform 92 | demodata=reshape(demodpath,1,NoBits); 93 | %% Calculate BER 94 | BER(SNRNo)=sum(xor(demodata,data))/NoBits; 95 | disp(['SNR: ' num2str(SNR(SNRNo)) '. BER: ' num2str(BER(SNRNo))]) 96 | end 97 | %% Plot result 98 | figure; 99 | semilogy(SNR,BER,'--dr','linewidth',2); 100 | grid on 101 | xlabel('SNR'); 102 | ylabel('BER'); 103 | title('Simulation Results') 104 | end --------------------------------------------------------------------------------