Sabtu, 10 November 2012

AM modulation illustration in Matlab

This article illustrates AM(Amplitude Modulation) in Matlab. Here the message signal m(t) consist of a rectangular pulse with +1 with 0.05 second duration and -2 amplitude pulse with duration of 0.05 second. This message signal modulates a carrier signal of 250Hz frequency to produce a DSB-AM signal. This transmitted DSB-AM signal s(t) is contaminated with noise n(t) in the channel. The received signal r(t) is thus s(t)+n(t). The SNR is assumed to be 20dB and a sampling frequency of 1KHz is used.

Running the AMmod.m matlab script provided below produces the various signal waveform and spectrum shown below. It also calculates the signal power and noise power for give SNR. The calculated signal power is 30.5mW and noise power is 0.30mW. The code uses the fftseq function that is also provided below.

For more tutorials see Video Tutorials and Matlab Tutorials

Let's Begin

The message signal is as follows-

\[m(t)=\begin{cases}+1 & 0\leq t \leq0.05\\-2 & 0.05\leq t \leq 0.1 \\ \space\space\space 0& \space\space otherwise\end{cases}\]

The waveform of this message signal is shown below-
Message Signal
Message Signal
The corresponding Spectrum of the Message is shown below-
Message Signal Spectrum
Message Signal Spectrum
 The Carrier signal is-
                      \[c(t)=cos(2\pi f_ct)\]
The Carrier waveform of frequency 250Hz is shown below-
Carrier signal waveform
Carrier signal waveform
 The noise signal waveform is shown below-
Noise
Noise
 The Noise Spectrum is shown below-
Noise Spectrum
Noise Spectrum
The DSB-AM modulated wave equation is-
                      \[s(t)=m(t)*cos(2\pi f_ct)\]
The DSB-AM waveform is shown below-
AM waveform
AM waveform
 The DSB-AM signal spectrum is shown below-
AM Frequency Spectrum
AM Frequency Spectrum
 The received signal is-
                      \[r(t)=m(t)+n(t)\]
The waveform of this noise contaminated received signal is shown below-
Noise contaminated AM modulated signal
Noise contaminated AM modulated signal
 The Spectrum of noise contaminated received signal is shown below-
Noise Contaminated Received Signal Frequency Spectrum
Noise Contaminated Received Signal Frequency Spectrum
Matlab Code

AMmod.m
----------------------------------------------------------------------------------------------------------------------
%Matlab Code for AM modulation Demonstration
to=0.05;
fs=1000;
ts=1/fs;
fc=250;                                                            %Carrier frequency
SNR_dB=20;
SNR_Linear=10^(SNR_dB/10);
df=0.3;
t=0:ts:3*to;
m=[ones(1,to/ts), -2*ones(1,to/ts), zeros(1,to/ts+1)];               %Message Signal
c=cos(2*pi*fc*t);                                                    %Carrier Signal
s=m.*c;                                                              %DSB-AM Signal
[M,m,df1]=fftseq(m,ts,df);
M=M/fs;
[C,c,df1]=fftseq(c,ts,df);
[S,s,df1]=fftseq(s,ts,df);
S=S/fs;
f=[0:df1:df1*(length(m)-1)]-fs/2;                       %frequency axis setting
message_power= (norm(m)^2)/length(m);  
signal_power=(norm(s)^2)/length(s)
noise_power=signal_power/SNR_Linear;
noise_std=sqrt(noise_power);
n=noise_std*randn(1,length(s));
[N,n,df1]=fftseq(n,ts,df);
N=N/fs;
r=s+n;
[R,r,df1]=fftseq(r,ts,df);
R=R/fs;
pause
signal_power
pause
noise_power
pause
clf
figure                       %Message
plot(t,m(1:length(t)))
xlabel('Time  ------>')
ylabel('Message Amplitude ----->')
title('The Message Signal Waveform')
pause
figure                       %Message
plot(t,c(1:length(t)))
xlabel('Time  ------>')
ylabel('Carrier Amplitude ----->')
title('The Carrier Signal Waveform')
pause
figure                        %Noise
plot(t,n(1:length(t)))
xlabel('Time  ------>')
ylabel('Noise Amplitude  ------>')
title('The Noise Signal')
pause
figure                        %AM signal
plot(t,s(1:length(t)))
xlabel('Time  ------>')
ylabel('Modulated AM Amplitude  ------>')
title('The Modulated AM signal')
pause
figure                           %Received Signal
plot(t,r(1:length(t)))
xlabel('Time  ------>')
ylabel('Received AM + Noise Amplitude  ------>')
title('Received Modulated AM + Noise signal')
pause
figure                          %Message Spectrum
plot(f,abs(fftshift(M)))
xlabel('Frequency  ------>')
ylabel('Message Amplitude  ------>')
title('Spectrum of Message')
pause
figure                            %AM signal Spectrum
plot(f,abs(fftshift(S)))
xlabel('Frequency  ------>')
ylabel('AM Signal Amplitude  ------>')
title('Spectrum of AM signal')
pause
figure                               %Noise Spectrum
plot(f,abs(fftshift(N)))
xlabel('Frequency   ------->')
ylabel('Noise Signal  ------->')
title('Spectrum of Noise')
pause
figure                              %Received Signal Spectrum
plot(f,abs(fftshift(R)))
xlabel('Frequency  ------->')
ylabel('Received AM + Noise Signal ------>')
title('Spectrum of Received AM+Noise signal')
---------------------------------------------------------------------------------------------------------------------
fftseq.m
---------------------------------------------------------------------------------------------------------------------
function [M,m,df]=fftseq(m,ts,df)
%       [M,m,df]=fftseq(m,ts,df)
%       [M,m,df]=fftseq(m,ts)
%FFTSEQ     generates M, the FFT of the sequence m.
%       The sequence is zero padded to meet the required frequency resolution df.
%       ts is the sampling interval. The output df is the final frequency resolution.
%       Output m is the zero padded version of input m. M is the FFT.
fs=1/ts;
if nargin == 2
  n1=0;
else
  n1=fs/df;
end
n2=length(m);
n=2^(max(nextpow2(n1),nextpow2(n2)));
M=fft(m,n);
m=[m,zeros(1,n-n2)];
df=fs/n;
-------------------------------------------------------------------------------------------------------------------------

See Download Matlab 2013 software

Jumat, 09 November 2012

Generation of Different Types of Signals in Matlab

In this article it is shown how to generate various important signals in Matlab. The different types of signal includes Unit Impulse, Unit Step, square, rectangle. sawtooth and others. In the study of communication system these signals appear frequently and thus knowledge about how to generate them in Matlab is important. For more see matlab tutorials and matlab software download.

Here we show the generation of following signals-
      1. Unit Impulse signal
      2. Unit Step signal
      3. Signum signal
      4. Square wave signal
      5. Rectangular wave signal
1. Unit Impulse (Delta Function):

The dirac delta function (continuous and discrete)is defined as-
\[\delta(t)=\begin{cases}1 & t = 0\\0 & otherwise\end{cases}\]
or,

\[\delta(n)=\begin{cases}1 & n = 0\\0 & otherwise\end{cases}\]
To generate a unit Impulse the following matlab statement can be used-

>> Imp=[1 zeros(1,N-1)]

Let the number of zeros be N=8, then

>> Imp=[1 zeros(1,7)];

This creates a sequence- 1 0 0 0 0 0 0 0

Applying stem function-

>> stem(Imp)

gives the following graph-
Unit Impluse Sequence
Unit Impluse Sequence
To create shifted unit impulse we can use the following matlab statement-

>> Imp_shift= [zeros(1,k-1) 1 zeros(1,N-k)]

If N=8 and k=2,

>> Imp_shift[zeros(1,1) 1 zeros(1,6)]

gives the sequence- 0 1 0 0 0 0 0 0

and,
>> stem(Imp_shift)

gives the following graph-

Shifted Unit Impulse
Shifted Unit Impulse

2. Unit Step Function

The unit step function is defined as-
 \[u(t)=\begin{cases}1 & t \geq 0\\0 & t < 0\end{cases}\]
or,
\[u(n)=\begin{cases}1 & n \geq 0\\0 & n < 0\end{cases}\]

To generate unit step sequence of length N the following matlab statement can be used-

u_step=[ones(1,N)]

let N=8, then we have

>> u_step=[ones(1,8)]

gives the sequence- 1 1 1 1 1 1 1 1

>> stem(u_step)

gives the following graph-

unit step sequence
unit step sequence
Similarly, to generate a shifted unit step sequence u(n-k)we can use the following matlab statement-

u_step_shift=[zeros(1,k) ones(1,N)]

let N=8, k=3 then,

>> u_step_shift=[zeros(1,3) ones(1,8)]

gives the sequence-  0 0 0 1 1 1 1 1 1 1 1 (that is, three Zeros followed by eight Ones)

>> stem(u_step_shift)

gives the following graph-

shifted unit step sequence
shifted unit step sequence

Another method to generate unit step function is to use the heaviside(x) matlab function. The following command and graph illustrates generation of unit step function using this heaviside(x) command.

>> n = -5:0.01:5;
>> u_step = heaviside(n);
>> plot(n,u_step)

This gives the following graph-

unit step function using heaviside function
unit step function using heaviside function

It's also easier to use heaviside function to generate a shifted unit step u(t-to) (or u(n-k)) as illustrated below-

>> n = -5:0.01:5;
>> u_step_shift = heaviside(n-2);
>> plot(n,u_step_shift)

shifted unit step function using heaviside function
shifted unit step function using heaviside function
3. Signum Function

The Signum function is defined as-

\[sign(t)=\begin{cases}1 & t< 0\\0 & t=0\\-1 & t>0\end{cases}\]
or,
\[sign(n)=\begin{cases}1 & n< 0\\0 & n=0\\-1 & n>0\end{cases}\]

To generate the sign(n) function the matlab code is-

>> n=-5:0.01:5;
>> y=sign(n);
>> plot(n,y)

The graph is shown below-

Signum function
Signum function
4. Square wave signal

Square signals can be generated using the square(t,duty) function. This function generates a periodic square wave with period T=2*pi with +ve and -ve unity peak value over the range defined by parameter t. The parameter duty defines percentage of period T over which the square wave remains positive.

Example: To generate a square wave over two period 2T=4*pi and amplitude of 2

>> t=0:0.001*pi:4*pi;
>> y=2*square(t);
>> plot(t,y)

The plot is shown below-

Square wave signal
Square wave signal
5. Rectangular wave signal

To generate rectangular signal in matlab we can use rectpuls(t) or rectpuls(t,w). rectpuls(t) function generates a continuous, aperiodic and unity height rectangular pulses. rectpuls(t,w) is same as rectpuls(t) with additional parameter w which allows to define width of the pulse.

Example:
To generate a rectangular pulse of amplitude 2, pulse width 3 we use the following commands-

>> t=-5:0.01:5;
>> y=2*rectpuls(t,3);
>> plot(t,y)
>> axis([-6 6 -0.5 3]);

The graph generated is shown below-

rectangular pulse
rectangular pulse

Kamis, 08 November 2012

Download NI Labview 2013 v.13.0 with Toolkits (x86-x64) Activated

Download NI LabVIEW 2013 for free here. LabVIEW 2013 is the latest version of National Instrument's system design software. LabVIEW gives engineers the tool needed to quickly test, prototype and solve system design problem. This reduces not only time and design effort but also provides solid reliability of designed product due to accurate real time measurement results produced by the software. Labview 2013 supports families of other CAD tools such as Xilinx ISE, ARM, Adurino etc. This software is helpful for engineers and scientist in any industry- communication system design, industrial control automation, data acquisition. See also Labview 2012 download.


LabVIEW 2013 v13 download

Free Download Link for NI Labview 2013 v.13.0 with Toolkits (x86-x64) Activated:


http://rapidgator.net/file/247cb56e68d3c181aa73b0a50feadef8/NI.Labview.2013.ACTIVATED.32_64bit.Toolkits.part1.rar.html
http://rapidgator.net/file/63ce6add0491f86b020c6da45941dbf3/NI.Labview.2013.ACTIVATED.32_64bit.Toolkits.part2.rar.html
http://rapidgator.net/file/449cfa02f184e4851b560343dbd8dbcb/NI.Labview.2013.ACTIVATED.32_64bit.Toolkits.part3.rar.html
http://rapidgator.net/file/5fa2460c731a83e2b48a2bbac2ea1b9c/NI.Labview.2013.ACTIVATED.32_64bit.Toolkits.part4.rar.html
http://rapidgator.net/file/b27aa71b06603c7105227f07ad17d47e/NI.Labview.2013.ACTIVATED.32_64bit.Toolkits.part5.rar.html
http://rapidgator.net/file/a6a8e6c5e423c0aaeb999ab6e08c9915/NI.Labview.2013.ACTIVATED.32_64bit.Toolkits.part6.rar.html
http://rapidgator.net/file/6789eb662b0496b0f72f78a5c842bddd/NI.Labview.2013.ACTIVATED.32_64bit.Toolkits.part7.rar.html
http://rapidgator.net/file/60b407b1a15f9053ee5f46eaeba4c5eb/NI.Labview.2013.ACTIVATED.32_64bit.Toolkits.part8.rar.html

or,

http://ul.to/3pv1wojg/NI.Labview.2013.ACTIVATED.32_64bit.Toolkits.part1.rar
http://ul.to/5jbr129p/NI.Labview.2013.ACTIVATED.32_64bit.Toolkits.part2.rar
http://ul.to/c8nq36vi/NI.Labview.2013.ACTIVATED.32_64bit.Toolkits.part3.rar
http://ul.to/8nrh7ors/NI.Labview.2013.ACTIVATED.32_64bit.Toolkits.part4.rar
http://ul.to/wtkjlv22/NI.Labview.2013.ACTIVATED.32_64bit.Toolkits.part5.rar
http://ul.to/0vywp1pq/NI.Labview.2013.ACTIVATED.32_64bit.Toolkits.part6.rar
http://ul.to/awb2i6qk/NI.Labview.2013.ACTIVATED.32_64bit.Toolkits.part7.rar
http://ul.to/nz5kumyv/NI.Labview.2013.ACTIVATED.32_64bit.Toolkits.part8.rar


or,

http://extabit.com/file/29g39jzu10638/NI.Labview.2013.ACTIVATED.32_64bit.Toolkits.part1.rar
http://extabit.com/file/29g39jzu1099w/NI.Labview.2013.ACTIVATED.32_64bit.Toolkits.part2.rar
http://extabit.com/file/29g39jzu102uc/NI.Labview.2013.ACTIVATED.32_64bit.Toolkits.part3.rar
http://extabit.com/file/29g39jzu102vo/NI.Labview.2013.ACTIVATED.32_64bit.Toolkits.part4.rar
http://extabit.com/file/29g39jzu0zwhw/NI.Labview.2013.ACTIVATED.32_64bit.Toolkits.part5.rar
http://extabit.com/file/29g39jzu0zmys/NI.Labview.2013.ACTIVATED.32_64bit.Toolkits.part6.rar
http://extabit.com/file/29g39jzu0zn44/NI.Labview.2013.ACTIVATED.32_64bit.Toolkits.part7.rar
http://extabit.com/file/29g39jzu0zn50/NI.Labview.2013.ACTIVATED.32_64bit.Toolkits.part8.rar

Minggu, 04 November 2012

Energy Spectral Density and Power Spectral Density

The Energy Spectral Density(ESD) and Power Spectral Density(PSD) are two important parameters in communication theory. They characterize signals as a function of frequency and also provide a convenient mathematical form that makes calculation easier. They are frequently encountered in the mathematical formula of communication theory and a firm grip on these parameter is important.

Here we investigate these parameters and obtain them using Matlab without using DFT/FFT functions that are incorporated in Matlab software. Their basic formula is converted and constructed in Matlab. The constructed Matlab code also outputs the two Spectral Density graph.

ESD(Energy Spectral Density) gives information about distribution of energy of an energy signal per unit bandwidth as a function of frequency. The unit of ESD is Joules/Hz.

PSD(Power Spectral Density) of a power signal gives information about the distribution of power per unit bandwidth as a function of frequency. The unit of PSD is Watt/Hz.

Energy Spectral Density

The formula for ESD for a energy signal x(t) is given by,

\[\psi_x(f)=|X(f)|^{2}\]
where X(f) is the Fourier transform of x(t)

This quantity can be used to find out the energy of the signal.

\[E_x=\int_{-\infty}^{\infty}x^{2}(t)dt =\int_{-\infty}^{\infty} \psi_x(f)df=\int_{-\infty}^{\infty} |X(f)|^{2}df \]
If x(t) is a real signal then X(f) is an even function of frequency and we can rewrite above equation as-
\[E_x=2\int_{0}^{\infty} \psi_x(f)df\]
Example:
This example shows how to calculate Energy Spectral Density(ESD) of energy signal.

The energy signal which will be used here is-
\[x(t)=\begin{cases}Acos(2\pi ft) & -\frac{T}{2}\leq t \leq \frac{T}{2}\\0 & elsewhere\end{cases}\]
Let A=5, f=1, T=4 then the matlab code for energy spectral density is below-

%Energy Spectral Density Calculation
t=[-2:0.001:2];
x=5*cos(2*pi*1*t);
figure
plot(t,x);
axis([-5 5 -6 6]);
xlabel('Time(t)----->')
ylabel('Amplitude ---->')
title('x(t) signal waveform')
k=0;
for f=-5:.01:5;
    k=k+1;
    X(k)=trapz(t,x.*exp(-j*2*pi*f*t));
end
ESD=X.*X;
f=-5:.01:5;
figure
plot(f,ESD)
xlabel('Frequency(f) ----->')
ylabel('Energy Spectral Density(ESD) ---->')
title('Energy Spectral Density Graph')
ESD_dB=10*log10(ESD);
figure
plot(f,ESD_dB);
xlabel('Frequency(f) ----->')
ylabel('Energy Spectral Density(ESD)in dB ---->')
title('Energy Spectral Density Graph')
The signal x(t) graph is shown below-

energy signal
Energy Signal x(t)
And the Energy Spectral Density graph is shown below-

Energy Spectral Density graph
Energy Spectral Density graph
Energy Spectral Density in dB graph is shown below-

Energy Spectral Density in dB
Energy Spectral Density in dB

Power Spectral Density

The formula for PSD for a power signal x(t) is given by,

\[ S_x(f)=\lim_{T \rightarrow \infty}\frac{1}{2T}\int_{-\infty}^{\infty} |X(f)|^{2}df \]
where X(f) is the Fourier Transform of x(t)
The power of a signal is then the integration of PSD,

\[P_x=\lim_{T \rightarrow \infty}\frac{1}{2T}\int_{-\infty}^{\infty}x^{2}(t)dt =\int_{-\infty}^{\infty} S_x(f)df=\int_{-\infty}^{\infty}\lim_{T \rightarrow \infty}\frac{1}{2T} |X(f)|^{2}df \]
Example
Let the power signal be-
 \[x(t)=Acos(2\pi ft)\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\infty\leq t \leq \infty\]
This is a power signal because the signal is periodic and has infinite energy. Since this signal has infinite energy it may not be Fourier Transformable so we take a truncated version of this signal. This truncated signal is defined below-
\[ x_T(t)=\begin{cases}Acos(2\pi ft) & -\frac{T}{2}\leq t \leq \frac{T}{2}\\0 & otherwise\end{cases}\]
Now the signal is Fourier Transformable and therefore has corresponding frequency domain description and PSD can be obtained.

Let A=5, f=1 and T=4,

The matlab code to calculate Power Spectral Density is given below-

%Power Spectral Density Calculation
t=[-2:0.001:2]; 
x=5*cos(2*pi*1*t); 
figure
plot(t,x);
axis([-5 5 -6 6]);
xlabel('Time(t)----->')
ylabel('Amplitude ---->')
title('x(t) signal waveform')
k=0;
for f=-5:.01:5;
    k=k+1;
    X(k)=trapz(t,x.*exp(-j*2*pi*f*t));
end
ESD=X.*X;
PSD=ESD./4;
f=-5:.01:5;
figure
plot(f,PSD)
xlabel('Frequency(f) ----->')
ylabel('Power Spectral Density(PSD) ---->')
title('Power Spectral Density Graph')
PSD_dB=10*log10(PSD);
figure
plot(f,PSD_dB);
xlabel('Frequency(f) ----->')
ylabel('Power Spectral Density(PSD) in dB---->')
title('Power Spectral Density Graph')

The truncated signal x(t) graph is shown below-

Truncated Power Signal
Truncated Power Signal
The Power Spectral Density graph is shown below-

Power Spectral Density Graph
Power Spectral Density Graph
The Power Spectral Density Graph in dB is shown below-

Power Spectral Density in dB
Power Spectral Density in dB
For more see Matlab tutorials and also see Matlab 2013 download blog post.

Kamis, 01 November 2012

PSK modulation Video Tutorial

The following video shows PSK modulation simulation in Cadence Orcad capture software. For the demonstration, a schematic diagram for the PSK modulation is drawn and simulated to obtain PSK waveform graph and its frequency spectrum. A ring modulator is used which is excited by the message binary sequence and impressed onto the 10KHz carrier sinusoid wave.


The PSK waveform graph and PSK freqency spectrum is shown below-

PSK Frequency Spectrum
Read more on here- PSK modulation
Also see ASK modulation video tutorial and ASK modulation

DSL or Cable Internet Connection

DSL and Cable are used for internet connection at residential homes. Many people wonder which technology is better and which one to choose. The choice between DSL or Cable internet connection depends upon the cost and quality of service in the area where client is located. Often they are equally priced. Both can offer high speed connection more than a client needs. Quality is another factor. Clients should make small survey and ask friends or neighbors about the quality of DSL and cable internet connection they are experiencing. Monthly price can be immediately found out from DSL service provider and cable providers. Then one can make a comparison to decide which one to use.

From the technology standpoint of view, both are equally advanced. DSL technology was developed from the ordinary telephone lines or PSTN network. PSTN network provider do not want to lose customers and internet was becoming popular. So they developed DSL technology to make more money and keep their customer happy. Cable comes from the TV industry. To make more money beside providing TV service and increase customer, the people from this industry developed the cable internet technology.

To use DSL or cable internet, the client needs to purchase DSL modem or Cable modem which are also equally priced. These cable and DSL modem extracts internet signal from the twisted copper pair or cable TV coaxial cable and sends to the computer or receives IP packets from computer and sends down to the twisted pair cable or coaxial cable to the internet network.

PSK modulation orcad capture tutorial

In this orcad capture tutorial, PSK modulation setup in orcad capture schematic, simulation and graph plot of PSK signal, binary message signal and the carrier signal is shown. A Ring Modulator is used for the modulation of the binary message signal with the high frequency carrier signal.

The PSK Modulation Schematic is shown below-

PSK Modulation Schematic
Fig: PSK Modulation Schematic
 In the schematic above the carrier signal is a 10KHz sinusoid with amplitude of 10V and is applied to the primary winding of the center tapped transformer which is a part of the Ring Modulator. The message signal is a binary sequence of polar type of voltage -5V and +5V, with pulse width of 2ms and period of 4ms and rise time, fall time of 0.1us. This pulsed message signal is applied to the secondary winding of the input transformer. The four diodes(D1N4934) forms the ring of the Ring Modulator. At the other end an output center tapped transformer produces PSK signal.

The binary message signal waveform, the carrier signal waveform and the resulting PSK signal waveform is shown below-
Waveform of PSK signal, binary message, carrier

 Spectrum of PSK signal is shown below-

PSK signal Spectrum
Fig: PSK signal Spectrum




 From the PSK frequency spectrum above we can see that most of the engery/power/amplitude is concentrated with 20KHs. The maximum amplitude is 750mV which occurs at 10KHz(the carrier signal frequency). Harmonics are present at 25KHz, 50KHz, 70KHz and so on.

The carrier signal frequency spectrum is shown below-
carrier signal spectrum
Fig:carrier signal spectrum
 Binary Message Signal Frequency Spectrum is shown below-
Binary Message Frequency Spectrum
Fig: Binary Message Frequency Spectrum

From the graph above we can see that most of the energy/power or amplitude of the binary message is contained in the bandwidth of 0 to 5KHz.

Also ASK modulation and ASK modulation video tutorial