You are on page 1of 6

clc

clear all

close all

%% Taking the time limit

n_lower = input('Enter the lower limit: ');

n_upper = input('Enter the upper limit: ');

n = n_lower : n_upper;

%% Unit Sample Sequence %%

x = [n==0];

subplot 221, stem(n,x)

xlabel('Time in Seconds')

ylabel('Unit sample value')

title('The Unit Sample Sequence')

%% Unit Step Sequence %%

x = [n>=0];

subplot 222, stem(n,x)

xlabel('Time in Seconds')

ylabel('Unit step value')

title('The Unit Step Sequence')

%% Unit Ramp Sequence %%

x = n.*[n>=0];

subplot 223, stem(n,x)

xlabel('Time in Seconds')

ylabel('Unit ramp value')

title('The Unit Ramp Sequence')

%% Exponential Sequence

a = input('Enter the co-eefifcient for Exponential Sequence: ');

e = exp(a.*n);

subplot 224, stem(n,e)

xlabel('Time in Seconds')

ylabel('Unit Exponential value')


title('The Exponential Sequence')

Convolution:
xn=input('enter the sequence 1 ');
l1=length(xn);
hn=input('enter the sequence 2 ');
l2=length(hn);
m=l1+l2-1;
z=zeros(1,m);
z=conv(xn,hn);
z1=zeros(1,m);
disp(z);
xnl1=[xn,zeros(1,l2-1)];
disp(xnl1);
hnl1=[hn,zeros(1,l1-1)];
disp(hnl1);
for i=1:m
for j=1:i
z1(i)=z1(i)+xnl1(j)*hnl1(i-j+1);
end;
end;
disp(z1);

>> convolution

enter the sequence 1 [1 2 3]

enter the sequence 2 [1 2 3]

1 4 10 12 9

1 2 3 0 0

1 2 3 0 0

1 4 10 12 9
%% *** Reading The Audio Signal *** %%
[n, Fs] = audioread('C:\Users\Acer\Downloads -dragon.mp3');
% Where n = Number of data in the audio signal % And Fs = no of Samples
per second in the audio signal
sound(n)
% This Function Plays the audio

[filename, pathname] = uigetfile('*', 'select the file');


[n,Fs] = audioread(num2str(filename));
P = audioplayer(n,Fs);
play(P)
% This function plays the audio

%% Recording the audio using audiorecorder function


Fs = 37500; % The rate of sampling
nBits = 16; % the number of bits
nChannel=1; %channel is defined
recObj = audiorecorder(Fs,nBits,nChannel);
disp('Start Recording')
record(recObj);
pause(5); % Defines the duration of record
disp('End of record')
y = getaudiodata(recObj); %storage of recording
sound(y,Fs);% Listening the record
audiowrite('My_Sound.wav',y,37500)% record is shaved

%% *** Program to make Echo of a given audio signal *** %%


clc
clear all
close all
% Defining the audio input function
[filename, pathname] = uigetfile('*', 'select the file');
[x,fs] = audioread(num2str(filename));
l = length(x); % length of audio signal
a=0.4; % amplitude of echo is defined
m = 0.2*fs; % The time after echo is generated
%loop adjustment
for i=1:m
x=[x; 0];
end
% Loop for producing echo
for i = 1:l+m
if i<=m
y(i) = x(i);
else
y(i) = x(i) + a*x(i-m);
end
end
p1 = audioplayer(x,fs) % The main audio
p0 = audioplayer(y,fs) % The audio added with echo
play(p0)

%% *** A program to produce multiple Echo levels *** %%


clc
clear all
close all
% Defining the audio input function from the user
[filename, pathname] = uigetfile('*', 'select the file');
[x,fs] = audioread(num2str(filename));
l = length(x); % Defining the length of audio signal
a=0.4; % amplitude
m = 0.2*fs; % The delay time after echo is generated
% Loop for adjusting the echo duration with main audio signal
for i=1:m
x=[x; 0];
end
% Loop
for i = 1:l+m
if i<=m
y(i) = x(i);
else
y(i) = x(i) + a*y(i-m); % audio is added repeatedly
end
end
p1 = audioplayer(x,fs) % The main file
p0 = audioplayer(y,fs) % The audio added with echo
play(p0)

%%For expansion of Time %%


clear all;
close all;
r = audioread('audio_file - dragon.mp3');
p1 = audioplayer(r,52000) % Sampling Frequency = 52000
play(p1);
% We can increase the sample number for expanding the signal

for i = 1 : (length(r));
y(2*i - 1) = r(i);
y(2*i) = 0;
end
% The upper loop will pad zero to the even positions of matrix y
p2 = audioplayer(r,12000); % Sampling Frequency = 12000
play(p2); %
%%program for Time Compression %%
% We can decrease the sample number for compressing the signal
for i = 1 : (length(r))/2;
y2(i) = r(2*i);
end
% The upper loop will be responsible for cancelling the odd elements in
signal x

%%for loop to recover Original Signal by Average Method


for i = 1 : (length(y2))
y2(2*1 -1) = y2(i);
if i < length(y2)
y(2*1) = (y2(i) + y2(i+1))/2;
else
y(2*i) = y2(i);
end
end
p3 = audioplayer(y2,32000);
play(p3);

clc
clear all
close all
% Taking the image as input
% RGB Image
img = uigetfile('*', 'Select your image');
x = imread(img);
figure(1)
imshow(x)
% GrayScale Image
x1 = rgb2gray(x);
figure(2)
imshow(x1)

You might also like