Compare commits

...

3 Commits

Author SHA1 Message Date
Filipriec
ac80e6fd55 semestralka 2025-11-06 14:59:22 +01:00
Filipriec
e46f0d4336 optimized 2025-10-09 16:41:29 +02:00
Filipriec
5f99d5cadd hodina 2 2025-10-09 16:09:36 +02:00
10 changed files with 205 additions and 0 deletions

27
hod2/1.m Normal file
View File

@@ -0,0 +1,27 @@
% X(k)=1/N \sum_{n=0}^{N-1} x(n)*e^{-j*2*\pi*n*k/N}
% x(n)=\sum_{n=0}^{N-1} X(k)e^{j*2*\pi*n*k/N}
x = [8,8,8,8,8,8,8,8]
X = []
N = length(x)
for k = 0:(N - 1)
Xk = 0;
for n = 0:(N - 1)
Xk = Xk + ( x(n + 1) .* exp(-1j * 2 * pi * n * k / N) );
end
X(end + 1) = Xk;
end
X = 1/N * X
temp = 1/N * fft(x)
y = [];
for n = 0:(N - 1)
xn = 0;
for k = 0:(N - 1)
xn = xn + ( X(k + 1) .* exp(1j * 2 * pi * n * k / N) );
end
y(end + 1) = xn;
end
y

8
hod2/2.m Normal file
View File

@@ -0,0 +1,8 @@
% X(k)=1/N \sum_{n=0}^{N-1} x(n)*e^{-j*2*\pi*n*k/N}
% x(n)=\sum_{n=0}^{N-1} X(k)e^{j*2*\pi*n*k/N}
x = [8,8,8,8,8,8,8,8]
X = DFT_priama(x)
x = DFT_spatna(X)

13
hod2/DFT_priama.m Normal file
View File

@@ -0,0 +1,13 @@
% priama X(k) z x(n)
function X = DFT_priama(x)
N = length(x);
X = zeros(1,N);
for k = 0:(N - 1)
Xk = 0;
for n = 0:(N - 1)
Xk = Xk + ( x(n + 1) .* exp(-1j * 2 * pi * n * k / N) );
end
X(k + 1) = Xk;
end
X = 1/N * X;
end

13
hod2/DFT_spatna.m Normal file
View File

@@ -0,0 +1,13 @@
% spatna x(n) z X(k)
function x = DFT_spatna(X)
N = length(X);
x = zeros(1,N);
for n = 0:(N - 1)
xn = 0;
for k = 0:(N - 1)
xn = xn + ( X(k + 1) .* exp(1j * 2 * pi * n * k / N) );
end
x(n + 1) = xn;
end
end

32
hod3/1.m Normal file
View File

@@ -0,0 +1,32 @@
clc;
close all;
max_val = 99
n = 0:max_val
f = 0.05
% x = (x^5-x^3+x^2-1)*(x^6-2);
%
% Konvolucia
a = sin(2*pi*f*n)
b = sin(2*pi*f*n+0.5)
c = conv(a,b)
figure;
stem(a)
hold on;
stem(b)
figure;
stem(c)
figure;
% Korelacia
R = xcorr(a,b)
stem(R)
figure;
% AutoKorelacia
T = autocorr(a)
stem(T)

33
hod3/2.m Normal file
View File

@@ -0,0 +1,33 @@
clc;
close all;
max_val = 99
n = 0:max_val
f = 0.05
% x = (x^5-x^3+x^2-1)*(x^6-2);
%
% Konvolucia
a = sin(2*pi*f*n)
b = sin(2*pi*f*n+0.5)
c = conv(a,b)
figure;
stem(a)
hold on;
stem(b)
figure;
stem(c)
figure;
% Korelacia
R = xcorr(a,b)
stem(R)
figure;
% AutoKorelacia
T = autocorr(a)
stem(T)

30
hod4/1.m Normal file
View File

@@ -0,0 +1,30 @@
% y(n)=(3/4)*y(n-1) + (1/6)*y(n-2) + x(n)+(1/2)*x(n-1)
clc;
clear all;
close all;
cit = [1, 0.5]
men = [1, -0.75, -1/6]
roots(men)
figure;
zplane(cit, men)
figure;
freqz(cit, men, 'whole')
z = roots(cit);
p = roots(men);
theta = pi/4;
r = 0.99;
new_zero_pair = [0;0];
new_pole_pair = [r*exp(1j*theta); r*exp(-1j*theta)];
filter_cit = poly(new_zero_pair)
filter_men = poly(new_pole_pair)
z_new = [z; new_zero_pair];
p_new = [p; new_pole_pair];
cit_new = poly(z_new)
men_new = poly(p_new)
figure;
zplane(cit_new, men_new)
figure;
freqz(cit_new, men_new, 'whole')

28
hod4/2.m Normal file
View File

@@ -0,0 +1,28 @@
% y(n)=(3/4)*y(n-1) + (1/6)*y(n-2) + x(n)+(1/2)*x(n-1)
clc;
clear all;
close all;
cit = [1, 0.5]
men = [1, -0.75, -1/6]
roots(men)
figure;
zplane(cit, men);
figure;
freqz(cit, men, 'whole');
x = [zeros(1, 10), 1, zeros(1, 100)]
y = zeros(size(x));
for n = 3:length(x)
y(n) = 0.75*y(n-1) + (1/6)*y(n-2) + x(n) + 0.5*x(n-1)
stem(0:length(x)-1, y, 'filled'); % plot discrete-time sequence
title(['System output up to sample n = ' num2str(n)]);
xlabel('n');
ylabel('y(n)');
ylim([-0.5 1.5]); % fixed axis for stability
grid on;
pause(0.25);
end

Binary file not shown.

21
semestralka/1.m Normal file
View File

@@ -0,0 +1,21 @@
clc;
close all;
clear all;
% semestralka
rawText = fileread('data6.dat');
nums = regexp(rawText, '[-+]?\d+', 'match');
data = int16(str2double(nums));
X = DFT_priama(double(data))
n = length(X)
freq = (0:n-1)/n
figure;
plot(double(data));
figure;
plot(freq, X)
figure;
plot(freq, abs(X))
figure;
plot(freq, angle(X))