You are on page 1of 22

Applications of DSP

in MATLAB
Image Processing in
MATLAB
clc
clear all
close all

% Reading of an image
i=imread('cameraman.tif’); % path of image

% Showing of an image
figure(1),imshow(i)

% Adding noise in an image


t1=imnoise(i,'salt & pepper');
figure(2),imshow(t1)
% Rotation of an image
t3=imrotate(i,45);
figure(3),imshow(t3);

% Increasing the brightness of an image


t4=i+50;
figure(4),imshow(t4);

% Decreasing the brightness of an image


t5=i-50;
figure(5),imshow(t5);
% Read the image in RGB format and Convert RGB image into Gray
 I=imread('r1.jpg');
I=rgb2gray(I);
figure, imshow(I),title('Original Image’);

% Save the gray image with name “test.png” in MATLAB folder


imwrite(I, 'test.png’);

% Read the saved image and give title as “Write Image with PNG
format”
B=imread('test.png');
figure, imshow(B),title('Write Image with png format');
% Basic Thresholding
 
I1=I>120;
figure, imshow(I1),title('Simple Image Thresholding');
 
%% Contrast Increase

%Id1=I+100;
Id1=imadd(I,100); %can use this command also for the previous
statement
figure,imshow(Id1),title('Contrast Increase');
%% Contrast Decrease
 
%Id2=Id-50;can use this command also for the next statement
Id2=imsubtract(I,50);
figure,imshow(Id2),title('Contrast decrease');
 
%% Image Multiply

Im=immultiply(I,0.5);
figure,imshow(Im), title('Image multiplied by 0.5');
 
 
%% Image Divide
Im1=imdivide(I,0.5);
figure,imshow(Im1),title('Image divided by 0.5');
Biomedical Signal
Processing in
MATLAB
1. Go to standard database website
https://archive.physionet.org/cgi-bin/atm/ATM

2. Download the data and save the values in the excel file

3. Load the excel file in MATLAB and plot


%Download ECG signals of Healthy and diseased subject

clc
clear all
close all

ii=xlsread('healthyecg.xlsx’); % Load data


subplot(2,1,1)
g=plot(ii)
axis([0 1000 -1 3])
title('Healthy ECG signal')
im=xlsread('diseasedecg.xlsx');
subplot(2,1,2)
g=plot(im)
axis([0 1000 -1 3])
title('Diseased ECG signal')
Generation of sound in
MATLAB
clc
clear all
close all
f=500; % set frequency, by changing frequency, sound will change
fs=32000; % sampling rate
d=3; % duration of music
n=fs*d;% number of samples
t=(1:n)/fs; % total number of data points
y=cos(2*pi*f*t);
 
% generate sound
sound(y,fs);
filename=('sound.wav');
audiowrite(filename,y,fs)
Generation of Echo in
MATLAB
• Write in Editor window
f=44100;
y=audioread('Example.mp3');
p=audioplayer(y,f);

• Write in Command window to play the audio file

play(p)

• Write in Command window to stop the audio file

stop(p)
• Write in Editor window and add the delay in audio file which produces Echo

num=[1,zeros(1,48000),0.9]; % increasing the delay


den=[1];
x=filter(num,den,y);
p1=audioplayer(x,f);

• Write in Command window to play the audio file

play(p1)

• Write in Command window to stop the audio file

stop(p1)
Generation of Music
“SAREGAMA” in
MATLAB
clc
clear all
close all
A=3;
N=2;
t=(0:0.001:N*8);
f=100;
sa=1/2*sin(2*pi*f*t);
re=1/2*sin(2*pi*f*t*9/8);
ga=1/2*sin(2*pi*f*t*5/4);
ma=1/2*sin(2*pi*f*t*4/3);
pa=1/2*sin(2*pi*f*t*3/2);
dha=1/2*sin(2*pi*f*t*5/3);
ni=1/2*sin(2*pi*f*t*15/8);
Sa=1/2*sin(2*pi*f*t*2);
Re=1/2*sin(2*pi*f*t*2*9/8);
Ga=1/2*sin(2*pi*f*t*2*5/4);
Ma=1/2*sin(2*pi*f*t*2*4/3);
Pa=1/2*sin(2*pi*f*t*2*3/2);
Dha=1/2*sin(2*pi*f*t*2*5/3);
Ni=1/2*sin(2*pi*f*t*2*15/8);
s=[sa re ga ma pa dha ni Sa];
b=fliplr(s);
s1=[sa re ga ma pa dha ni Sa b];
%sound(s1);
if strcmp(A,'sa')
sound(sa);
elseif strcmp(A,'re')
sound(re);
elseif strcmp(A,'ga')
sound(ga);
elseif strcmp(A,'ma')
sound(ma);
elseif strcmp(A,'pa')
sound(pa);
elseif strcmp(A,'dha')
sound(dha);
elseif strcmp(A,'ni')
sound(ni);
elseif strcmp(A,'Sa')
sound(Sa);
elseif strcmp(A,'sargam')
sound(s1);
elseif strcmp(A,'Re')
sound(Re);
elseif strcmp(A,'Ga')
sound(Ga);
elseif strcmp(A,'Ma')
sound(Ma);
elseif strcmp(A,'Pa')
sound(Pa);
elseif strcmp(A,'Dha')
sound(Dha);
elseif strcmp(A,'Ni')
sound(Ni);
elseif strcmp(A,'s1')
sound(s1)
end
end
• Write in Command window to play the audio “SA RE GA MA”
Sound(s1)

You might also like