Sunday, February 5, 2012

sampling using matlab

 clc
 clear all
 close all
fsm=4000
f=1
t=0:(1/fsm):1
m=sin(2*pi*f*t)
figure(1)
plot(t,m)
subplot(211)
plot(t,m)
subplot(212)
plot(m)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%% generating impulse train %%%%%%%%%%%%%%%%

fs=(100*f);
s=sin(2*pi*fs*t);
k=s;
k(k<1)=0;
sam=k;
figure
plot(s);
hold all
plot(sam,'k')

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
sample=m.*sam;
%%
figure
plot(sample)
hold all
plot(m)

pulsecode modulation using matlab


Pulse code Modulation:

                By observing the name we think this is a modulation process but in reality this a one type of A to D conversion mechanism i.e. analog to digital conversion technique. Beside this technique we have lot of methods like delta modulation, differential pulse code modulation, adaptive delta modulation, adaptive differential pulse code modulation etc in digital communications. There is always a trade of between all these methods we compare all these based on the bit rate, circuit implementation, and bandwidth. PCM uses lot of operations to convert analog signal to digital signal so the technique is complex.  At the receiver side we employ sampling, quantizing, encoding. Generally the two process named as encoding and quantizing are done in the same circuit known as analog to digital converter i.e. A to D converter. The operations done in the receiver circuit are regeneration of the received signal, decoder, and reconstruction or regeneration. All these operations are performed on the quantized samples. All these operations are done in the same circuit which is digital to analog converter i.e. D to A converter. We know that in the process of transmission we face lot of problems with atmospheric noise and distortion and filtering action of the channel. To combat all these effects we employ regenerating repeaters in the channel to reconstruct and re transmit the coded pulses which are in the way to the receiver. This is time to deal all the processes used in the PCM.  A PCM stream is a digital representation of an analog signal, in which the magnitude of the analog signal is sampled regularly at uniform intervals, with each sample being quantized to the nearest value within a range of digital steps. . This is the standard form used for digital audio in computers, CD and DVD formats. PCM has two properties namely sampling rate and bit depth we all know about sampling rate bit depth refers to the number of digital values that the each sample can take. Quantization error is the main drawback of PCM.

Sampling:

Digital communications requires sampling which is first step in all A to D converters. The sampling is done according to the Nyquist criterion. We may define the process of sampling as a band-limited signal of finite energy, which has no frequency components higher than W hertz, may be completely recovered from the knowledge of its samples taken at the rate of 2W per second. The other definition is a band-limited signal of finite energy, which has no frequency components higher than W hertz, is completely described by specifying the values of the signal at instants of time separated by 1/2W seconds. We use these to definitions at the receiver and transmitter. The sampling rate 2W is called the Nyquist rate. And its inverse is called the Nyquist interval. To make the signal as the band limited signal we incorporate the low pass filter at the beginning of the transmitter known as the anti-aliasing filter which stops or attenuates the high frequency components which lie outside the desired frequency band. Then the filtered signal is sampled at a rate higher than the Nyquist rate. A circuit known as the sample and hold circuit is used in sampling to produce the flat top sampling. Flat top sampling provides us to use simple quantizing strategy. Over sampling is used to reduce the distortion in most of the analog to digital converters.

Quantizing:

                Quantization in DSP represents the process which maps the large set values to a single value. A circuit which performs this operation is called the quantizer. This process is also introduces some errors in the signal this is called quantization error or rounding of error. This is a non linear process because this is many to one mapping function. Quantized sample has discrete nature in both time and amplitude. Quantizers are of two types namely uniform and non uniform. In uniform quantization step size is constant while in non uniform quantization step size is varied according to the amplitude of the signal. To perform non uniform quantization one needs to pass the signal into the compressor and then into the uniform quantizer. Non uniform quantization takes care of both high and small variations in the amplitude levels of the signal. we have two laws to perform the quantization they are A-law and µ-law. In the receiver we perform the inverse operation of the quantizer in this we send the received signal into the expander. The device which can perform both operations of expansion and compression is called compander.

Encoding:

                Encoding is done to transmit the signal obtained by the combined effect of the sampling and quantizing over the channel which has undesired characteristics. The signal obtained from the sampling and quantizing is not suitable for transmission as it is over a telephone line i.e. copper pair or radio or microwave link. To combat with the channel impairments we use encoding process. For this we use different types of coding techniques. Encoding process is a one to one representation. A particular arrangement of symbols used in a code to represent a single value of the discrete set is called a code word or character. In a binary code each symbol may be represented by the any two levels of presence of pulse or absence of pulse. Binary wave is robust to noise and easy to regenerate. For example in a binary code each sample is represented with the n number of bits then we can represent the total of 2n discrete levels.

 Program:               

clear all
close all
t=0:.01:3
a=sin(2*pi*t)
p=square(2*pi*10*t)
p(p<0)=0
s=a.*p
figure(1)
subplot(211)
plot(a)
xlabel('time')
ylabel('amplitude')
title('analog signal')
subplot(212)
plot(s)
xlabel('time')
ylabel('amplitude')
title('sampled signal')
n=3
y=uencode(s,n,1)
r=udecode(y,n,1)
figure(2)
subplot(211)
plot(y)
xlabel('time')
ylabel('amplitude')
title('encoded signal')
subplot(212)
plot(r)
xlabel('time')
ylabel('amplitude')
title('decoded signal')
figure(3)
plot(p)
xlabel('time')
ylabel('amplitude')
title('square signal')




"Success is a journey...not a destination".


sampling process using matlab

clear all
close all
clf
fb=1000                                     %baseband signal freqquency in hetz
tb=1/fb
fs=40000
ns=fs/fb                                    %number of samples in one period of the base band signal
t=linspace(0,.002,ns)
sq=(1+square(t))/2
asb=5*sin(2*pi*fb*t).*sq
subplot(211)
stem(t,sq)
axis([0 .002 0 1])
xlabel('time in seconds')
ylabel('amplitude in volts')
title('square wave output')
subplot(212)
stem(t,asb)
axis([0 .002 -5 5])
xlabel('time in seconds')
ylabel('amplitude in volts')
title('simulation of samplig process')

                                                                                                  





"Success often comes to those who dare to act. It seldom goes to the timid who are ever afraid of the consequences."

- Jawaharlal Nehru

on off keying/amplitude shift keying using matlab


Contents:

1. Amplitude Shift Keying
2. Algorithm
3. Matlab Commands
4. Program

Amplitude Shift Keying:

Amplitude shift keying (ASK) is a very popular modulation used in control applications. This is due to its simplicity and low implementation costs. ASK modulation has the advantage of allowing the transmitter to idle during the transmission of a bit zero. Therefore this reduces the power consumption. This disadvantage of ASK modulation arises in the presence of an undesired signal. in amplitude shift keying (ASK), as the name specifies the amplitude of the carrier signal is varied between two levels if the ASK scheme is Binary ASK. Sometimes it is more than two levels if the ASK scheme is M-array. All this is done according to the data bit to be transmitted over the noisy channel. The information is assumed to be unipolar binary data. In binary ask bit 1 is transmitted with the carrier of specified amplitude.

The bit zero is transmitted with the no carrier during the bit interval. During all the bit intervals amplitude will be changed but frequency will be kept constant. In M-array ask the amplitude levels of the carrier will change between M numbers of values. The main advantage of the ASK is power saving and simplicity in implementation. The ASK wave form can be represented mathematically as s(t)=m(t)*sin(2πfct). where s(t) is the ASK output signal, m(t) is the unipolar binary message signal to be transmitted and fc is the carrier frequency.Amplitude shift keying (ASK) is a simple and elementary form of digital modulation in which the amplitude of a carrier sinusoid is modified in a discrete manner depending on the value of a modulating symbol. This is a narrowband modulation scheme and we assume that a large number of carrier cycles are sent within a symbol interval.obvious that the information is embedded only in the peak amplitude of the modulated signal.this is described as a one type of digital amplitude modulation technique. BASK has only one basis function so this can be described as a one dimensional modulation scheme.this technique is used for telegraph services.on-off keying is not a spectrally not efficeint scheme becuse as the amplitude of the carrier changes abruptly when the data bit changes. for this reason this technique is used for transmission of data at low or modarate data rates.

Algorithm:

                The binary message to be transmitted is taken and it should be represented in a waveform so we can implement ask. Then generate the carrier it may be either sin or cos. After generating carrier multiply the carrier with the message point by point.

Matlab commands:

1.       K=Length(x)
It finds the length of the array x and returns its length as an integer.
2.       T=[0.01:0.01:k]
This specifies the time interval over which the carrier time period will be decided.
3.      Z=m.*c
This is matlab Command for point by point multiplication. Sometimes it generates errors if the m and c are not of same dimensions.
4.       M((i-1)*100+1:i*100)=a(i)
This applies the value of the message bit i during the specified interval.
5.       p = randperm(n)
Returns a random permutation of the integers 1:n.
6.      mod(1,randperm(n))
this command generates the n number of integers and all these having only two values. For example mod(1,randperm(5)) ans =[0     1     1     1     1]
gtext('string')
this command places a specified string on the figure

Program:
a=mod(1,randperm(n))
k=length(a)
t=[0.01:0.01:k]
c=sin(2*pi*5*t)
for i=1:1:k
    m((i-1)*100+1:i*100)=a(i)
end
subplot(221)
plot(m)
xlabel('time')
ylabel('amplitude')
title('massage signal')
subplot(222)
plot(c)
xlabel('time')
ylabel('amplitude')
title('carrier signal')
z=c.*m
subplot(223)
plot(z)
xlabel('time')
ylabel('amplitude')
title('amplitude shift keying')




you may Like                              
Go for generation of                     

You may interested in 1. Phase Shift Keying             go for     
2. Frequency Shift Keying      go for     
3. Hybrid Shift Keying            go for     

                                                           




"Success is a science; if you have the conditions, you get the result."


                                                      -Oscar Wilde                                                 



                                                      


DC motor control with Pulse Width Modulation Part 1

DC Motor intro DC motor is a device which converts electrical energy into kinetic energy. It converts the DC power into movement. The typica...