Popular Posts

Monday, October 31, 2011

MATLAB : Frequently used built-in functions in Signal Processing Toolbox

filter(b,a,x)


FILTER One-dimensional digital filter.
    Y = FILTER(B,A,X) filters the data in vector X with the
    filter described by vectors A and B to create the filtered
    data Y.  The filter is a "Direct Form II Transposed"
    implementation of the standard difference equation:

    a(1)*y(n) = b(1)*x(n) + b(2)*x(n-1) + ... + b(nb+1)*x(n-nb)
                          - a(2)*y(n-1) - ... - a(na+1)*y(n-na)

    If a(1) is not equal to 1, FILTER normalizes the filter
    coefficients by a(1).

    FILTER always operates along the first non-singleton dimension,
    namely dimension 1 for column vectors and non-trivial matrices,
    and dimension 2 for row vectors.



fft(x) 

FFT Discrete Fourier transform.
    FFT(X) is the discrete Fourier transform (DFT) of vector X.  For
    matrices, the FFT operation is applied to each column. For N-D
    arrays, the FFT operation operates on the first non-singleton
    dimension.



ifft(x)

IFFT Inverse discrete Fourier transform.
    IFFT(X) is the inverse discrete Fourier transform of X.



conv(a,b)


CONV Convolution and polynomial multiplication.
    C = CONV(A, B) convolves vectors A and B.  The resulting vector is
    length MAX([LENGTH(A)+LENGTH(B)-1,LENGTH(A),LENGTH(B)]). If A and B are
    vectors of polynomial coefficients, convolving them is equivalent to
    multiplying the two polynomials.





deconv(b,a)



   [Q,R] = DECONV(B,A) deconvolves vector A out of vector B.  The result
    is returned in vector Q and the remainder in vector R such that
    B = conv(A,Q) + R.

    If A and B are vectors of polynomial coefficients, deconvolution
    is equivalent to polynomial division.  The result of dividing B by
    A is quotient Q and remainder R.





abs(x)


ABS    Absolute value.
    ABS(X) is the absolute value of the elements of X. When
    X is complex, ABS(X) is the complex modulus (magnitude) of
    the elements of X.





angle(h)


ANGLE  Phase angle.
    ANGLE(H) returns the phase angles, in radians, of a matrix with
    complex elements. 





freqz(b,a,N)


FREQZ Digital filter frequency response.
    [H,W] = FREQZ(B,A,N) returns the N-point complex frequency response
    vector H and the N-point frequency vector W in radians/sample of
    the filter:
                jw               -jw              -jmw
         jw  B(e)    b(1) + b(2)e + .... + b(m+1)e
      H(e) = ---- = ------------------------------------
                jw               -jw              -jnw
             A(e)    a(1) + a(2)e + .... + a(n+1)e
    given numerator and denominator coefficients in vectors B and A. The
    frequency response is evaluated at N points equally spaced around the
    upper half of the unit circle. If N isn't specified, it defaults to
    512.





stem(y)


STEM   Discrete sequence or "stem" plot.
    STEM(Y) plots the data sequence Y as stems from the x axis
    terminated with circles for the data value. If Y is a matrix then
    each column is plotted as a separate series.







stem(x,y)



STEM(X,Y) plots the data sequence Y at the values specified
    in X.



plot(x,y)


PLOT   Linear plot.
    PLOT(X,Y) plots vector Y versus vector X. If X or Y is a matrix,
    then the vector is plotted versus the rows or columns of the matrix,
    whichever line up.  If X is a scalar and Y is a vector, disconnected
    line objects are created and plotted as discrete points vertically at
    X.





title('text')


TITLE  Graph title.
    TITLE('text') adds text at the top of the current axis





xlabel('text')


XLABEL X-axis label.
    XLABEL('text') adds text beside the X-axis on the current axis.





ylabel('text')




YLABEL Y-axis label.
    YLABEL('text') adds text beside the Y-axis on the current axis.

Thursday, October 27, 2011

How to hack a Walgreens Digital Camera ???

Walgreens provides access to consumer goods and services and pharmacy, health and wellness services in America through its retail drugstores, Walgreens Health Services division and Walgreens Health and Wellness division. Walgreens Health Services offers pharmacy patients and prescription drug and medical plans through Walgreens Mail Service Inc., Walgreens Home Care Inc., Walgreens Specialty Pharmacy LLC and SeniorMed LLC (a pharmacy provider to long-term care facilities). Walgreens Health and Wellness division includes Take Care Health Systems. Walgreens has 7,733 drugstores as of June 30, 2011.

One such product is the Walgreens Digital Camera. The camera, which I got as a gift has a resolution of 5.1 MP, 4X Digital Zoom, 1.5'' LCD Display, built in flash and built in memory.

The image quality is good, but the LCD Display provided is of poor quality. It can be just used for getting the outline of the picture you are capturing.

The camera comes at a very low cost, around 30 USD  (US Dollars) which is equivalent to 1500 - 1600 INR. (Indian Rupees).
 
But the problem is retrieving the images captured. According to the information booklet and the website, the
photos taken with the digital camera can be retrieved only at the Walgreens outlet, i.e. one has to depend on the company to retrieve the photos. The stores are available in US alone, hence the camera might be useless for people outside US( United States).

The low cost of the camera is thus recovered as printing cost .


A brief look at some facts ....

Pricing ..




Camera features and conditions ....








When I got the camera and used it for the first time, I was shocked on how to retrieve the images. Personally, I am a user who lives in India, hence, unable to avail the services of a Walgreens retail outlet.

But soon I found out a solution,

I examined the connector port and found it very similar to that of USB Flash Drive ( Pen Drive).

Now I will get you through some steps which will enable one to access the photos in the camera without even going to a WALGREENS company outlet !

Just go to a nearby electronic shop and get a USB to USB cable ie it has the male connectors at one end and female connector pins at the other end, something given like the one below.







Just remove the metal shield at one end as indicated in the picture below ...




 After removing the metal shield from one side, the USB cable will look somewhat like this, and you will also
get a rectangular strip which is used for providing the correct spacing while a device is to be plugged to the port.


Cable after the USB Shield is removed......




I had mentioned earlier about, the white rectangular strip .. Just get that strip into the camera port as shown .





The camera can now be easily connected to a PC/Laptop and the camera will function as a USB Flash Drive ( Hence no additional drivers are required.).  The LCD display of the camera will indicate it with a message 'USB' with the symbol.
After connecting the camera to PC




The computer will recognize it as a flash drive ..










The USB to USB cable costs less than a dollar (around 40 INR).

Enjoy taking photos .. retrieve them, print them, as you wish without spending more ....

Here are a few of my clicks. . . 


  






After copying the captured images, you can remove the usb cable from the camera and the display might flash something like this.




It will give an option


-Either to retain the photos, by pressing the shutter key

-Or to format the memory by pressing the DEL. key.

It is advisable to format the memory each time after copying, since the camera has the capability to hold 50 photos at a time.

Enjoy !!

Saturday, October 22, 2011

Some important commands in MATLAB

HELP

HELP Display help text in Command Window.

HELP, by itself, lists all primary help topics. Each primary topic
      corresponds to a directory name on the MATLABPATH.

      HELP / lists a description of all operators and special characters.

      HELP FUN displays a description of and syntax for the function FUN.
      When FUN is in multiple directories on the MATLAB path, HELP displays
      information about the first FUN found on the path.


EXAMPLES:
      help close - displays help for the CLOSE function.



DEMO

DEMO Access product demos via Help browser.

    DEMO opens the Demos pane in the Help browser, listing
    demos for all installed products that are selected
    in the Help browser product filter.

    DEMO SUBTOPIC opens the Demos pane to the specified
    SUBTOPIC, which can be 'matlab', 'toolbox',
    'simulink', 'blockset', or 'links and targets'.

    DEMO SUBTOPIC CATEGORY opens the Demos pane to the
    specified CATEGORY, where CATEGORY can be a product
    or category within SUBTOPIC.
   
    Examples:
        demo matlab



WHO

WHO    List current variables.
    WHO lists the variables in the current workspace.



WHOS

WHOS List current variables, long form.
    WHOS is a long form of WHO.  It lists all the variables in the current
    workspace, together with information about their size, bytes, class,
    etc.



CLEAR

CLEAR  Clear variables and functions from memory.
    CLEAR removes all variables from the workspace.



CLC

CLC    Clear command window.
    CLC clears the command window and homes the cursor.



CLOSE

CLOSE  Close figure.
CLOSE, by itself, closes the current figure window.


QUIT

QUIT Quit MATLAB session.
    QUIT terminates MATLAB after running the script FINISH.M,
    if it exists. The workspace information will not be saved
    unless FINISH.M calls SAVE. If an error occurs while
    executing FINISH.M, quitting is cancelled.

MATLAB - Editor Window

Editor Window is to create program files with an extension .m

A new blank m-file can be choosen from the option
File-->New-->Blank M-File


MATLAB Command Window

Command Window is characterised by the propmpt '>>'.

All Commands and the ready to run program filename can be typed here.

Graphic Window gives the display of the figures as the result of the program.

 

Tuesday, October 18, 2011

MATLAB Programs


GENERATION OF SIMPLE SIGNALS



%GENERATION OF SIMPLE SIGNALS


clc;
clear all;
close all;
%Unit Impulse Signal
t=-2:2;
y=[zeros(1,2),1, zeros(1,2)];
subplot(221);
stem(t,y);
xlabel('Time Index');
ylabel('Amplitude');
%Unit Step Sequence
n=input('Enter the
length of step sequence N = '
);
t=0:n-1;
y1=ones(1,n);
subplot(222);
stem(t,y1);
xlabel('Time Index');
ylabel('Amplitude');
%Ramp Sequence
n1=input('Enter the length of ramp sequence N = ');
t=0:n1;
subplot(223);
stem(t,t);
xlabel('Time Index');
ylabel('Amplitude');
n2=input('Enter the
length of exponential sequence N = '
);
t=0:n2;
a=input('Enter the
value of a = '
);
y2=exp(a*t);
subplot(224);
stem(t,y2);
xlabel('Time Index');
ylabel('Amplitude'); 


Enter the length of step sequence N = 8
Enter the length of ramp sequence N = 8
Enter the length of exponential sequence N = 8
Enter the value of a = -1

OUTPUT

 



AM GENERATION WITH DOUBLE SIDE BAND (DSB) AND SUPPRESSED CARRIER

%AM Wave DSB with carrier


clc;
clear all;
close all;
fc=input('Enter the carrier signal frequency in hz,fc = ');
fm=input('Enter the modulating signal frequency in hz,fm = ');
m=input('Modulation index,m= ');
n=0:0.001:1;
c=sin(2*pi*fc*n);%carrier signal
M=sin(2*pi*fm*n);% modulating signal
y=(1+m*M).*c;%AM signal
subplot(2,1,1);
plot(n,y);
ylabel('amplitude');
xlabel('time index');

%AM
with suppressed carrier
n=0:0.001:1;
c=sin(2*pi*fc*n);%carrier signal
M=sin(2*pi*fm*n);% modulating signal
y=M.*c;
subplot(2,1,2);
plot(n,y);
axis([0 1 -2 2]);
ylabel('amplitude');
xlabel('time index');



Enter the carrier signal frequency in Hz, fc = 50 
Enter the modulating signal frequency in Hz, fm = 5 
Modulating index, m = 0.5


OUTPUT



LINEAR CONVOLUTION USING BUILT IN FUNCTION




%Linear Convolution using built-in function

clc;
clear all;
close all;
x=input('Enter the input sequence x[n] = ');
lx=input('Enter the starting time index of x[n] = ');
h=input('Enter the input sequence h[n] = ');
lh=input('Enter the starting time index of h[n] = ');
y= conv(x,h);
n=lx+lh:length(y)+lx+lh-1;
stem(n,y);
ylabel('Amplitude');
xlabel('Time Index');
title('Linear Convolution');



Enter the input sequence x[n] = [1 2 3 4]
Enter the starting time index of x[n] = -2
Enter the input sequence h[n] = [3 3 4]
Enter the starting time index of h[n] = -1



SQUARE WAVE FROM SINUSOIDAL HARMONICS


%SQUARE WAVE FROM SINUSOIDAL HARMONICS

clc;
clear all;
close all;
y=0;
h=input('No of harmonics = ');
f=input('enter the frequency =');
t=0:0.005:1/f
for i=1:2:h
y= y+sin(i*2*pi*f*t)/i;
plot(t,y);
pause;
hold on;
end


No of harmonics = 20
enter the frequency =0.5








 
IMPULSE RESPONSE OF LTI SYSTEM 




%Impulse Response of LTI System

clc;
clear all;
close all;
N=input('Enter the required length of the impulse response, N = ');
b=input('Enter coeffecients of x[n], b = ')
a=input('Enter coeffecients of y[n], a = ')
x=[1, zeros(1, N-1)];
y=filter(b,a,x);
n=0:N-1;
stem(n,y);
xlabel('Time Index n');
ylabel('Amplitude');
title('Impulse response of the system');



Enter the required length of the impulse response, N = 40
Enter coeffecients of x[n], b = [ -0.8 -0.44 -0.36 -0.22]

b =

   -0.8000   -0.4400   -0.3600   -0.2200

Enter coeffecients of y[n], a = [1 0.7 -0.45 -0.6]

a =

    1.0000    0.7000   -0.4500   -0.6000