Generowanie lab1
N=100;
%czas
c=50;
%przesuniecie
b=20;
%szerokosc
z = zeros(1,N);
z(1,(c-(b/2)):(b/2+c -1)) = ones(1,20);
figure(1);
plot(z,
'-bh'
);
f=2
%czestotliwosc
fp=1000
%czestotliwosc probkowania
Td=2
%czas probkowania
t = [0:1/fp:Td];
x = sin(2*pi*f*t);
plot(x,
'-g.'
);
f=10
%czestotliwosc
fp=100
%czestotliwosc probkowania
N=100
%liczba próbek
T=1/f
%0.1
Tp=1/fp
%0.01
%x=[0:0.01:Tp*N]
x=[0:N-1]*Tp
y=sin(2*pi*f*x)
plot(x,y,
'-b.'
);
N=200;
f0=50;
fp=10000;
p0=0;
sz=50/0.01;
k=2*pi*sz
n=0:N-1;
x=sin((2.*pi.*f0.*n)/fp+(k.*n.*n)/(2.*fp.*fp)+p0);
plot(n,x);
N = 800;
f0=100;
%Hz
df=50;
% hz
fm = 20;
% Hz
fp = 10000;
%Hz
p0=0;
w0 = 2*pi*f0;
dw = 2*pi*df;
wm= 2*pi*fm
n=0:N-1;
x=sin((2.*pi.*f0.*n)/fp-(dw/wm).*cos((wm.*n)/fp)+dw/wm+p0)
plot(n,x)
f=10;
T=1;
Td=2;
fp=100;
N=Td*fp;
a=1;
n=0:N-1;
t=0:1/fp:Td-1/fp;
x=a.*exp(-(n/fp)/T).*sin(2.*pi.*f.*n/fp)
s=a.*(1-t/T)
n=n/fp;
hold
on
;
plot(n,x)
plot(t,s,
'r'
)
Szereg Foureira
clc;
clear all;
close all;
T=1 % s
dt=1e-3;
t=0:dt:T;
n=2;
% 1
y1=1/sqrt(T)
subplot(4,1,1),plot(t,y1);
for n=1:3
y2=sqrt(2/T)*cos((2*pi/T)*n*t);
y3=sqrt(2/T)*sin((2*pi/T)*n*t);
subplot(4,1,2),plot(t,y2)
hold on
subplot(4,1,3),plot(t,y3)
hold on
end
for n=-2:1:2
% 2
y4=(1/sqrt(T))*exp((2*pi/T)*n*t);
subplot(4,1,4),plot(t,y4)
hold on
end
2.
%zadanie 2 szeregi fouriera
clear
all
close
all
;
clc;
N= 13;
T = 4;
x=0;
XM=[];
dt=1e-3;
%g = -N:N;
t=0:dt:T;
for
n = -N:N
if
n == 0
Xn = 0.5;
else
Xn = ((-1)^n-1)/(-j*2*pi*n);
end
XM=[XM Xn];
x=x+Xn*exp(j*2*pi*n*t/T);
end
ind = find(x>0.5);
xr = zeros(size(x));
xr(ind) = 1;
%m = 0:N;
figure(1)
plot(t,real(x));
hold
on
plot(t,xr,
'-r'
);
figure(2)
stem(abs(XM));
error = sum((xr - x).^2)
%xwzor = (ones(1:(N/2)) zeros((N/2):N);
%figure(3)
%plot(t,xr);
Para etry syg ału
clear
all
close
all
clc
N=100;
k=[0:2*N-1]
t=[0:0.01:1]
xa=[1,2,3,0,0];
ya=[4,1,1,0,0];
xb=[zeros(1,10/2) ones(1,10/2)];
xc=randn(1,100)
xda=sin(2*pi*5*t);
xdb=sin(2*pi*5*t)+(1/2)*sin(2*pi*10*t)+(1/4)*sin(2*pi*30*t);
Rxya=sum(xa.*ya);
korb=xcorr(xb);
% Rxyb=sum(xa.*ya)
subplot(6,2,1); plot(korb);
ind=0;
for
k=-N+1:N-1
ind=ind+1; Rxy(ind)=0
for
n=1:N
if
(n-k)>0 && (n-k)<=N
Rxy(ind)=Rxy(ind)+xa(n)*ya(n-k)
end
end
end
1.
clear
all
close
all
clc
N=100
n=[0:N-1]
c=50
b=20
xa = [zeros(1,N/2) ones(1,N/2)];
xb=sin((2*pi/N)*n)
xc=randn(1,N)
subplot(3,1,1);
plot(xa);
subplot(3,1,2);
plot(xb);
subplot(3,1,3);
plot(xc);
asred=sum(xa)/N
asrednia=mean(xa)
awa=(1/(N-1))*sum((xa-asred).^2)
awar=var(xa)
aodch=sqrt(awar)
aodchylenie=std(xa)
bsred=sum(xb)/length(xb)
bsrednia=mean(xb)
bwa=(1/(N-1))*sum((xb-bsred).^2)
bwar=var(xb)
bodch=sqrt(bwar)
bodchylenie=std(xb)
csred=sum(xc)/length(xc)
csrednia=mean(xc)
cwa=(1/(N-1))*sum((xc-csred).^2)
cwar=var(xc)
codch=sqrt(cwar)
codchylenie=std(xc)
Syg ały dyskret e
1.
function y = splot_labb(x,h)
Nx=length(x);
Nh=length(h);
for n=1:Nx+Nh-1
y(n)=0;
for k=1:Nh
if (n-k+1)>=1 && (n-k+1)<=Nx
y(n)=y(n)+(h(k)*x(n-k+1));
end
end
end
end
%TS lab Układy dyskret e lti zad
clc ;
clear all;
close all;
x = [1, 2, 3];
h = [1, 1, 1, 1];
v = splot_labb(x,h);
g = filter(h,1,x);
d = conv(x,h);
2.
%TS lab Układy dyskret e lti zad
clc ;
clear
all
;
close
all
;
N= 10;
wg = pi/4;
n = -10:10;
for
i=1:(2*N-1)
for
n =-N:N
if
n == 0 H(i) = wg/pi;
else
H(i) = sin(wg*n)/(pi*n);
end
%h(n) = 1/(2*pi)*H(exp(j*w)*exp(j*w*n);
end
end
for
i = 1:length(n)
%for n = -10:10;
n = i-N-1;
if
n == 0
else
H(i) = sin(wg*n)/(pi*n);
end
%end
end
plot(n,H,
'o-b'
);
%stem
ind = find(n==0);
K(ind) = wg/pi;
t = hamming(K);
plot(t,
'r'
)
zad4.
clear all
clc
fo=150;
fp=1000;
f1=100;
f2=250;
Nh=15;
wo=(fo/(fp/2))*pi
for n=-Nh:Nh;
if n==0
h0(n+Nh+1)=wo/pi;
else
h0(n+Nh+1)=sin(wo*n)/(pi*n);
end
end
plot(h0,'o-b')
fp=1000;
N=1e3;
Td=5;
dt=1/fp;
f=fp/2;
t=(0:N-1)*dt;
fi1=0;
fi2=0;
A1=1.5;
A2=2;
x1=A1*cos(2*pi*f1*t+fi1);
x2=A2*cos(2*pi*f2*t+fi2);
x=x1+x2;
plot(t,x,'.-')
y=filter(h0,1,x)
plot(t,x1,'.-r')
hold on
plot(t,y,'.-b')