MATLAB Code
clc;
clear all; close all;
Data_sym = [0 1 1 0 1 0 0 1];
M = 4;
Phase = 0;
Sampling_rate = 48e3;
Data_Rate = 100;
Bandwidth = 400;
Upsampling_factor = Sampling_rate/Data_Rate;
Rolloff = 0.4;
Upsampled_Data = upsample(pskmod(Data_sym,M,Phase),Upsampling_factor);
Pulse_shape = firrcos(2*Upsampling_factor,Bandwidth/2,Rolloff,Sampling_rate,'rolloff','sqrt');
Output
What if we change the roll-off
roll-off = 0.01
roll-off = 0.99
What if we change the bandwidth
Bandwidth = 100 Hz
Bandwidth = 1000 Hz
What if we change the sampling rate
Sampling rate = 10 KHz
Sampling rate = 100 KHz
Another MATLAB Code
% The code is developed by SalimWireless.Com
clc;
clear;
close all;
% Parameters
fs = 1000; % Sampling frequency in Hz
symbolRate = 100; % Symbol rate (baud)
span = 6; % Filter span in symbols
alpha = 0.25; % Roll-off factor for raised cosine filter
% Generate random data symbols
numSymbols = 100; % Number of symbols
data = randi([0 1], numSymbols, 1) * 2 - 1; % Generate random binary data (BPSK symbols: -1, 1)
% Upsample the data to match sampling rate
samplesPerSymbol = fs / symbolRate; % Samples per symbol based on fs and symbol rate
dataUpsampled = upsample(data, samplesPerSymbol);
% Create a raised cosine filter
rcFilter = rcosdesign(alpha, span, samplesPerSymbol, 'sqrt'); % Square root raised cosine filter
% Apply the filter to the upsampled data
txSignal = conv(dataUpsampled, rcFilter, 'same');
figure;
subplot(4,1,1)
stem(data);
title('Original Message signal');
grid on;
subplot(4,1,2)
plot(dataUpsampled);
title('Upsampled Message signal');
grid on;
subplot(4,1,3)
plot(rcFilter);
title('Raise Cosine Filter Coefficient');
grid on;
subplot(4,1,4)
plot(txSignal);
title('Transmitted Signal after Raised Cosine Filtering');
grid on;
clc;
clear;
close all;
% Parameters
fs = 1000; % Sampling frequency in Hz
symbolRate = 100; % Symbol rate (baud)
span = 6; % Filter span in symbols
alpha = 0.25; % Roll-off factor for raised cosine filter
% Generate random data symbols
numSymbols = 100; % Number of symbols
data = randi([0 1], numSymbols, 1) * 2 - 1; % Generate random binary data (BPSK symbols: -1, 1)
% Upsample the data to match sampling rate
samplesPerSymbol = fs / symbolRate; % Samples per symbol based on fs and symbol rate
dataUpsampled = upsample(data, samplesPerSymbol);
% Create a raised cosine filter
rcFilter = rcosdesign(alpha, span, samplesPerSymbol, 'sqrt'); % Square root raised cosine filter
% Apply the filter to the upsampled data
txSignal = conv(dataUpsampled, rcFilter, 'same');
figure;
subplot(4,1,1)
stem(data);
title('Original Message signal');
grid on;
subplot(4,1,2)
plot(dataUpsampled);
title('Upsampled Message signal');
grid on;
subplot(4,1,3)
plot(rcFilter);
title('Raise Cosine Filter Coefficient');
grid on;
subplot(4,1,4)
plot(txSignal);
title('Transmitted Signal after Raised Cosine Filtering');
grid on;
Output
Copy the MATLAB Code above from here