Monday, November 23, 2015

Sampling a Signal using Matlab

SAMPLING:
The matlab code for sampling of sinusoidal signal shown in below..
clc;
clear all;
close all;
fs=500e3; %Very high sampling rate 500 kHz
f=10e3; %Frequency of sinusoid
nCyl=5; %generate five cycles of sinusoid
t=0:1/fs:nCyl*1/f; %time index
x=cos(2*pi*f*t);
figure,
 plot(t,x)
title('Continuous sinusoidal signal');
xlabel('Time(s)');
ylabel('Amplitude');
fs1=30e3; %3kHz sampling rate
t1=0:1/fs1:nCyl*1/f; %time index
x1=cos(2*pi*f*t1);
 fs2=50e3; %5kHz sampling rate
t2=0:1/fs2:nCyl*1/f; %time index
x2=cos(2*pi*f*t2);
figure,
subplot(2,1,1);
%plot(t,x);
stem(t1,x1);
title('Sampling Continuous sinusoidal signal at f1=3kHz');
xlabel('Time(s)');
ylabel('Amplitude');
%hold on;

subplot(2,1,2);
%plot(t,x);
stem(t2,x2);
title('Sampling Continuous sinusoidal signal at f2=5kHz');
xlabel('Time(s)');
ylabel('Amplitude');
hold on;

OUTPUT:


See you with next tutorial.....

HOW TO READ IMAGE FROM FILE USING MATLAB?

Read Image and Display:

Read image from file and display, we have to type this code in matlab and run..
clc;
clear all;
close all;
[FileName,PathName] = uigetfile('*.jpg','Select the IMAGE file');
I=imread([PathName,FileName]);
% I=imresize(I,[256 256]);
imshow(I);
title('Input Image');

THE OUTPUT RESULT:

Sunday, November 22, 2015

CROP iMAGE using MATLAB

Read image into the workspace.
          I = imread('cameraman.tif');
Open Crop Image tool associated with this image. Specify a variable in which to store the cropped image. The example includes the optional return value rect in which imcrop returns the four-element position vector of the rectangle you draw.
         [I2, rect] = imcrop(I);
When you move the cursor over the image, it changes to a cross-hairs . The Crop Image tool blocks the MATLAB command line until you complete the operation.
Using the mouse, draw a rectangle over the portion of the image that you want to crop.
Perform the crop operation by double-clicking in the crop rectangle or selecting Crop Image on the context menu.
The Crop Image tool returns the cropped area in the return variable, I2. The variable rect is the four-element position vector describing the crop rectangle you specified.
now we can see the crop image by type the commend 
                                               imshow(I2);


see you with next interesting idea....