Popular Posts

Sunday, November 6, 2011

Different Types of Analysis using SPICE


The dc analysis portion of SPICE (.DC) determines the dc operating point of the circuit with inductors shorted and capacitors opened. The dc analysis options are specified on the .DC, .TF, and .OP control lines. A dc analysis is automatically performed prior to a transient analysis to determine the transient initial conditions, and prior to an ac small-signal analysis to determine the linearized, small-signal models for nonlinear devices. If requested, the dc small-signal value of a transfer function (ratio of output variable to input source), input resistance, and output resistance is also computed as a part of the dc solution. The dc analysis can also be used to generate dc transfer curves: a specified independent voltage or current source is stepped over a user-specified range and the dc output variables are stored for each sequential source value.

 .DC: DC Transfer Function

General form:
     .DC SRCNAM VSTART VSTOP VINCR [ SRC2 START2 STOP2 INCR2 ]
Examples:
     .DC VIN 0.25 5.0 0.25
     .DC VDS 0 10 .5 VGS 0 5 1
     .DC VCE 0 10 .25 IB 0 10U 1U
The inclusion of this line in an input file directs SPICE to perform a dc analysis of the circuit. The DC line defines the dc transfer curve source and sweep limits (again with capacitors open and inductors shorted). SRCNAM is the name of an independent voltage or current source. VSTART, VSTOP, and VINCR are the starting, final, and incrementing values respectively. The first example causes the value of the voltage source VIN to be swept from 0.25 volts to 5.0 volts in increments of 0.25 volts. A second source (SRC2) may optionally be specified with associated sweep parameters. In this case, the first source is swept over its range for each value of the second source. This option can be useful for obtaining semiconductor device output characteristics.

The ac small-signal portion of SPICE (.AC) computes the ac output variables as a function of frequency. The program first computes the dc operating point of the circuit and determines linearized, small-signal models for all of the nonlinear devices in the circuit. The resultant linear circuit is then analyzed over a user-specified range of frequencies. The desired output of an ac small- signal analysis is usually a transfer function (voltage gain, transimpedance, etc). If the circuit has only one ac input, it is convenient to set that input to unity and zero phase, so that output variables have the same value as the transfer function of the output variable with respect to the input.

.AC: Small-Signal AC Analysis

General form:
     .AC DEC ND FSTART FSTOP
     .AC OCT NO FSTART FSTOP
     .AC LIN NP FSTART FSTOP
Examples:
     .AC DEC 10 1 10K
     .AC DEC 10 1K 100MEG
     .AC LIN 100 1 100HZ
DEC stands for decade variation, and ND is the number of points per decade. OCT stands for octave variation, and NO is the number of points per octave. LIN stands for linear variation, and NP is the number of points. FSTART is the starting frequency, and FSTOP is the final frequency. If this line is included in the input file, SPICE performs an AC analysis of the circuit over the specified frequency range. Note that in order for this analysis to be meaningful, at least one independent source must have been specified with an ac value.
The transient analysis portion of SPICE (.TRAN) computes the transient output variables as a function of time over a user-specified time interval. The initial conditions are automatically determined by a dc analysis. All sources which are not time dependent (for example, power supplies) are set to their dc value. The transient time interval is specified on a .TRAN control line.

.TRAN: Transient Analysis

General form:
     .TRAN TSTEP TSTOP [ [ TSTART ] TMAX ]
Examples:
     .TRAN 1NS 100NS
     .TRAN 1NS 1000NS 500NS
     .TRAN 10NS 1US
The inclusion of this line in an input file directs SPICE to perfom a transient analysis of the circuit. TSTEP is the printing or plotting increment for line-printer output. For use with the post-processor, TSTEP is the suggested computing increment. TSTOP is the final time, and TSTART is the initial time. If TSTART is omitted, it is assumed to be zero. The transient analysis always begins at time zero. In the interval <zero, TSTART>, the circuit is analyzed (to reach a steady state), but no outputs are stored. In the interval <TSTART, TSTOP>, the circuit is analyzed and outputs are stored. TMAX is the maximum step-size that SPICE uses; for default, the program chooses either TSTEP or (TSTOP-TSTART)/50.0, whichever is smaller. TMAX is useful when one wishes to guarantee a computing interval which is smaller than the printer increment, TSTEP.
[Note: The original Berkeley code had a bug so it actually chooses the larger of either TSTEP or (TSTOP-TSTART)/50.0 so I suggest you set TMAX explicitly unless you have a patched version. Another reason for doing this is that certain circuits, particularly those involving sinusoidal oscillation, fool the integrator into increasing the timestep too much. For circuits which use short pulses, TMAX should be no more than about 50 times the shortest feature of interest. There is also an internal lower limit 1e-9*TMAX imposed on TSTEP and non-convergent circuits may give 'Timestep too short' messages indicating this limit has been hit. CDHW.]
UIC (use initial conditions) is an optional keyword which indicates that the user does not want SPICE to solve for the quiescent operating point before beginning the transient analysis. If this keyword is specified, SPICE uses the values specified using IC=... on the various elements as the initial transient condition and proceeds with the analysis. If the .IC control line has been specified, then the node voltages on the .IC line are used to compute the initial conditions for the devices. Look at the description on the .IC control line for its interpretation when UIC is not specified

The pole-zero analysis portion of SPICE (.PZ) computes the poles and/or zeros in the small-signal ac transfer function. The program first computes the dc operating point and then determines the linearized, small-signal models for all the nonlinear devices in the circuit. This circuit is then used to find the poles and zeros of the transfer function.
Two types of transfer functions are allowed : one of the form (output voltage)/(input voltage) and the other of the form (output voltage)/(input current). These two types of transfer functions cover all the cases and one can find the poles/zeros of functions like input/output impedance and voltage gain. The input and output ports are specified as two pairs of nodes.
The pole-zero analysis works with resistors, capacitors, inductors, linear-controlled sources, independent sources, BJTs, MOSFETs, JFETs and diodes. Transmission lines are not supported.
The method used in the analysis is a sub-optimal numerical search. For large circuits it may take a considerable time or fail to find all poles and zeros. For some circuits, the method becomes "lost" and finds an excessive number of poles or zeros.

.PZ: Pole-Zero Analysis

General form:
     .PZ NODE1 NODE2 NODE3 NODE4 { CUR | VOL } { POL | ZER | PZ }
Examples:
     .PZ 1 0 3 0 CUR POL
     .PZ 2 3 5 0 VOL ZER
     .PZ 4 1 4 1 CUR PZ
The inclusion of this line in an input file directs SPICE to perform a pole-zero analysis. CUR stands for a transfer function of the type (output voltage)/(input current) while VOL stands for a transfer function of the type (output voltage)/(input voltage). POL stands for pole analysis only, ZER for zero analysis only and PZ for both. This feature is provided mainly because if there is a nonconvergence in finding poles or zeros, then, at least the other can be found. Finally, NODE1 and NODE2 are the two input nodes and NODE3 and NODE4 are the two output nodes. Thus, there is complete freedom regarding the output and input ports and the type of transfer function.
In interactive mode, the command syntax is the same except that the first field is PZ instead of .PZ. To print the results, one should use the command 'print all'.

The distortion analysis portion of SPICE (.DISTO) computes steady-state harmonic and intermodulation products for small input signal magnitudes. If signals of a single frequency are specified as the input to the circuit, the complex values of the second and third harmonics are determined at every point in the circuit. If there are signals of two frequencies input to the circuit, the analysis finds out the complex values of the circuit variables at the sum and difference of the input frequencies, and at the difference of the smaller frequency from the second harmonic of the larger frequency.
Distortion analysis is supported for the following nonlinear devices: diodes (DIO), BJT, JFET, MOSFETs (levels 1, 2, 3, 4/BSIM1, 5/BSIM2, and 6) and MESFETS. All linear devices are automatically supported by distortion analysis. If there are switches present in the circuit, the analysis continues to be accurate provided the switches do not change state under the small excitations used for distortion calculations.
Spice3 will calculate (.SENS) either the DC operating-point sensitivity or the AC small-signal sensitivity of an output variable with respect to all circuit variables, including model parameters. Spice calculates the difference in an output variable (either a node voltage or a branch current) by perturbing each parameter of each device independently. Since the method is a numerical approximation, the results may demonstrate second order affects in highly sensitive parameters, or may fail to show very low but non-zero sensitivity. Further, since each variable is perturb by a small fraction of its value, zero-valued parameters are not analyized (this has the benefit of reducing what is usually a very large amount of data).
The noise analysis portion of SPICE (.NOISE) does analysis device-generated noise for the given circuit. When provided with an input source and an output port, the analysis calculates the noise contributions of each device (and each noise generator within the device) to the output port voltage. It also calculates the input noise to the circuit, equivalent to the output noise referred to the specified input source. This is done for every frequency point in a specified range - the calculated value of the noise corresponds to the spectral density of the circuit variable viewed as a stationary gaussian stochastic process.
After calculating the spectral densities, noise analysis integrates these values over the specified frequency range to arrive at the total noise voltage/current (over this frequency range). This calculated value corresponds to the variance of the circuit variable viewed as a stationary gaussian process.

.NOISE: Noise Analysis

General form:
     .NOISE V(OUTPUT [ , REF ] ) SRC [ DEC | LIN | OCT ] PTS FSTART FSTOP
     + [ PTS_PER_SUMMARY ]
Examples:
     .NOISE V(5) VIN DEC 10 1kHZ 100Mhz
     .NOISE V(5,3) V1 OCT 8 1.0 1.0e6 1
The Noise line does a noise analysis of the circuit. OUTPUT is the node at which the total output noise is desired; if REF is specified, then the noise voltage V(OUTPUT) - V(REF) is calculated. By default, REF is assumed to be ground. SRC is the name of an independent source to which input noise is referred. PTS, FSTART and FSTOP are .AC type parameters that specify the frequency range over which plots are desired. PTS_PER_SUMMARY is an optional integer; if specified, the noise contributions of each noise generator is produced every PTS_PER_SUMMARY frequency points.
The .NOISE control line produces two plots - one for the Noise Spectral Density curves and one for the total Integrated Noise over the specified frequency range. All noise voltages/currents are in squared units (V2/Hz and A2/Hz for spectral density, V2 and A2 for integrated noise).

All input data for SPICE is assumed to have been measured at a nominal temperature of 27°C, which can be changed by use of the TNOM parameter on the .OPTIONS control line. This value can further be overridden for any device which models temperature effects by specifying the TNOM parameter on the model itself. The circuit simulation is performed at a temperature of 27°C, unless overridden by a TEMP parameter on the .OPTIONS control line. Individual instances may further override the circuit temperature through the specification of a TEMP parameter on the instance.
Temperature dependent support is provided for resistors, diodes, JFETs, BJTs, and level 1, 2, and 3 MOSFETs. BSIM (levels 4 and 5) MOSFETs have an alternate temperature dependency scheme which adjusts all of the model parameters before input to SPICE. For details of the BSIM temperature adjustment.
Temperature appears explicitly in the exponential terms of the BJT and diode model equations. In addition, saturation currents have a built-in temperature dependence. The temperature dependence of the saturation current in the BJT models is determined by:
                              XTI
                          |T |        | E q(T  T )|
                            1            g   1  0
          I (T ) = I (T ) |--|     exp|-----------|
           S  1     S  0
                          |T |        |k (T  - T )|
                            0              1    0
where k is Boltzmann's constant, q is the electronic charge, Eg is the energy gap which is a model parameter, and XTI is the saturation current temperature exponent (also a model parameter, and usually equal to 3).
The temperature dependence of forward and reverse beta is according to the formula:
                                      XTB
                                  |T |
                                    1
                    B(T ) = B(T ) |--|
                       1       0
                                  |T |
                                    0
where T1 and TT0 are in kelvin, and XTB is a user-supplied model parameter. Temperature effects on beta are carried out by appropriate adjustment to the values of BF, ISE, BR , and ISC (spice model parameters BF, ISE, BR, and ISC, respectively).
Temperature dependence of the saturation current in the junction diode model is determined by:
                             XTI
                             ---
                              N
                         |T |        |  E q(T  T ) |
                           1             g   1  0
         I (T ) = I (T ) |--|     exp|-------------|
          S  1     S  0
                         |T |        |N k (T  - T )|
                           0                1    0
where N is the emission coefficient, which is a model parameter, and the other symbols have the same meaning as above. Note that for Schottky barrier diodes, the value of the saturation current temperature exponent, XTI, is usually 2.
Temperature appears explicitly in the value of junction potential, U (in spice PHI), for all the device models. The temperature dependence is determined by:
                                   | N N   |
                                      a d
                          kT       |------ |
                   U(T) = --  log        2
                           q     e |N (T)  |
                                     i
where k is Boltzmann's constant, q is the electronic charge, Na is the acceptor impurity density, Nd is the donor impurity density, Ni is the intrinsic carrier concentration, and Eg is the energy gap.
Temperature appears explicitly in the value of surface mobility, M0 (or UO), for the MOSFET model. The temperature dependence is determined by:
                                M (T )
                                 0  0
                       M (T) = -------
                        0          1.5
                               | T|
                               |--|
                               |T |
                                 0
The effects of temperature on resistors is modeled by the formula:
R(T) = R(T0 ) [1 + TC1 (T - T0 ) + TC2 (T - T0)2 ]
where T is the circuit temperature, T0 is the nominal temperature, and TC1 and TC2 are the first- and second-order temperature coefficients.

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