Matlab Manual Draft1
Matlab Manual Draft1
# OUTPUT :
# OUTPUT :
% c) triangular function%
clc;
clear all;
close all;
t=0:0.01:2;
x=sawtooth(2*pi*5*t,0.5);
subplot(2,1,1);
plot(t,x,'g');
xlabel('time');
ylabel('amplitude');
title('trianguler signal');
subplot(2,1,2);
stem(t,x,'r');
xlabel('time');
ylabel('amplitude');
title('triangular sequence');
# OUTPUT :
% d) sinusoidal function%
clc;
clear all;
close all;
t=0:0.01:2;
x=sin(2*pi*t);
subplot(2,1,1);
plot(t,x,'g');
xlabel('time');
Department of ECE , GEC Hassan
Pinciples Of Communication Systems Lab
ylabel('amplitude');
title('sinusoidal signal');
subplot(2,1,2);
stem(t,x,'r');
xlabel('time');
ylabel('amplitude');
title('sinusoidal sequence');
# OUTPUT :
% e) Exponential Function%
clc;
clear all;
close all;
n=50;
s=0:1:n;
figure(1)
C1=0.95*(exp(j*(pi/10)).*s);
C2=0.95*(exp(j*(pi/10)).*s);
C=real(C1)+real(C2);
subplot(2,1,1);
plot(s,C,'b');
subplot(2,1,2);
stem(s, C)
xlabel('Sample Number n');
ylabel('Amplitude');
title('Exponential Signal');
#OUTPUT :
% Time vector
t = 0:T:duration-T;
# OUTPUT :
%% Message Signal :
Am = 14;
fm = 200;
ym = Am*cos(2*pi*fm*t);
figure;
subplot(4, 1, 1);
plot(t(1:10000), ym(1:10000));
title('Message Signal');
xlabel('time(t)');
ylabel('Amplitude');
%% Carrier Signal :
Ac = Am/h;
fc = 2000;
yc = Ac*cos(2*pi*fc*t);
subplot(4, 1, 2);
plot(t(1:10000), yc(1:10000));
title('Carrier Signal');
xlabel('time(t)');
ylabel('Amplitude');
%% Modulated Signal :
y = ammod(ym, fc, 100000, 0, Ac);
subplot(4, 1, 3);
plot(t(1:10000), y(1:10000));
title('Modulated Signal');
xlabel('time(t)');
ylabel('Amplitude');
%% Demodulated Signal :
z = amdemod(y, fc, 100000, 0, Ac);
subplot(4, 1, 4);
plot(t(1:10000), z(1:10000));
title('Demodulated Signal');
xlabel('time(t)');
ylabel('Amplitude');
ylim([-10, 10]);
# OUTPUT :
clc;
clear all;
close all;
t = 0:0.001:1; %upto 1000 samples
vm = input('Enter Amplitude (Message) = ');
vc = input('Enter Amplitude (Carrier) = ');
fM = input('Enter Message frequency = ');
fc = input('Enter Carrier frequency = ');
m = input('Enter Modulation Index = ');
msg = vm*sin(2*pi*fM*t);
subplot(3,1,1); %plotting message signal
Department of ECE , GEC Hassan
Pinciples Of Communication Systems Lab
plot(t,msg);
xlabel('Time');
ylabel('Amplitude');
title('Message ');
carrier = vc*sin(2*pi*fc*t);
subplot(3,1,2); %plotting carrier signal
plot(t,carrier);
xlabel('Time');
ylabel('Amplitude');
title('Carrier Signal');
y = vc*sin(2*pi*fc*t+m.*cos(2*pi*fM*t));
subplot(3,1,3); %plotting FM (Frequency Modulated) signal
plot(t,y);
xlabel('Time');
ylabel('Amplitude');
title('FM Signal');
# OUTPUT :
Sample MATLAB Input:
Enter Amplitude (Message) = 5
Enter Amplitude (Carrier) = 5
Enter Message frequency = 8
Enter Carrier frequency = 100
Enter Modulation Index = 10
5. Sampling and reconstruction of low pass signals. Display the signals and its
spectrum
% Time vector
t = 0:T:duration-T;
subplot(2, 2, 1);
plot(t, x, 'b', 'LineWidth', 2);
title('Original Signal');
xlabel('Time (s)');
ylabel('Amplitude');
% Sampling
Fs_new = 200; % New sampling frequency (Hz)
T_new = 1/Fs_new; % New sampling period
t_new = 0:T_new:duration-T_new;
x_sampled = A_signal * sin(2*pi*f_signal*t_new);
# OUTPUT :
# OUTPUT :
Columns 1 through 25
82 91 12 92 63 9 28 55 96 97 15 98 96 49 80 14 42 92
80 96 66 3 85 94 68
Columns 26 through 30
76 75 39 66 17
Demultiplexed Signal 1:
82 92 28 97 96 14 80 3 68 39
Demultiplexed Signal 2:
91 63 55 15 49 42 96 85 76 66
Demultiplexed Signal 3:
12 9 96 98 80 92 66 94 75 17
% Sampling
nSamples = 10; % Number of samples
sampled_signal = Analog_signal(1:nSamples); % Downsample
% Quantization
nBits = 4; % Number of bits for quantization
quantized_signal = round(sampled_signal * (2^(nBits-1) - 1));
# OUTPUT :
8. Generate a) NRZ, RZ and Raised cosine pulse, b) Generate and plot eye
diagram
# OUTPUT :
rz_signal = [];
end
#OUTPUT :
% Derived parameters
Fs = samples_per_symbol * symbol_rate; % Sampling frequency
Ts = 1 / symbol_rate; % Symbol duration
% Time vector
t = linspace(-span/2, span/2, span * samples_per_symbol);
# OUTPUT :
% Reshape the data into a matrix with desired number of samples per symbol
samples_per_symbol = 10;
num_symbols = data_length / samples_per_symbol;
eye_data = reshape(data, samples_per_symbol, num_symbols);
# OUTPUT :
% Parameters
mu = 0; % Mean of the Gaussian distribution
sigma = 1; % Standard deviation of the Gaussian distribution
% Plot PDF
figure;
plot(x, pdf, 'b', 'LineWidth', 2);
title('Probability Density Function of Gaussian Distribution');
xlabel('x');
ylabel('PDF');
grid on;
# OUTPUT :
AIM: To write a MATLAB program to generate the signal and its spectrum of an
audio signal
% You can also use the following line to display the spectrum in dB scale
% plot(f, 20*log10(abs(Y)));
% ylabel('Magnitude (dB)');
% Adjust plot
grid on;