CS Assignment 1
CS Assignment 1
Assignment 1
Write a MATLAB program for generations of following periodic/ aperiodic signals ,
Plot the same using MATLAB subplot function, label the axis and title each subplot.
Part a)
%Write a MATLAB program for generations of following periodic/ aperiodic
signals :
% Square, exponential(decay and rising), Ramp.
x=0:0.01:20;
y1=sin(x);
y2=cos(x);
y3=square(x,50);
y5=exp(x);
y6=exp(x).^-1;
subplot(3,2,1);
plot(x,y1);
xlabel('X-axis');
ylabel('Sin(x)');
title('Subplot 1: sin(x)');
subplot(3,2,2);
plot(x,y2);
xlabel('X-axis');
ylabel('cos(x)');
title('Subplot 2: cos(x)');
subplot(3,2,3);
plot(x,y3);
xlabel('X-axis');
ylabel('square(x)');
title('Subplot 3: square(x)');
subplot(3,2,4);
plot(x,x);
xlabel('X-axis');
ylabel('ramp(x)');
title('Subplot 3: ramp(x)');
1
Circuit Simulation Laboratory
subplot(3,2,5);
plot(x,y5);
xlabel('X-axis');
ylabel('exp(x)');
title('Subplot 3: exponential rising');
subplot(3,2,6);
plot(x,y6);
xlabel('X-axis');
ylabel('exp(-x)');
title('Subplot 3: exponential decay');
Fig 1.1 Sine, Cosine, Ramp, Exponential rising and decaying signals
2
Circuit Simulation Laboratory
Part b)
%Generate a sinusoidal waveforms x1(n) and x2(n) of 50 Hz and 120Hz
respectively.
%Generate a composite signal which is addition of these two sinusoids.
%Find the spectrum of signal using Fourier analysis.
3
Circuit Simulation Laboratory
INFORMATION:-
FFT:
4
Circuit Simulation Laboratory
PLOT:
SUBPLOT:
5
Circuit Simulation Laboratory
Conclusion:-
Thus, we have generated different signals such as ramp, square, exponential, sine using the basic
functions in the MATLAB. Also we have generated a composite signal which is addition of two
sinusoids .Taking fast Fourier transform of the mixed sum of two sinusoidal signals we plot its
amplitude spectra taking absolute value using abs( ) function in the MATLAB.