Compare commits

5 Commits

Author SHA1 Message Date
Filipriec
1efa2dbec6 semestralka 2025-11-13 21:45:30 +01:00
Filipriec
4f4b634dc8 semestralka a praca na nej 2025-11-13 14:47:18 +01:00
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
12 changed files with 258 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.

43
semestralka/1.m Normal file
View File

@@ -0,0 +1,43 @@
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);
Fs = 200;
freq = (0:n-1)*Fs/n;
figure;
plot(double(data));
figure;
plot(freq, X)
%3
figure;
magX = abs(X);
plot(freq, magX)
% freq shift pre -Fs/2 po Fs/2
freq_shift = (-n/2:n/2-1)*(Fs/n);
%4
figure;
subplot(2,1,1);
plot(freq_shift, real(fftshift(X)), 'b');
subplot(2,1,2);
plot(freq_shift, imag(fftshift(X)), 'r');
%5
figure;
plot(freq, imag(X), 'r');
%6
figure;
plot(freq, real(X), 'r');
figure;
plot(freq, angle(X))
[pks, locs] = findpeaks(magX, 'NPeaks', 10, 'SortStr', 'descend');
f0 = freq(locs)
f0b = f0(f0 < 100);
f0_ohranicene = f0b

29
semestralka/2.m Normal file
View File

@@ -0,0 +1,29 @@
clc;
close all;
clear all;
f0_ohranicene = [25, 20, 10, 12.5];
% semestralka
rawText = fileread('data6.dat');
nums = regexp(rawText, '[-+]?\d+', 'match');
data = int16(str2double(nums));
Fs = 200;
r = 0.95;
b = 1;
a = 1;
for k = 1:length(f0_ohranicene)
theta = 2*pi*(f0_ohranicene(k)/Fs);
b = conv(b, [1, -2*cos(theta), 1]);
a = conv(a, [1, -2*r*cos(theta), r^2]);
end
figure;
zplane(b, a);
figure;
freqz(b, a);
figure;
freqz(b, a);
filtered_data = filter(b, a, double(data));
plot(filtered_data);

2
semestralka/docs.txt Normal file
View File

@@ -0,0 +1,2 @@
https://en.wikipedia.org/wiki/Infinite_impulse_response
https://courses.physics.illinois.edu/ece401/fa2020/slides/lec15.pdf