?? bpsk.m
字號:
%% Script file for computer exercise "BPSK".%N = 2^6; % Number of symbolsfc = 1e3; % Carrier frequencyfs = 4*1e3; % Sampling frequencyTs = 1/fs; % Sampling time = 1/fsT = 1/100; % Symbol timetarray = [0:Ts:N*T-Ts]';% Array with time indexd = sign(randn(N,1)); % Generate N random binary symbols, +/- 1dmat = ones(T/Ts,1)*d'; dover = dmat(:); % Symbols but over sampled%% Plot the over sampled symbol sequence%figure(1)plot(tarray,dover)axis([0 max(tarray) -1.2 1.2])title('Over sampled symbol sequence')disp('Hit any key to continue!')pauseaxis auto%% Generate the BPSK modulated carrier (the phase is 0/pi)%y = dover .* cos(2*pi*fc*tarray);%% Below you can add a phase to the signal. Because of % propagation delay to the receiver, this phase is unknown % at the receiver. You can also add noise with variance (power) var.%var = 0;noise = sqrt(var)*randn(size(y));phase = 0;y = dover .* cos(2*pi*fc*tarray + phase) + noise;%% Plot the beginning of the signal (Use the zoom function in the plot!)%figure(1)plot(tarray(1:min(length(y),200)),y(1:min(length(y),200)))title('The modulated signal')disp('Hit any key to continue!')pause%%% Plot the spectrum%Y = fft(y);plot(abs(Y));title('The spectrum of modulated signal')disp('Hit any key to continue!')pause%% Plot the spectrum with the correct frequency scale.% Function from "2E1311 Signals and Systems" course %[Y,f] = ftfast(y,tarray);%plot(f,abs(Y))%title('The spectrum of modulated signal (correct axis)')%disp('Hit any key to continue!')%pause%% Below is the receiver. % The receiver starts by multiplying the signal with % the carrier signal. If you set phase = 0 above, this corresponds % to coherent demodulation. Otherwise this is incoherent demodulation. %I = cos(2*pi*fc*tarray);yI = I.*y; %% Plot the spectrum of the demodulated signal. %%[Y,f] = ftfast(yI,tarray);%plot(f,abs(Y))%title('The spectrum of the demodulated signal')%disp('Hit any key to continue!')%pause%% Note the aliasing! Remove this by low pass filtering. % Create a simple LP filter and filter the signal. %% Use mybutter instead of butter if you have Matlab Student version.[B,A] = butter(4,1/T/fs*2);yIlow =filter(2*B,A,yI);%% Plot the spectrum of the LP filtered demodulated signal. %%[Y,f] = ftfast(yIlow,tarray);%plot(f,abs(Y))%title('The spectrum of the LP filtered demodulated signal')%disp('Hit any key to continue!')%pause%% Now compare this to the original symbol sequence.%figure(1)plot(tarray,dover,tarray,yIlow,'r')axis([0 max(tarray) -1.2 1.2])title('Original symbol sequence and LP filtered demodulated signal')
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -