1. Write a program in MATLAB to generate the following waveforms
1. Unit step sequence,
2. Unit Ramp sequence,
3. Sinusoidal sequence,
4. Exponential sequence,
5. Random sequence
t = 0:0.01:1; %this t is the sampling frequency fs = 1/t,
%which is needed as matlab only plots discrete
f = 5 ;
%this f is the signal frequency
d = sind(360*f*t)%just to check the sind function which takes values in
degrees
figure(2)
plot(t,d)
y = sin(2*pi*f*t);
figure(1)
subplot(2,3,2), plot(t,y)
title('sine')
%used to give title to the graph
axis([-2 2 -2 2]) %used to set the axis max and min
subplot(2,3,3), stem(t,y)
title('discrete sine')
xlabel('time')
%to give title to the X-axis
ylabel('amplitude') %to give title to the Y-axis
subplot(2,3,4), plot(t,t)
title('ramp')
xlabel('time')
ylabel('amplitude')
a = exp(t);
subplot(2,3,5),plot(a)
title('exponential')
xlabel('time')
ylabel('amplitude')
r = rand([1,40])
subplot(2,3,6),plot(r)
title('random')
xlabel('time')
ylabel('amplitude')
for k=1:1:10
stp(k)=1;
end
y1=[0:1:9]
%step function needs an array for plot
subplot(2,3,1),plot(y1,stp)
title('step')
xlabel('time')
ylabel('amplitude')
Figure 1 ques1
Figure 2 Discrete time signals of quest1 by replacing plot with stem
2. Write a program in MATLAB to study the basic operations on the Discrete – time signals.
(Operation on dependent variable (amplitude manipulation) and Operation on independent
variable (time manipulation)).
n = 0:0.01:1; %this t is the sampling frequency fs = 1/t,
%which is needed as matlab only plots discrete
p = n-3
f = 5;
%this f is the signal frequency
y = sin(2*pi*f*p)
subplot(1,3,1),plot(n,y,p,y)
title('time shift')
axis([-5 5 -2 2])
subplot(1,3,2),plot(n,y,n,y+2)
title('offset')
subplot(1,3,3),plot(n,y,n,y*2)
title('amplitude')
Figure 3 ques2
3. Histogram
clear
Y = [3 3 1 1 2 2 15 5 5 5 7 7 8 8 8 8]
n=1;
for j=1:length(Y)
a=0;
k = Y(j);
for n=1:length(Y)
if Y(n) == k && n~=(length(Y)+1)
a = a+1;
end
end
S(Y(j)) = a;
end
S
plot(S,'.')
figure,hist(Y)
Figure 4 quest3
4. convolution
clear all
close all
clc
x =
h =
yyy
m =
n =
X =
H =
for
[1 2 6 0 3];
[0 6 3 1 7 8];
= conv(x,h)
length(x);
length(h);
[x,zeros(1,n)];
[h,zeros(1,m)];
i=1:n+m-1
Y(i)=0;
for j=1:m
if(i-j+1>0)
Y(i)=Y(i)+X(j)*H(i-j+1);
else
end
end
end
Y
figure(1)
stem(Y);
ylabel('Y[n]');
xlabel('n -->');
title('Convolution w/o "conv" function');
% for circular convolution
x = [1 0 2 3 2 3 2 3 2 3];
h = [1 3 5 6 5 6 5 6 5 6 5 6];
n1 = length(x);
n2 = length(h);
n = max(n1,n2);
x = [x,zeros(1,n-n1)];
h = [h,zeros(1,n-n2)];
y = zeros(1,n);
for i=0:n-1
for j=0:n-1
k = mod((i-j),n);
y(i+1) = y(i+1) + x(j+1)*h(k+1);
end
end
a = 1:n;
figure (2)
stem(a,y)
ylabel('Y[n]');
xlabel('n -->');
title('Circular convolution w/o "conv" function');
Output
yyy =
0
6 15 43 27 46 67 51 21 24
Y=
0
6 15 43 27 46 67 51 21 24
Figure 5 quest4
5. DTMF
f0=340; d=f0; % Pick a frequency and the note D
f=f0*(2^(3/12)); g=f0*(2^(5/12)); % The notes F and G
bf=f0*(2^(8/12)); c=f0*(2^(10/12)); % The notes B(flat) and C
d2=2*d; % The note D (an octave higher)
ts=1/8192; % Sampling interval
t=0:ts:0.4; % Time for each note (0.4 s)
s1=0*(0:ts:0.1); % Silent period (0.1 s)
s2=0*(0:ts:0.05); % Shorter silent period (0.05 s)
tl=0:ts:1; % Time for last note of each scale
d1=sin(2*pi*d*t); % Start generating the notes
f1=sin(2*pi*f*t); g1=sin(2*pi*g*t);
bf1=sin(2*pi*bf*t); c1=sin(2*pi*c*t);
dl1=sin(2*pi*d2*tl); dl2=sin(2*pi*d*tl);
asc=[d1 s1 f1 s1 g1 s1 bf1 s1 c1 s2 dl1]; % Create ascending scale
dsc=[c1 s1 bf1 s1 g1 s1 f1 s1 dl2]; % Create descending scale
y=[asc s1 dsc s1]; sound(y) % Malkauns scale (y)
CODE 2 (dial tone of a landline buttons)
t = 0:0.01:1;
ts=1/8192;
a1 = sin(2*pi*697*t)+sin(2*pi*1209*t);
a2 = sin(2*pi*697*t)+sin(2*pi*1336*t);
a3 = sin(2*pi*697*t)+sin(2*pi*1477*t);
a4 = sin(2*pi*770*t)+sin(2*pi*1209*t);
a5 = sin(2*pi*770*t)+sin(2*pi*1336*t);
a6 = sin(2*pi*770*t)+sin(2*pi*1477*t);
a7 = sin(2*pi*852*t)+sin(2*pi*1209*t);
a8 = sin(2*pi*852*t)+sin(2*pi*1336*t);
a9 = sin(2*pi*852*t)+sin(2*pi*1477*t);
a0 = sin(2*pi*941*t)+sin(2*pi*1336*t);
s1 = (0:ts:0.5);
y = [a4 s1 a8 s1 a7 s1 a2 s1 a5 s1 a5 s1 a0]
sound(y)
6. sound and frequency response
n = 0:0.01:1; %this t is the sampling frequency fs = 1/t,
%which is needed as matlab only plots discrete
for f=1:10:5000
y = sind(2*pi*f*n);
sound(y)
end
freqz(y)
Figure 6 quest6
7. FFT using DIT and DIF
N=input('Enter the number of elements:');
for i=1:N
re(i)= input('Enter the real part of the element:');
im(i)= input('Enter the imaginary part of the element:');
end
%% Call Dit_fft function
[re1,im1]= ditfft(re,im,N);
disp(re1);
disp(im1);
figure(1);
subplot(2,2,1);
stem(re1);
xlabel('Time period');
ylabel('Amplitude');
title('Real part of the output');
subplot(2,2,2);
stem(im1);
xlabel('Time period');
ylabel('Amplitude');
title('Imaginary part of the output');
© Copyright 2026 Paperzz