--------------------------------------------------------------
1) Basic Operations
--------------------------------------------------------------
t=input('Enter the length of maxm. time ');
n=0:t-1;
y=ones(1,t);
subplot(4,4,1);
plot(n,y);
title('unit step x1(t)');
z=ones(1,t);
subplot(4,4,5);
plot(n,z);
title('unit step x2(t)');
w=y+z;
subplot(4,4,9);
plot(n,w);
title('Addition of x1 and x2');
c=y-z;
subplot(4,4,13);
plot(n,c);
title('Subtraction of x1 and x2');
d=y*2;
subplot(4,4,2);
plot(n,d);
title('Multiplication by factor 2 to x1');
e=y/2;
subplot(4,4,3);
plot(n,e);
title('Divison by factor 2 to x1');
n=n/2;
subplot(4,4,4);
plot(n,z);
title('Expansion of x2 by factor 2');
n=n*2;
subplot(4,4,6);
plot(n,z);
title('compression by 2 of x2');
z=-3:t-1;
subplot(4,4,7);
plot(n,z);
title('Delayed x2 signal by 3');
n=n-3;
subplot(4,4,8);
plot(n,z);
title('Advance x2 by 3');
n=-n;
subplot(4,4,10);
plot(n,z);
title('Folded signal of x2');
--------------------------------------------------------------
2) Fourier
--------------------------------------------------------------
syms x y
f = 1/sqrt(x);
z=laplace(f, x, y);
plot(z);
1) Basic Operations
--------------------------------------------------------------
t=input('Enter the length of maxm. time ');
n=0:t-1;
y=ones(1,t);
subplot(4,4,1);
plot(n,y);
title('unit step x1(t)');
z=ones(1,t);
subplot(4,4,5);
plot(n,z);
title('unit step x2(t)');
w=y+z;
subplot(4,4,9);
plot(n,w);
title('Addition of x1 and x2');
c=y-z;
subplot(4,4,13);
plot(n,c);
title('Subtraction of x1 and x2');
d=y*2;
subplot(4,4,2);
plot(n,d);
title('Multiplication by factor 2 to x1');
e=y/2;
subplot(4,4,3);
plot(n,e);
title('Divison by factor 2 to x1');
n=n/2;
subplot(4,4,4);
plot(n,z);
title('Expansion of x2 by factor 2');
n=n*2;
subplot(4,4,6);
plot(n,z);
title('compression by 2 of x2');
z=-3:t-1;
subplot(4,4,7);
plot(n,z);
title('Delayed x2 signal by 3');
n=n-3;
subplot(4,4,8);
plot(n,z);
title('Advance x2 by 3');
n=-n;
subplot(4,4,10);
plot(n,z);
title('Folded signal of x2');
--------------------------------------------------------------
2) Fourier
--------------------------------------------------------------
syms x y
f = 1/sqrt(x);
z=laplace(f, x, y);
plot(z);
--------------------------------------------------------------
3) Convolution
--------------------------------------------------------------
t=0:0.001:6;
f=2;
x=sin(2*pi*f*t);
y=cos(2*pi*f*t);
z=conv(x,y);
plot(z);
--------------------------------------------------------------
4) Differential Sampling
--------------------------------------------------------------
F = [0 0.2500 0.5000 0.7500 1.0000];
A = [1.00 0.6667 0.3333 0 0];
Order = 511;
B1 = fir2(Order,F,A);
[Hx,W] = freqz(B1,1,8192,'whole');
Hx = [Hx(4098:end) ; Hx(1:4097)];
omega = -pi+(2*pi/8192):(2*pi)/8192:pi;
plot(omega,abs(Hx));
set(gca,'xlim',[-pi pi]);
set(gca,'xtick',[-pi -pi/2 0 pi/2 pi]);
grid on;
title('Magnitude Spectrum');
xlabel('Radians/Sample'); ylabel('Magnitude');
--------------------------------------------------------------
5) Sampling
--------------------------------------------------------------
TsSmall == 1/Fs;
tLong = 0:TsSmall:0.6-TsSmall;
yLong = 2*sin(2*pi*f_max*tLong);
if(Fs>2*f_max)
axes(handles.axes1);
N=length(yLong);
%this part of the code generates that frequency axis
if mod(N,2)==0
k=-N/2:N/2-1; % N even
else
k=-(N-1)/2:(N-1)/2; % N odd
end
T=N/Fs;
freq=k/T; %the frequency axis
X=fft(yLong)/N; % make up for the lack of 1/N in Matlab FFT
plot(freq,abs(X));
ylabel('Amplitude');
xlabel('frequency component');
title('Over Sampling')
elseif(Fs==2*f_max)
axes(handles.axes2);
N=length(yLong);
%this part of the code generates that frequency axis
if mod(N,2)==0
k=-N/2:N/2-1; % N even
else
k=-(N-1)/2:(N-1)/2; % N odd
end
T=N/Fs;
freq=k/T; %the frequency axis
X=fft(yLong)/N; % make up for the lack of 1/N in Matlab FFT
plot(freq,abs(X));
ylabel('Amplitude');
xlabel('frequency component');
title('Critical/Nyquist Sampling')
else
axes(handles.axes3);
N=length(yLong);
%this part of the code generates that frequency axis
if mod(N,2)==0
k=-N/2:N/2-1; % N even
else
k=-(N-1)/2:(N-1)/2; % N odd
end
end
T=N/Fs;
freq=k/T; %the frequency axis
X=fft(yLong)/N; % make up for the lack of 1/N in Matlab FFT
plot(freq,abs(X));
ylabel('Amplitude');
xlabel('frequency component');
title('Under Sampling')
--------------------------------------------------------------
6) Impulse
--------------------------------------------------------------
num=[0 0 0];
den=[0 -2 0];
n=9;
z=impz(num,den,n);
plot(z);
--------------------------------------------------------------
7) Impulse
--------------------------------------------------------------
clc
clear all
close all
x = [1];
y = [ -2];
n = -20:1:10;
imp = [zeros(1,20) 1 zeros(1,10)];
h = filter (x, y, imp);
plot(h);
--------------------------------------------------------------
8) Filter
--------------------------------------------------------------
clc;close all;clear all;
x=[1 2 3 4 5 6 7 8];
h=1/4*[1 1 1 1];
freqz(h)
y1=filter(h,1,x)
y2=conv(h,x,'same')
y3=cconv(h,x)
fvtool(h)
--------------------------------------------------------------
9) Jacobian
--------------------------------------------------------------
clear all; close all; clc
syms x y z r l f;
x=r*cos(l)*cos(f);
y=r*cos(l)*sin(f);
z=r*sin(l);
jacobian([x y z],[r l f])
--------------------------------------------------------------
10) Mysinc
--------------------------------------------------------------
function z= mysinc(x)
%help mysinc
if x==sym(0)
z=1;
else
z=sin(pi*x)/pi/x;
end
--------------------------------------------------------------
11) Equations
--------------------------------------------------------------
syms x y z;
eq1='2*x-3*y+4*z=5';
eq='y+4*z+x=10';
eq3='-2*z+3*x+4*y=0';
[x y z]=solve(eq1,eq2,eq3,x,y,z)
--------------------------------------------------------------
12) Not Defined
--------------------------------------------------------------
clear all; close all; clc;
syms x
limit(1/x,x,0,'left')
--------------------------------------------------------------
13) Huffman Decoding
--------------------------------------------------------------
symbols = [1:6]; % Distinct symbols that data source can produce
p = [.5 .125 .125 .125 .0625 .0625]; % Probability distribution
[dict,avglen] = huffmandict(symbols,p); % Create dictionary.
actualsig = randsrc(1,100,[symbols; p]); % Create data using p.
comp = huffmanenco(actualsig,dict); % Encode the data.
dsig = huffmandeco(comp,dict); % Decode the Huffman code.
isequal(actualsig,dsig) % Check whether the decoding is correct.
--------------------------------------------------------------
14) Fast Fourier Transform
--------------------------------------------------------------
clc;
clear all;
close all;
Fs=100;
F=5;
A=1;
n=0:99;
s=A*cos(2*pi*F/Fs*n);
s2=A*cos(2*pi*2*F/Fs*n);
Fs=fft(s);
y=fft(s+s2);
y1=fftshift(y);
n1=-Fs/2:Fs/2-1;
y2=repmat(s,[1,100]);
mesh(y2);
--------------------------------------------------------------
15) Filter-Convolution
--------------------------------------------------------------
clear all; close all; clc;
load('abcde.mat')
A=(data(:,2));
M=max(A);
plot(A,'b')
hold on;
for i=1:(length(A))
if A(i)<(0.7*M)
A(i)=0;
end
end
plot(A,'r')
hold on
mask=(1/20)*[boxcar(20)];
filtered=conv(mask,A);
plot(filtered,'g');
j=1;
for i=(3:length(filtered)-2)
if (filtered(i-2))<(filtered(i-1)) && filtered(i-1)<filtered(i)&&filtered(i+1)<filtered(i)&&filtered(i+2)<filtered(i+1)
pkx(j)=i;
pky(j)=filtered(i);
j=j+1;
end
end
plot(filtered,'y');
plot(pkx,pky,'*');
X=1:length(filtered);
fs=500;
X=X/fs;
plot(X);
for i=1:(length(pkx)-1)
dpkx(i)=pkx(i+1)-pkx(i);
end
dpkx=dpkx/fs
No comments:
Post a Comment