You are on page 1of 9

Table of Contents

........................................................................................................................................ 1
Q1 Reading Given MP3 using audioread ................................................................................. 1
1a Plotting initial 4 sec ........................................................................................................ 1
1b creating new file ............................................................................................................. 2
1c Playing Audio ................................................................................................................ 2
1d Audio Info ..................................................................................................................... 2
1e Convert Samples to vectors .............................................................................................. 2
Q2 Finding error between data and resultant samples ................................................................ 2
Q3 Reading given txt data .................................................................................................... 3
Q4 Read given jpeg image ................................................................................................... 3
4a Seperate RGB ................................................................................................................ 4
4b Resizing image ............................................................................................................... 6
4c Conversion of colour to gray ............................................................................................ 7
4d Creating RGB from red pallete ......................................................................................... 7
Q5 Reading xls file and displaying image ............................................................................... 8
Q6 Calculating no. of frames ................................................................................................ 8
Q6b Extract frames till 2 secs ............................................................................................... 9

%%LAB1

Author :Aadhitiya VS

net id av558

1710110001

Professors Dr. Vijay Kumar Chakka and Dr. Upendra Pandey

clc; %clears the command window


clearvars; % clears the variables

Q1 Reading Given MP3 using audioread


[y,fs]=audioread('Signal_Processing_Audio.mp3'); %reads the sampled
data and sampling frequency

fy=y(:,1); %Selecting first column of y

1a Plotting initial 4 sec


T=4;
ydata=fy(1:T*fs); %Sampled data for first 4 seconds
t=0:1/fs:T-1/fs; %from 0 to t-1 samples
plot(t,ydata); % plots t vs ydata
xlabel('time(sec)'); %labelling x axis
ylabel('Amplitude'); % labelling y axis
title('sound'); %title of the plot

1
1b creating new file
audiowrite('new_audio.wav',ydata,fs); % writes a matrix of audio data,
y with sample rate to a new.wave
% on increasing fs the song is faster

1c Playing Audio
sound(ydata,fs); %sound function plays the audio

1d Audio Info
audioinfo('new_audio.wav');

1e Convert Samples to vectors


Y=reshape(ydata,[44100,4]); % we reshaped ydata vector into a matrix Y

Q2 Finding error between data and resultant


samples
flo = floor(ydata); %flooring ydata

2
ce= ceil(ydata); %ceiling ydata
ro = round(ydata); %rounding data
diff1 = ydata - flo; %calculating difference then we calculate
absolute
diff2 = ydata - ce;
diff3 = ydata - ro;
ab1 = abs(diff1);
ab2 = abs(diff2);
ab3 = abs(diff3);
F = sum(ab1(:)); %adding the absolute value of the difference between
floor and ydata
G = sum(ab2(:));
H = sum(ab3(:));

Q3 Reading given txt data


data=load('ECG_data(1).txt');%Loads data from file name
figure;
plot(data);
title('ECG data');

Q4 Read given jpeg image


I=imread('RGB_Image.jpg'); %Reads the file. We know image is a 3d
vector and we want to break it into 3 vectors.

3
Ir=I(:,:,1); % We are breaking 3d vector into a single vector of red
colour
Ig=I(:,:,2); % breaking the 3d vector into a single vector of 2nd
coloumn of green.
Ib=I(:,:,3); % Similar process for blue

4a Seperate RGB
figure;
imshow(I); %Shows the coloured image
title('coloured image');
figure;
imshow(Ir); %shows the red pallete but its grey
title('red image');
figure;
imshow(Ig); % shows green pallete but its grey
title('green image');
figure;
imshow(Ib); % shows blue pallete but its grey
title('blue image');

4
5
4b Resizing image
I1=imresize(I,1.5); %resizes I to 1.5 its size and stores it in I1
figure;
imshow(I1); %shows 1.5x the image
title('resize');

6
4c Conversion of colour to gray
Igray=rgb2gray(I); % converts I to Grayscale Igray
figure;
imshow(Igray); %the difference is that they are gray now
title('Grayscale');

4d Creating RGB from red pallete


A=zeros(330,510); %creating a zero matrix for Green
B=zeros(330,510); %creating a zero matrix for blue

C=cat(3,Ir,A,B); %creating rgb by appending zeroes to extracted red


pallete

imwrite(C,'Ired.jpeg'); %creates a new image


figure;
imshow(C);
title('Red RGB');

7
Q5 Reading xls file and displaying image
[numstr,str]=xlsread('Text_Data.xlsx');
%to convert string into characters
c1=char(str);
asc=double(c1); %converting to double
img=reshape(asc,[],11); %resizing to our own specifications
figure;
imshow(img);
title('xls image');

Q6 Calculating no. of frames


V = VideoReader('Signal_Processing_Video.mp4'); %Reads the input video
Fra1 = V.Framerate*V.Duration; %gives us total number of frames
Framerate = V.Framerate;
no.Frames = round(Fra1); %Rounding off to get total number of frames

8
Q6b Extract frames till 2 secs
Vid = VideoWriter('New.avi'); %writing video data into avi file
open(Vid); %opening it to write video data
for i=0:2*Framerate; % for loop to collect frames till 2 seconds
f = readFrame(V); %storing it in frames
writeVideo(Vid,f); %writing video with the frames obtained till 2 secs
end
close(Vid);
implay('New.avi'); %plays the new video created

Published with MATLAB® R2016a

You might also like