Showing posts with label MATLAB PROGRAMS. Show all posts
Showing posts with label MATLAB PROGRAMS. Show all posts
Monday, November 21, 2011
0
Monday, November 21, 2011
tech
Read more...
matlab program for crosscorrelation crosscorrelation using matlab
% CROSS CORRELATION
clear all;
x = input('enter first sequence x=');
h = input('enter second sequence =');
N1=length(x);
N2=length(h);
m=0:N1-1;
k=0:N2-1;
N= max(N1,N2);
x =[x zeros(1,N-N1)];
h =[h zeros(1,N-N2)];
if (N1>N2)
p=x;x=h;h=p; %for swapping since first term should be smaller so swapping smaller with biger one
end
z=x;
for i=1:N-1
for i=N-1:-1:1
x(i+1)=x(i); %rotating
end;
x(1)=0; %assigning zero
z=[z; x]; %concatenating matrices
end;
m=[z]*[h']; %cross-correlation
m=m/N;
disp(z);
disp(h);
disp(m);
stem(m);
title('cross-correlation')
xlabel('time index=');
ylabel('amplitude =');
input
enter first sequence x=[1 2 3 4 ]
enter second sequence =[1 2 3 4 5]
clear all;
x = input('enter first sequence x=');
h = input('enter second sequence =');
N1=length(x);
N2=length(h);
m=0:N1-1;
k=0:N2-1;
N= max(N1,N2);
x =[x zeros(1,N-N1)];
h =[h zeros(1,N-N2)];
if (N1>N2)
p=x;x=h;h=p; %for swapping since first term should be smaller so swapping smaller with biger one
end
z=x;
for i=1:N-1
for i=N-1:-1:1
x(i+1)=x(i); %rotating
end;
x(1)=0; %assigning zero
z=[z; x]; %concatenating matrices
end;
m=[z]*[h']; %cross-correlation
m=m/N;
disp(z);
disp(h);
disp(m);
stem(m);
title('cross-correlation')
xlabel('time index=');
ylabel('amplitude =');
input
enter first sequence x=[1 2 3 4 ]
enter second sequence =[1 2 3 4 5]
output
tags:matlab program for correlation matlab code for cross correlation
Sunday, May 1, 2011
1
Sunday, May 1, 2011
tech
Read more...
matlab program for autocorrelation matlab code for autocorrelation autocorrelation matlab code
matlab program for autocorrelation
program
clear all;
x=input('Enter the sequence');
N=length(x);
y=x;
z=x;
for i=1:N-1
for i=N-1:-1:1
x(i+1)=x(i);
end
x(1)=0;
z=[z;x];
end
m=[z]*[y'];
m=m/N;
stem(m);
disp(m);
title('Auto correlation');
xlabel('Time index');
ylabel('Amplitude');
input
enter the sequence[1 2 3 4 5]
tags:autocorrelation matlab code,matlab program for autocorrelation matlab code for autocorrelation autocorrelation matlab code autocorrelation using matlab
program
clear all;
x=input('Enter the sequence');
N=length(x);
y=x;
z=x;
for i=1:N-1
for i=N-1:-1:1
x(i+1)=x(i);
end
x(1)=0;
z=[z;x];
end
m=[z]*[y'];
m=m/N;
stem(m);
disp(m);
title('Auto correlation');
xlabel('Time index');
ylabel('Amplitude');
input
enter the sequence[1 2 3 4 5]
output
Monday, April 18, 2011
2
Monday, April 18, 2011
tech
Read more...
matlab program for circular convolution matlab code for convolution matlab code for circular convolution
circular convolution using matlab
%circular convolution
a=input('enter first sequence');
b=input('enter second sequence');
l1=length(a);
l2=length(b);
N=max(l1,l2);
a=[a zeros(N-l1)];
b=[b zeros(N-l2)];
for n=0:N-1
y(n+1)=0;
for i=0:N-1;
j=mod(n-i,N);
y(n+1)=y(n+1)+a(i+1)*b(j+1);
end
end
disp(y);
x=1:N;
stem(x,y);
input
enter first sequence[2 1 2 1]
enter second sequence[1 2 3 4]
%circular convolution
a=input('enter first sequence');
b=input('enter second sequence');
l1=length(a);
l2=length(b);
N=max(l1,l2);
a=[a zeros(N-l1)];
b=[b zeros(N-l2)];
for n=0:N-1
y(n+1)=0;
for i=0:N-1;
j=mod(n-i,N);
y(n+1)=y(n+1)+a(i+1)*b(j+1);
end
end
disp(y);
x=1:N;
stem(x,y);
input
enter first sequence[2 1 2 1]
enter second sequence[1 2 3 4]
output
tags: matlab program for circular convolution matlab code for convolution matlab code for circular convolution circular convolution using matlab
4
tech
Read more...
matlab program for linear convolution matlab code for linear convolution linear convolution using matlab program
matlab program for linear convolution
%linear convolution
a=input('enter the first sequence');
b=input('enter second sequence');
l1=length(a);
l2=length(b);
a=[a zeros(1,l2-1)];
b=[b zeros(1,l1-1)];
N=l1+l2-1;
for k=1:N
s=0;
for i=1:k
s=s+(a(i)*b(k+1-i));
end
c(k)=s;
end
l=length(c);
n=1:1:l;
disp(c);
stem(n,c);
xlabel('time');
ylabel('amplitude');
title('linear convolution');
input
enter the first sequence[2 1 1]
enter second sequence[1 2 4]
%linear convolution
a=input('enter the first sequence');
b=input('enter second sequence');
l1=length(a);
l2=length(b);
a=[a zeros(1,l2-1)];
b=[b zeros(1,l1-1)];
N=l1+l2-1;
for k=1:N
s=0;
for i=1:k
s=s+(a(i)*b(k+1-i));
end
c(k)=s;
end
l=length(c);
n=1:1:l;
disp(c);
stem(n,c);
xlabel('time');
ylabel('amplitude');
title('linear convolution');
input
enter the first sequence[2 1 1]
enter second sequence[1 2 4]
output
tags:matlab program for linear convolution matlab program for convolution matlab code for linear convolution linear convolution using matlab program
Wednesday, April 13, 2011
0
Wednesday, April 13, 2011
tech
Read more...
matlab program for fir hpf filter high pass filter fir design using matlab
matlab program for fir high pass filter
clear all;
w=input('enter cut off fre in hertz');
N=input('no of samples');
wc=2*pi*w;
alpha=(N-1)/2;
eps=.001;
for n=0:1:N-1
hd(n+1)=(sin(pi*(n-alpha+eps))-sin(wc*(n-alpha+eps)))/(pi*(n-alpha+eps));
end
wr=ones(1,N);
hn=hd.*wr;
w=0:.01:pi;
h=freqz(hn,1,w);
%absolute value plotting
subplot(131);
plot(w/pi,abs(h),'r');
grid;
xlabel('normalised freq');
ylabel('mag');
title('abs');
subplot(132);
plot(w/pi,angle(h),'g');
xlabel('normalised freq');
ylabel('mag');
title('angle');
%log magn plot
subplot(133);
plot(w/pi,20*log10(h),'b');
grid;
xlabel('normalised freq');
ylabel('log mag');
title('log mag');
output
enter frequency .25
enter number of samples 25
tags:fir hpf implementation using matlab matlab program for fir high pass filter design
clear all;
w=input('enter cut off fre in hertz');
N=input('no of samples');
wc=2*pi*w;
alpha=(N-1)/2;
eps=.001;
for n=0:1:N-1
hd(n+1)=(sin(pi*(n-alpha+eps))-sin(wc*(n-alpha+eps)))/(pi*(n-alpha+eps));
end
wr=ones(1,N);
hn=hd.*wr;
w=0:.01:pi;
h=freqz(hn,1,w);
%absolute value plotting
subplot(131);
plot(w/pi,abs(h),'r');
grid;
xlabel('normalised freq');
ylabel('mag');
title('abs');
subplot(132);
plot(w/pi,angle(h),'g');
xlabel('normalised freq');
ylabel('mag');
title('angle');
%log magn plot
subplot(133);
plot(w/pi,20*log10(h),'b');
grid;
xlabel('normalised freq');
ylabel('log mag');
title('log mag');
output
enter frequency .25
enter number of samples 25
tags:fir hpf implementation using matlab matlab program for fir high pass filter design
1
tech
Read more...
matlab program for fir filter low pass matlab program for fir low pass filter
matlab program for fir low pass filter
w=input('enter cut off frequency in hertz');
N=input('enter number of samples');
wc=2*pi*w;
alpha=(N-1)/2;
eps=.001;
for n=0:1:N-1;
hd(n+1)=sin(wc*(n-alpha+eps))/(pi*(n-alpha+eps));
end
wr=ones(1,N);
hn=hd.*wr;
w=0:.01:pi;
h=freqz(hn,1,w); %frequency response
%absolute value
subplot(131)
plot(w/pi,abs(h),'r');
grid;
xlabel('normalised frequency');
ylabel('magnitude');
title('absolute value');
%angle plotting
subplot(132)
plot(w/pi,angle(h),'g');
grid;
xlabel('normalised frequency');
ylabel('magnitude');
title('angle');
%log plotting
subplot(133)
plot(w/pi,20*log(h),'b');
grid;
xlabel('normalised frequency');
ylabel('log magnitude');
title('log magnitude');
output
enter cut off frequency .25
enter number of samples 25
w=input('enter cut off frequency in hertz');
N=input('enter number of samples');
wc=2*pi*w;
alpha=(N-1)/2;
eps=.001;
for n=0:1:N-1;
hd(n+1)=sin(wc*(n-alpha+eps))/(pi*(n-alpha+eps));
end
wr=ones(1,N);
hn=hd.*wr;
w=0:.01:pi;
h=freqz(hn,1,w); %frequency response
%absolute value
subplot(131)
plot(w/pi,abs(h),'r');
grid;
xlabel('normalised frequency');
ylabel('magnitude');
title('absolute value');
%angle plotting
subplot(132)
plot(w/pi,angle(h),'g');
grid;
xlabel('normalised frequency');
ylabel('magnitude');
title('angle');
%log plotting
subplot(133)
plot(w/pi,20*log(h),'b');
grid;
xlabel('normalised frequency');
ylabel('log magnitude');
title('log magnitude');
output
enter cut off frequency .25
enter number of samples 25
tags:fir low pass filter using matlab matlab fir lpf fir filter design using matlab matlab program for fir lpf design
Tuesday, February 22, 2011
0
Tuesday, February 22, 2011
tech
Read more...
matlab program for sampling theorem
%sampling theorm
clear all;
t=-10:.01:10; %t vector
T=8; %time period
fm=1/T; %frequency
x=cos(2*pi*fm*t); %cos wave
fs1=1.6*fm; %fs<2fm
fs2=2*fm; %fs=2fm
fs3=8*fm; %fs>2fm
n1=-4:1:4; %index vector
xn1=cos(2*pi*n1*fm/fs1);%aliasing
subplot(2,2,1);
plot(t,x);
xlabel('time in sec');
ylabel('x(t)');
title('continuous time signal');
subplot(2,2,2);
stem(n1,xn1); %aliasing discrete
hold on;
plot(n1,xn1); %aliasing cont
xlabel('n');
ylabel('x(n)');
title('discrete time s/g with fs<2fm');
n2=-5:1:5; %time index
xn2=cos(2*pi*n2*fm/fs2); %fs=2fm
subplot(2,2,3);
stem(n2,xn2); %sampling for fs=2fm
hold on;
plot(n2,xn2); %ploting fs=2fm
xlabel('n');
ylabel('x(n)');
title('discrete time s/g with fs=2fm');
n3=-20:1:20; %time index
xn3=cos(2*pi*n3*fm/fs3); %fs>2fm
subplot(2,2,4);
stem(n3,xn3); %samples for fs>2fm
hold on;
plot(n3,xn3); %ploting fs>2fm
xlabel('n');
ylabel('x(n)');
title('discrete time s/g with fs>2fm');
clear all;
t=-10:.01:10; %t vector
T=8; %time period
fm=1/T; %frequency
x=cos(2*pi*fm*t); %cos wave
fs1=1.6*fm; %fs<2fm
fs2=2*fm; %fs=2fm
fs3=8*fm; %fs>2fm
n1=-4:1:4; %index vector
xn1=cos(2*pi*n1*fm/fs1);%aliasing
subplot(2,2,1);
plot(t,x);
xlabel('time in sec');
ylabel('x(t)');
title('continuous time signal');
subplot(2,2,2);
stem(n1,xn1); %aliasing discrete
hold on;
plot(n1,xn1); %aliasing cont
xlabel('n');
ylabel('x(n)');
title('discrete time s/g with fs<2fm');
n2=-5:1:5; %time index
xn2=cos(2*pi*n2*fm/fs2); %fs=2fm
subplot(2,2,3);
stem(n2,xn2); %sampling for fs=2fm
hold on;
plot(n2,xn2); %ploting fs=2fm
xlabel('n');
ylabel('x(n)');
title('discrete time s/g with fs=2fm');
n3=-20:1:20; %time index
xn3=cos(2*pi*n3*fm/fs3); %fs>2fm
subplot(2,2,4);
stem(n3,xn3); %samples for fs>2fm
hold on;
plot(n3,xn3); %ploting fs>2fm
xlabel('n');
ylabel('x(n)');
title('discrete time s/g with fs>2fm');
output
tags:matlab program for sampling theorm sampling methods matlab sampling generation using matlab
0
tech
Read more...
matlab program for triangular wave generation|triangle wave generator using matlab
%traingular wave
a=input('enter the no of periods');
b=input('enter the amplitude');
c=input('enter the no of cycles');
%continous traingular wave
m=2*b/a; %calculation of slope
d=0;
e=a/2; % half period
p=0; %pt of each -ve slope wrt
subplot(121);
for n=1:c %no of cycles =no of loops
x=d:.01:e; %first half period
plot(x,m*(x-(n-1)*a),'r'); %positive slope
hold on
p=e+a/2;
x=e:.01:p; %second half period
plot(x,-1*m*(x-(n-1)*a)+b*2,'r');%negative slope
hold on;
d=d+a; % next +ve slope plot
e=e+a; %next -ve slope plot
end
xlabel('no of cycles');
ylabel('amplitude');
title('continous trian wave');
legend('triang wave');
grid major;
%discrite triangular wave
subplot(122);
m=2*b/a;
d=0;
e=a/2;
p=0;
for n=1:c
x=d:.1:e;
stem(x,m*(x-(n-1)*a));
hold on
p=e+a/2;
x=e:.1:p;
stem(x,-1*m*(x-(n-1)*a)+b*2);
hold on;
d=d+a;
tags:matlab program for triangular wave generation trinagle wave using matlab
a=input('enter the no of periods');
b=input('enter the amplitude');
c=input('enter the no of cycles');
%continous traingular wave
m=2*b/a; %calculation of slope
d=0;
e=a/2; % half period
p=0; %pt of each -ve slope wrt
subplot(121);
for n=1:c %no of cycles =no of loops
x=d:.01:e; %first half period
plot(x,m*(x-(n-1)*a),'r'); %positive slope
hold on
p=e+a/2;
x=e:.01:p; %second half period
plot(x,-1*m*(x-(n-1)*a)+b*2,'r');%negative slope
hold on;
d=d+a; % next +ve slope plot
e=e+a; %next -ve slope plot
end
xlabel('no of cycles');
ylabel('amplitude');
title('continous trian wave');
legend('triang wave');
grid major;
%discrite triangular wave
subplot(122);
m=2*b/a;
d=0;
e=a/2;
p=0;
for n=1:c
x=d:.1:e;
stem(x,m*(x-(n-1)*a));
hold on
p=e+a/2;
x=e:.1:p;
stem(x,-1*m*(x-(n-1)*a)+b*2);
hold on;
d=d+a;
e=e+a;
end
output
Sunday, December 5, 2010
1
Sunday, December 5, 2010
tech
Program
Read more...
Matlab Program for exponential wave
Brief Theory
In Exponential Wave, the amplitude varies exponentially with respect to time. Exponential Wave is expressed as y=a*exp(b*t) where a is a constant and b is the amplitude and t is the time. Exponential wave may be positive or negative exponential according to the amplitude. If amplitude is positive it is positive exponential and if amplitude is negative it is negative exponential. In this program I have written the program for positive and negative exponential both continuous and discrete.Program
% positive exponential continous
clc; %clear command window
t=0:.1:1;
a=input('enter the amplitude');
y=a*exp(5*t); %calculation of exponential wave
subplot(221); % breaks figure window into 2*2 matrix and select 1st axis for current plot
plot(t,y); %continous plot
title('positive exponential continous');
%positive exponential discrete
t=0:.1:1;
y=a*exp(5*t);
subplot(222); %breaks figure window into 2*1 matrix and select 2nd axis for current plot
stem(t,y); %discrete plot
xlabel('time');
ylabel('amplitude');
title('positive exponential discrete');
% negative exponential continous
t=0:.1:1;
y=a*exp(-5*t);
subplot(223);
plot(t,y);
title('negative exponential continous');
xlabel('time');
ylabel('amplitude');
%negative exponential discrete
t=0:.1:1;
y=a*exp(-5*t);
subplot(224);
stem(t,y);
title('negative exponential discrete');
xlabel('time');
ylabel('amplitude');
Monday, November 22, 2010
0
Monday, November 22, 2010
tech
matlab program for amplitude modulation
PROGRAM
% amplitude modulated wave
n=0:100;
m=0.3;fm=0.01;fc=0.1;
xm=sin(2*pi*fm*n);
xc=sin(2*pi*fc*n);
y=(1+m*xm).*xc;
stem(n,y);
grid;
xlabel('time index n');
ylabel('amplitude');
Read more...
% amplitude modulated wave
n=0:100;
m=0.3;fm=0.01;fc=0.1;
xm=sin(2*pi*fm*n);
xc=sin(2*pi*fc*n);
y=(1+m*xm).*xc;
stem(n,y);
grid;
xlabel('time index n');
ylabel('amplitude');
OUTPUT
0
tech
SINE WAVE
SOURCES->SINE WAVE
SCOPE
SIMULINK->SINK->SCOPE
CLICK ON PARAMETER ICON ON SCOPE DISPLAY
GENERAL
AXES:NO OF AXES:1
TIME RANGE:AUTO
SPECTRUM SCOPE
SIGNAL PROCESSING BLOCKSET->SINKS->SPECTRUM SCOPE
SET THE PROPERTIES AS SHOWN BELOW
CLICK ON SIMULATION ICON ON MODEL WINDOW AND OBSERVE OUTPUT
Read more...
MATLAB SIMULINK PROGRAM FOR DISCRETE SINE WAVE
SINE WAVE
SOURCES->SINE WAVE
SOURCE BLOCK PARAMETERS
SCOPE
SIMULINK->SINK->SCOPE
CLICK ON PARAMETER ICON ON SCOPE DISPLAY
GENERAL
AXES:NO OF AXES:1
TIME RANGE:AUTO
SPECTRUM SCOPE
SIGNAL PROCESSING BLOCKSET->SINKS->SPECTRUM SCOPE
SET THE PROPERTIES AS SHOWN BELOW
CLICK ON SIMULATION ICON ON MODEL WINDOW AND OBSERVE OUTPUT
Wednesday, November 17, 2010
0
Wednesday, November 17, 2010
tech
Read more...
MATLAB PROGRAM FOR Ramp continous and discrete
PROGRAM
% ramp continous and discrete
n=0:.1:10;
subplot(211); %breaks figure window into 2*1 matrix and select 1st axis for current plot
plot(n,n); %plotting the value of n against n for getting ramp signal
title('ramp continous');
xlabel('time');
ylabel('amplitude');
subplot(212); %breaks figure window into 2*1 matrix and select 2nd axis for current plot
stem(n,n); %discrete plot
title('ramp discrete');
xlabel('time');
ylabel('amplitude');
n=0:.1:10;
subplot(211); %breaks figure window into 2*1 matrix and select 1st axis for current plot
plot(n,n); %plotting the value of n against n for getting ramp signal
title('ramp continous');
xlabel('time');
ylabel('amplitude');
subplot(212); %breaks figure window into 2*1 matrix and select 2nd axis for current plot
stem(n,n); %discrete plot
title('ramp discrete');
xlabel('time');
ylabel('amplitude');
OUTPUT
0
tech
Step Wave Continous and Discrete
PROGRAM
Read more...
% step discrete and continous
n=ones(1,20); % creates an array of 20 elements with value 1;
x=0:1:19;
subplot(211); %breaks figure window into 2*1 matrix and select 1st axis for current plot
stem(x,n); %discrete step wave
title('discrete step');
xlabel('time');
ylabel('amplitude');
subplot(212); %breaks figure window into 2*1 matrix and select 2nd axis for current plot
plot(x,n); %continous sine wave
title('continous step');
xlabel('time');
ylabel('amplitude');
n=ones(1,20); % creates an array of 20 elements with value 1;
x=0:1:19;
subplot(211); %breaks figure window into 2*1 matrix and select 1st axis for current plot
stem(x,n); %discrete step wave
title('discrete step');
xlabel('time');
ylabel('amplitude');
subplot(212); %breaks figure window into 2*1 matrix and select 2nd axis for current plot
plot(x,n); %continous sine wave
title('continous step');
xlabel('time');
ylabel('amplitude');
OUTPUT
0
tech
Read more...
matlab program for Step Wave Discrete
PROGRAM
% step discrete
n=ones(1,20); % creates an array of 20 elements with value 1;
x=0:1:19;
stem(x,n); %discrete step wave
title('continous step');
xlabel('time');
ylabel('amplitude');
n=ones(1,20); % creates an array of 20 elements with value 1;
x=0:1:19;
stem(x,n); %discrete step wave
title('continous step');
xlabel('time');
ylabel('amplitude');
0
tech
Read more...
matlab program for sine wave generation(Continous and discrete)
Program
f=input('enter the frequency');
y=a*sin(2*pi*f*t); %calculation of sine wave
plot(t,y); %plot the value of t against y
title('continous sinewave'); % title of the graph
xlabel('time');
ylabel('amplitude');
% discrete sine wave
clc; %clear command window
t=0:.1:10; %create an array t starting from 0 and .1 is the increment and 10 final value
a=input('enter the amplitude');
f=input('enter the frequency');
y=a*sin(2*pi*f*t); %calculation of sine wave
stem(t,y); %discrete plot the value of t against y
title('discrete sinewave'); % title of the graph
xlabel('time');
ylabel('amplitude');
% continous sine wave
t=0:.1:10; %create an array t
a=input('enter the amplitude');t=0:.1:10; %create an array t
f=input('enter the frequency');
y=a*sin(2*pi*f*t); %calculation of sine wave
plot(t,y); %plot the value of t against y
title('continous sinewave'); % title of the graph
xlabel('time');
ylabel('amplitude');
output
% discrete sine wave
clc; %clear command window
t=0:.1:10; %create an array t starting from 0 and .1 is the increment and 10 final value
a=input('enter the amplitude');
f=input('enter the frequency');
y=a*sin(2*pi*f*t); %calculation of sine wave
stem(t,y); %discrete plot the value of t against y
title('discrete sinewave'); % title of the graph
xlabel('time');
ylabel('amplitude');
OUTPUT
Subscribe to:
Posts (Atom)