Thursday, 19 December 2013

Addition and Multiplication of Two Sequences

close all;
clear all;
clc;
x=input('enter sequence -1');
y=input('enter input sequence-2');
M=length(x);
N=length(y);
subplot(2,2,1);
stem(x);
xlabel('time');
ylabel('amplitude');
title('input sequence-1');
subplot(2,2,2);
stem(y);
xlabel('time');
ylabel('amplitude');
title('input sequence-2');
if M>N
z=x+[y,zeros(1,M-N)];
a=x.*[y,zeros(1,M-N)];
else
z=[x,zeros(1,N-M)]+y;
a=[x,zeros(1,N-M)].*y;
end;
subplot(2,2,3);
stem(z);
xlabel('time');
ylabel('amplitude');
title(' Addition of input sequences");
subplot(2,2,4);
stem(a);
xlabel('time');
ylabel('amplitude');
title('multiplication of input sequences ');

Output:
 sequence -1[1 4 8 6]
enter input sequence-2[1 6 8 9]



Sinc funtion and Triangular function

close all;
clear all;
clc;
t=-4:0.1:4;
x=sinc(pi*t);
subplot(2,1,1);
plot(x);
xlabel('time');
ylabel('amplitude');
title('sinc function');
y=0:0.5:2;
for j=0:3
x=(4*j)+y;
subplot(2,1,2);
plot(x,y);
hold on;
end;
for k=0:3
x=(4*k)-y;
subplot(2,1,2);
plot(x,y);
hold on;
end;
hold off;

Output:

Program for Impulse Function and Step function Generation

close all;
clear all;
clc;
n=[-5:5];
i=imp_scr(0,-5,5);
subplot(2,1,1);
stem(n,i);
xlabel('time');
ylabel('amplitude');
title('impulse function');
s=step_scr(0,-5,5);
subplot(2,1,2);
plot(n,s);
xlabel('time');
yalbel('amplitude');
title('step sequence');
%user defined functons

%for imp_scr
function[x,n]=imp_scr(no,n1,n2);
n=[n1:n2];
x=[(n-n0)==0];

%for step_scr
function[x,n]=step_scr[n0,n1,n2];
n=[n1:n2];
x=[(n-n0)>=0];


Note: the user has to type the user defined functions in a new window and save them with the exact same names of imp_scr and step_scr if the user defined functions are to work
The files are to be saved in the same directory as the original file.

Program for Ramp Function and Sequence

close all;
clear all;
clc;
t=0:1:25;
r=t;
subplot(2,1,1);
plot(t,r);
xlabel('time');
ylabel('amplitude');
title('ramp function');
subplot(2,1,2);
stem(t,r);
xlabel('time');
ylabel('amplitude');
title('ramp sequence');

Output:



Basic Waves in Discrete Time Domain

close all;
clear all;
clc;
t=0:0.001:2;
f=1;
w=2*pi*f;
a=sint(w*t);
subplot(2,2,1);
stem(t,a);
xlabel('time');
ylabel('amplitude');
title('sinusoidal signal');
b=cos(w*t);
subplot(2,2,2);
stem(t,b);
xlabel('time');
ylabel('amplitude');
title('co-sinusoidal signal');
c=square(w*t);
subplot(2,2,3);
stem(t,c);
xlabel('time');
ylabel('amplitude');
title('square signal');
d=sawtooth(w*t);
subplot(2,2,2);
stem(t,d);
xlabel('time');
ylabel('amplitude');
title('sawtooth signal');

Various Basic Signals

close all;
clear all;
clc;
t=0:0.001:2;
f=1;
w=2*pi*f;
a=sint(w*t);
subplot(2,2,1);
plot(t,a);
xlabel('time');
ylabel('amplitude');
title('sinusoidal signal');
b=cos(w*t);
subplot(2,2,2);
plot(t,b);
xlabel('time');
ylabel('amplitude');
title('co-sinusoidal signal');
c=square(w*t);
subplot(2,2,3);
plot(t,c);
xlabel('time');
ylabel('amplitude');
title('square signal');
d=sawtooth(w*t);
subplot(2,2,2);
plot(t,d);
xlabel('time');
ylabel('amplitude');
title('sawtooth signal');

Output:



Basic Operations on Matrices Matlab Code

clear all;
close all;
clc;
a=input('enter matrix A:');
b=input('eneter matrix B:');
c=input('enter Matrix C:');
disp('the size of matrix A is :');
disp(size(a));
disp('the size of matrix B is :');
disp(size(b));
disp('the size of matrix C is :');
disp(size(c));
disp('the addition of matrices A & B is:');
disp(a+b);
disp('the substraction of matrices A & B is :');
disp(a-b);
disp('the element by element multiplication of A & B is:');
disp(a.*b);
disp('The trace of matrix C is :');
disp(trace(c));
disp('the determinant of the matrix C is :');
disp(det(c));
disp ('the inverse of matrix C is :');
disp(inv(c));
disp(' the rank of matrix C is :');
disp(rank(c));

Outputs if the specied inputs as given  below are:

Matrix A : [1 2;3 4]
Matrix B : [3 4;5 6]
Matrix C:  [1 2;3 4]

The size of matrix A is
       2     2
The size of matrix B is
      2      2
The size of matrix c is
      2       2
the addition of matrices A & B is:  4     6
                                                    8      10
the substraction of matrices A & B is :  -2    -2
                                                            -2    -2

the element by element multiplication of A & B is:  3     8
                                                                            15  24

The trace of matrix C is : 5

the determinant of the matrix C is : -2

the inverse of matrix C is :   -2.000       1.000
.                                         1.5000      -0.5000

the rank of matrix C is : 2

Tuesday, 24 September 2013

Fm Modulation Code

the Program for coding Freequency Modulation is

clc;
fs=1000;
fc=100;
t=[0:fs]/fs;
k=50;
x=sin(2*pi*t);
subplot(3,1,1);
plot(t,x);
title('message sigal');
xlabel('time');
ylabel('amplitude');
y=fmmod(x,fc,fs,k);
subplot(3,1,2);
plot(t,y);
xlabel('time');
ylabel('amplitude');
title('modulated signal');
z=fmdemod(y,fc,fs,k);
subplot(3,1,3);
plot(t,z);
xlabel('time');
ylabel('amplitude');
title('demodulated wave');


The Output for the above program is:

Wednesday, 4 September 2013

DSBSC Modulation Code

The program for  DSBSC Modulation is:

clc;
clr;
fs=2;
fc=50;
t=0:0.001:1;
x=sin(2*pi*fs*t);
y=sin(2*pi*fc*t);
subplot(2,2,1);
plot(t,x);
xlabel('time');
ylabel('amplitude');
title('message signal');
subplot(2,2,2);
plot(t,y);
xlabel('time');
ylabel('amplitude');
title('carrier signal');
z=x.*y;
subplot(2,2,3);
plot(z,t);
xlabel('time');
ylabel('amplitude');
title('DSBSC Modulated Waveform');
d=z./y;
subplot(2,2,4);
plot(t,d);
xlabel('time');
ylabel('amplitude');
title('Demodulated Wave');



The output of the code is given as follows:


Tuesday, 6 August 2013

Amplitude modulation Code in Matlab


Program

fs=500;
fc=50;
t=[0:2*fs]/fs;
x=2*sin(2*pi*t);
y=ammod(x,fc,fs);
z=fft(y);
f=[0:length(z)-1];
subplot(2,2,1);
plot(t,x);
xlabel('time');
xlabel('Freequency');
ylabel('amplitude');
title('Input Waveform');
subplot(2,2,2);
plot(f,y);
ylabel('amplitude');
title('modulated waveform');
subplot(2,2,3);
plot(f,z);
xlabel('Freequency');
ylabel('amplitude');
title('spectrum diagram');x= ammod(y,fc,fs);
subplot(2,2,4);
plot(t,x);
xlabel('time);
ylabel('amplitude);
title('demodulated waveform)




Output waveforms



SSB Modulator Internal Block Diagram





Internal Block diagram and Connections of SSB Modulator


Non Phase shifted Sinusoidal Input waveform - Message Signal

Non Phase shifted Sinusoidal Input waveform - Carrier Signal


Phase shifted Sinusoidal Input waveform - Message Signal


Phase shifted Sinusoidal Input waveform - Carrier Signal




Spectrum Analyser Block Properties



Spectrum Analyser Output




The Experiment

To perform this experiment first insert four sine wave blocks into the workspace

Then place two sine wave blocks together to a multiplier and the other two to another multiplier

In two of the sime wave blocks connected to the same multiplier change the inital phase reading to 90 degrees as shown in the source block parameters

Connect the outputs of the multipliers to an adder and the output of the adder to a spectrumm analyser

DSBSC using Internal Structure of blocks


DSBSC Internal Structure Block Diagram



Input Sine Wave 1 Parameters - Carrier Wave



Sine Wave Input Paraneters - Message Signal



Spectrum Analyser Output DSBSC

DSBSC


BLOCK DIAGRAM DSBSC MODULATOR


Source Block parameters



Modulator Properties DSBSC



DSBSC Modulated Wave

DSBSC Demodulator Blockset

DSBSC Demodulator Properties








DSBSC Demodulated Waveform

SSB MODULATION


MODULATOR BLOCKSET


SOURCE BLOCK PARAMETERS




MODULATOR PROPERTIES

MODULATED WAVE


DEMODULATION BLOCKSET


DEMODULATOR PROPERTIES WINDOW

DEMODULATED WAVEFORM



Freequency Modulation

FREQUENCY MODULATION

The Blocks required for frequency modulation are:
1.Sine wave Block
2. Frequency Modulation Block
3. Sampling Scope

Connect the blocks as shown in the diagram below

Block Diagram

The parameters for the Modulator along with freequency values and other necessary settings are shown in the diagram below


Modulator properties

The source parameters including frequency of the input sine wave are shown in the picture below


Source block parameters

The output waveform appears in the CRO as:

Modulated waveform

For demodulation connect a FM demodulator block in between the FM modulator block and the sampling scope and connect them as shown in the diagram below.




Demodulator block diagram
With the settings of the source and modulator blocks remaining the same adjust the demodulator to the necessary frequency and other parameters as necessary and as shown in the picture below:




FM Demodulator properties

The Demodulated output appears in the CRO as thus:



Demodulatoed Waveform





AM Modulation

The Block diagrams required for the AM Modulation are:
1. Sine Wave Block

2. Amplitude Modulator Block
3.Sampling Scope

Connect the blocks as shown in the diagram below




Block diagram of AM modulator in SIMULINK


The parameters of the input sine wave block are as given in the block below.
Set the parameters as shown in the diagram



Source block properties along with their values

The values of the modulator along with requisite frequencies are as given below


Modulator properties along with their values


The DSBSC modulated waveform is as given below


AM Modulated wave

                                                   Demodulated or Input wave









The lab maual can be downloaded from this link along with all thie pics above

https://docs.google.com/file/d/0B_sevGyWoSsNdEsxOE9SbzctUWc/edit?usp=sharing