Sunday, 17 September 2017

MATLAB Program for FIR Bandpass Filter

function fir1() is used for the design of FIR filter.You can refer the MATLAB product help for the syntax of these functions. The program for an FIR bandpass filter is given below.

% Program to design FIR bandpass filter .

close all;
clear all;

fp=input('Enter the start and stop frequency of the pass band');
f=input(' Enter the sampling frequency');
n=input(' Enter the order of the filter');

% Normalizing the frequencies

wp=(2/f).*fp;

%Calculation of filter coefficients

b=fir1(n,wp);

%Plotting the filter response

freqz(b,1,500,f);
TITLE('Magnitude and Phase response');


%output
%Enter the start and stop frequency of the pass band[1000 2000]
%Enter the sampling frequency 5000
%Enter the order of the filter 50

MATLAB Program for IIR Chebyschev Type - II Filter

The function cheb2ord() is used to find the filter order and center frequency and cheby2() is used to find the filter coefficients.A low pass filter is implimented.


% Program to design IIR Chebyschev type - II filter


clear all;
close all;


fp=input('Enter the pass band frequency fp   = ');
fs=input('Enter the stop band frequency fs   = ');
rp=input('Enter the pass band attenuation rp = ');
rs=input('Enter the stop band attenuation rs = ');
f=input ('Enter the sampling frequency f     = ');


wp=2*fp/f;
ws=2*fs/f;


[n,wn]=cheb2ord(wp,ws,rp,rs);


[b,a]=cheby2(n,rs,wn,'low');


freqz(b,a,500,f);
TITLE ('Magnitude and phase respose of the IIR Chebyschev type - II filter');


%output
%Enter the pass band frequency fp   = 1000
%Enter the stop band frequency fs   = 1200
%Enter the pass band attenuation rp = .2
%Enter the stop band attenuation rs = 45
%Enter the sampling frequency f     = 3000

MATLAB Program for IIR Chebyschev Type - I Filter

The function cheb1ord() is used to find the filter order and center frequency and cheby1() is used to find the filter coefficients.A low pass filter is implimented.

% Program to design IIR Chebyschev type - I filter


clear all;
close all;


fp=input('Enter the pass band frequency fp   = ');
fs=input('Enter the stop band frequency fs   = ');
rp=input('Enter the pass band attenuation rp = ');
rs=input('Enter the stop band attenuation rs = ');
f=input ('Enter the sampling frequency f     = ');


wp=2*fp/f;
ws=2*fs/f;


[n,wn]=cheb1ord(wp,ws,rp,rs);


[b,a]=cheby1(n,rp,wn,'low');


freqz(b,a,500,f);
TITLE ('Magnitude and phase respose of the IIR Chebyschev type - I filter');


%output
%Enter the pass band frequency fp   = 1000
%Enter the stop band frequency fs   = 1200
%Enter the pass band attenuation rp = .2
%Enter the stop band attenuation rs = 45
%Enter the sampling frequency f     = 3000


MATLAB Program for IIR Butterworth Filter

The function buttord(), is used to find the filter order and center frequency . Function butter() is used to find the filter coefficients.A low pass filter is implemented.


%Program to design an IIR Butterworth filter


clear all;
close all;
fp=input('Enter the pass band frequency fp   = ');
fs=input('Enter the stop band frequency fs   = ');
rp=input('Enter the pass band attenuation rp = ');
rs=input('Enter the stop band attenuation rs = ');
f=input ('Enter the sampling frequency f     = ');


wp=2*fp/f;
ws=2*fs/f;


[n,wn]=buttord(wp,ws,rp,rs);


[b,a]=butter(n,wn,'low');


freqz(b,a,500,f);
TITLE ('Magnitude and phase respose of the IIR butterworth filter');


%output
%Enter the pass band frequency fp   = 1000
%Enter the stop band frequency fs   = 1200
%Enter the pass band attenuation rp = .2
%Enter the stop band attenuation rs = 45
%Enter the sampling frequency f     = 3000


MATLAB Program for FIR Filter Using Window

Popular window coefficients.
  1. hann() - for hanning window
  2. hamming() - for hamming window
  3. blackman() - for blackman window
  4. kaiser() - for kaiser window
% Program to design a FIR filter using windows.

close all;
clear all;

fp=input('Enter the pass band frequency');
fs=input('Enter the stop band frequency');
rp=input(' Enter the pass band attenuation');
rs=input('Enter the stop band attenuation');
f=input(' Enter the sampling frequency');

%Calculating filter order

num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n=ceil(num/dem);
n=abs(n);

% Normalizing the frequencies

wp=2*fp/f;
ws=2*fs/f;
wn=(ws+wp)/2;

%Adjusting the filter order. The order of window must be an odd number 
%and the order of filter must be one less than that of the window 

if (rem(n,2)==0)
    m=n+1;
else
        m=n;
        n=n-1;
end

%Window sequence calculation

w=hann(m);

%Calculation of filter coefficients

b=fir1(n,wn,'low',w);

%Plotting the filter response

freqz(b,1,500,3000);
TITLE('Magnitude and Phase response');


Output:
%output
%Enter the pass band frequency1000
%Enter the stop band frequency1200
%Enter the pass band attenuation.2
%Enter the stop band attenuation45
%Enter the sampling frequency3000


You can change this lowpass filter to high pass filter by changing the option 'low' to 
'high' in the fir1() function. The output is shown below.



%output
%Enter the pass band frequency1200
%Enter the stop band frequency1000
%Enter the pass band attenuation.2
%Enter the stop band attenuation45
%Enter the sampling frequency3000




Saturday, 20 February 2016

Matlab rogram for TDM

Time Division Multiplexing (TDM)

A multiplexing technique which processes information of different transmitters successively in defined time segments for transmission over one channel.
It can be of two types:
1.Asynchronous Time Division Multiplexing
2.Synchronous Time Division Multiplexing

A simple MATLAB program for TDM 

clc;
 
clearll;
 
closeall;
 
x=0:.5:4*pi;
 
sig1=8*sin(x);
 
l=length(sig1);
 
sig2=8*triang(l);
 
subplot(221)
 
plot(sig1);
 
title('Sinosoidal Signal');
 
ylabel('Amp---------->');
 
xlabel('time----------->');
 
subplot(222);
 
plot(sig2)
 
title('trangular Signal');
 
ylabel('Amp---------->');
 
xlabel('time----------->');
 
subplot(223)
 
stem(sig1);
 
title('Sinosoidal Signal');
 
ylabel('Amp---------->');
 
xlabel('time----------->');
 
subplot(224);
 
stem(sig2)
 
title('trangular Signal');
 
ylabel('Amp---------->');
 
xlabel('time----------->');
 
l1=length(sig1);
 
l2=length(sig2);
 
for i=1:l2
 
sig(1,i)=sig1(i);
 
sig(2,i)=sig2(i);
 
end
 
tdmsig=reshape(sig,1,2*l1);
 
figure
 
stem(tdmsig);
 
title('Tdm Signal')
 
ylabel('Amp---------->');
 
xlabel('time----------->');
 
demux=reshape(tdmsig,2,l2);
 
for i=1:l1
 
sig3(i)=demux(1,i);
 
sig4(i)=demux(2,i);
 
end
 
figure
 
subplot(2,1,1)
 
plot(sig3)
 
title('Recovered Sinosoidal Signal');
 
ylabel('Amp---------->');
 
xlabel('time----------->');
 
subplot(2,1,2);
 
plot(sig4);
 
title('Recovered Triangular Signal');
 
ylabel('Amp---------->');
 

Delta Modulation using Simulink

Delta Modulation:

  1. Next form of pulse modulation.
  2. Transmits information only to indicate whether the analog signal that is being encoded goes up or goes down.
  3. The Encoder Outputs are highs or lows that “instruct” whether to go up or down, respectively.
  4. DM takes advantage of the fact that voice signals do not change abruptly.
  5. The analog signal is quantized by a one-bit ADC (a comparator implemented as a comparator). 
  6. The comparator output is converted back to an analog signal with a 1-bit DAC, and subtracted from the input after passing through an integrator.
  7. The shape of the analog signal is transmitted as follows: a "1" indicates that a positive excursion has occurred since the last sample, and a "0" indicates that a negative excursion has occurred since the last sample.


Generation of Delta modulated signal using Simulink in MATLAB