Compare commits

..

8 Commits

Author SHA1 Message Date
Filipriec
d94c92eead storiing sem2 2025-12-05 18:57:22 +01:00
Filipriec
f9f5e27f45 sem2 start 2025-12-05 18:57:22 +01:00
Priec
9bf8347b79 final code for css 2025-12-02 22:55:37 +01:00
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
15 changed files with 591 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.

61
semestralka/FIR.m Normal file
View File

@@ -0,0 +1,61 @@
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;
N = 3000;
notch_hw = 0.08;
trans_bw = 0.08;
f0_sorted = sort(f0_ohranicene);
F = [];
A = [];
prev_end = 0;
for k = 1:length(f0_sorted)
f0 = f0_sorted(k);
notch_start = (f0 - notch_hw) / (Fs/2);
notch_end = (f0 + notch_hw) / (Fs/2);
trans_start = max(prev_end + 0.001, (f0 - notch_hw - trans_bw) / (Fs/2));
trans_end = (f0 + notch_hw + trans_bw) / (Fs/2);
if trans_start > prev_end + 0.001
F = [F, prev_end, trans_start];
A = [A, 1, 1];
end
F = [F, notch_start, notch_end];
A = [A, 0, 0];
prev_end = trans_end;
end
if prev_end < 1
F = [F, prev_end, 1];
A = [A, 1, 1];
end
F = max(0, min(1, F));
b = firls(N, F, A);
a = 1;
b = real(b);
figure;
zplane(b, a);
figure;
freqz(b, a);
set(gcf, 'Color', 'none');
set(gca, 'Color', 'none');
print('-depsc', 'fig1_semD.eps');
figure;
freqz(b, a);
filtered_data = filtfilt(b, a, double(data));
title('Filtrovaný signál');
xlabel('Vzorky');
ylabel('Amplitúda');
set(gcf, 'Color', 'none');
set(gca, 'Color', 'none');
plot(filtered_data);
print('-depsc', 'fig2_semD.eps');

56
semestralka/IIR_SOS.m Normal file
View File

@@ -0,0 +1,56 @@
clc;
close all;
clear all;
f0_ohranicene = [25, 20, 10, 12.5];
rawText = fileread('data6.dat');
nums = regexp(rawText, '[-+]?\d+', 'match');
data = int16(str2double(nums));
Fs = 200;
r = 0.98;
% predalokovana SOS matica pre vsetky filtrovane zlozky
% 6 lebo koeficienty [b0, b1, b2, a0, a1, a2]
sos = zeros(length(f0_ohranicene), 6);
for k = 1:length(f0_ohranicene)
theta = 2 * pi * (f0_ohranicene(k) / Fs);
b = [1, -2*cos(theta), 1];
a = [1, -2*r*cos(theta), r^2];
sos(k, :) = [b, a]
end
figure;
[z, p, k_gain] = sos2zp(sos);
figure;
zplane(z, p);
title('Nuly a póly filtra');
xlabel('Reálna časť');
ylabel('Imaginárna časť');
set(gcf, 'Color', 'none');
set(gca, 'Color', 'none');
print('-depsc', 'fig2_semE.eps');
figure;
freqz(sos, 4096, Fs);
title('Frekvenčná charakteristika SOS filtra');
xlabel('Frekvencia [Hz]');
ylabel('Zosilnenie [dB]');
set(gcf, 'Color', 'none');
set(gca, 'Color', 'none');
print('-depsc', 'fig3_semE.eps');
filtered_data = sosfilt(sos, double(data));
figure;
plot(filtered_data);
title('Filtrovaný signál');
xlabel('Vzorky');
ylabel('Amplitúda');
grid on;
set(gcf, 'Color', 'none');
set(gca, 'Color', 'none');
set(gcf, 'PaperPosition', [0 0 1.7*6 0.75*4.2]);
set(gcf, 'PaperSize', [1.7*6 0.75*4.2]);
print('-depsc', 'fig4_semE.eps');

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

102
semestralka/full_IIR.m Normal file
View File

@@ -0,0 +1,102 @@
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)
%4
% freq shift pre -Fs/2 po Fs/2
freq_shift = (-n/2:n/2-1)*(Fs/n);
figure;
subplot(2,1,1);
plot(freq_shift, real(fftshift(X)));
title('Reálna časť posunutého spektra');
xlabel('Frekvencia [Hz]');
ylabel('Reálna hodnota');
subplot(2,1,2);
plot(freq_shift, imag(fftshift(X)), 'r');
title('Imaginárna časť posunutého spektra');
xlabel('Frekvencia [Hz]');
ylabel('Imaginárna hodnota');
set(gcf, 'PaperPosition', [0 0 1.7*6 0.75*4.2]);
set(gcf, 'PaperSize', [1.7*6 0.75*4.2]);
set(gcf, 'Color', 'none'); set(gca, 'Color', 'none');
print('-depsc', 'fig_im_real_semC.eps');
%5
figure;
plot(freq, imag(X), 'r');
%6
figure;
plot(freq, real(X));
%7
figure;
% fazove spektrum
plot(freq, angle(X))
[pks, locs] = findpeaks(magX, 'NPeaks', 10, 'SortStr', 'descend');
f0 = freq(locs)
f0b = f0(f0 < 100); % nyquistov teorem
f0_ohranicene = f0b
f0_ohranicene(f0_ohranicene < 2) = [];
r = 0.975;
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);
title('Nuly a póly filtra');
xlabel('Reálna časť');
ylabel('Imaginárna časť');
set(gcf, 'Color', 'none'); set(gca, 'Color', 'none');
print('-depsc', 'fig1_semC.eps');
figure;
freqz(b, a);
title('Frekvenčná charakteristika (1)');
xlabel('Frekvencia [Hz]');
ylabel('Zosilnenie [dB]');
set(gcf, 'Color', 'none'); set(gca, 'Color', 'none');
print('-depsc', 'fig2_semC.eps');
figure;
freqz(b, a);
title('Frekvenčná charakteristika (2)');
xlabel('Frekvencia [Hz]');
ylabel('Zosilnenie [dB]');
set(gcf, 'Color', 'none'); set(gca, 'Color', 'none');
print('-depsc', 'fig3_semC.eps');
filtered_data = filter(b, a, double(data));
figure;
plot(filtered_data);
title('Filtrovaný signál');
xlabel('Vzorky');
ylabel('Amplitúda');
grid on;
set(gcf, 'Color', 'none'); set(gca, 'Color', 'none');
set(gcf, 'PaperPosition', [0 0 1.7*6 0.75*4.2]);
set(gcf, 'PaperSize', [1.7*6 0.75*4.2]);
print('-depsc', 'fig4_semC.eps');

72
semestralka2/analyza.m Normal file
View File

@@ -0,0 +1,72 @@
clc;
close all;
clear all;
[y, Fs] = audioread('sem2.wav');
t = (0:length(y)-1) / Fs;
figure; %1
plot(t, y);
xlabel('Time');
ylabel('Amplitude');
title('Waveform sem2.wav');
grid on;
[y1, Fs1] = audioread('flac.wav');
[y2, Fs2] = audioread('flac2.wav');
t1 = (0:length(y1)-1) / Fs1;
t2 = (0:length(y2)-1) / Fs2;
figure; %2
plot(t1, y1);
xlabel('Time [s]');
ylabel('Amplitude');
title('Waveform flac.wav');
grid on;
figure; %3
plot(t2, y2);
xlabel('Time [s]');
ylabel('Amplitude');
title('Waveform flac2.wav');
grid on;
N1 = length(y1);
N2 = length(y2);
X1 = fft(y1);
X2 = fft(y2);
freq_shift1 = (-N1/2 : N1/2 - 1) * (Fs1 / N1);
freq_shift2 = (-N2/2 : N2/2 - 1) * (Fs2 / N2);
figure; %4
subplot(2,1,1);
plot(freq_shift1, real(fftshift(X1)), 'b');
title('Reálna časť posunutého spektra flac.wav');
xlabel('Frekvencia [Hz]');
ylabel('Reálna hodnota');
grid on;
subplot(2,1,2);
plot(freq_shift1, imag(fftshift(X1)), 'r');
title('Imaginárna časť posunutého spektra flac.wav');
xlabel('Frekvencia [Hz]');
ylabel('Imaginárna hodnota');
grid on;
set(gcf, 'Color', 'none'); set(gca, 'Color', 'none');
figure; %5
subplot(2,1,1);
plot(freq_shift2, real(fftshift(X2)), 'b');
title('Reálna časť posunutého spektra flac2.wav');
xlabel('Frekvencia [Hz]');
ylabel('Reálna hodnota');
grid on;
subplot(2,1,2);
plot(freq_shift2, imag(fftshift(X2)), 'r');
title('Imaginárna časť posunutého spektra flac2.wav');
xlabel('Frekvencia [Hz]');
ylabel('Imaginárna hodnota');
grid on;
set(gcf, 'Color', 'none'); set(gca, 'Color', 'none');

114
semestralka2/analyza_b.m Normal file
View File

@@ -0,0 +1,114 @@
clc;
close all;
clear all;
[y, Fs] = audioread('sem2.wav');
t = (0:length(y)-1) / Fs;
figure; %1
plot(t, y);
xlabel('Time');
ylabel('Amplitude');
title('Waveform sem2.wav');
grid on;
[y1, Fs1] = audioread('flac.wav');
[y2, Fs2] = audioread('flac2.wav');
t1 = (0:length(y1)-1) / Fs1;
t2 = (0:length(y2)-1) / Fs2;
figure; %2
plot(t1, y1);
xlabel('Time [s]');
ylabel('Amplitude');
title('Waveform flac.wav');
grid on;
figure; %3
plot(t2, y2);
xlabel('Time [s]');
ylabel('Amplitude');
title('Waveform flac2.wav');
grid on;
N1 = length(y1);
N2 = length(y2);
X1 = fft(y1);
X2 = fft(y2);
freq_shift1 = (-N1/2 : N1/2 - 1) * (Fs1 / N1);
freq_shift2 = (-N2/2 : N2/2 - 1) * (Fs2 / N2);
figure; %4
subplot(2,1,1);
plot(freq_shift1, real(fftshift(X1)), 'b');
title('Reálna časť posunutého spektra flac.wav');
xlabel('Frekvencia [Hz]');
ylabel('Reálna hodnota');
grid on;
subplot(2,1,2);
plot(freq_shift1, imag(fftshift(X1)), 'r');
title('Imaginárna časť posunutého spektra flac.wav');
xlabel('Frekvencia [Hz]');
ylabel('Imaginárna hodnota');
grid on;
set(gcf, 'Color', 'none'); set(gca, 'Color', 'none');
figure; %5
subplot(2,1,1);
plot(freq_shift2, real(fftshift(X2)), 'b');
title('Reálna časť posunutého spektra flac2.wav');
xlabel('Frekvencia [Hz]');
ylabel('Reálna hodnota');
grid on;
subplot(2,1,2);
plot(freq_shift2, imag(fftshift(X2)), 'r');
title('Imaginárna časť posunutého spektra flac2.wav');
xlabel('Frekvencia [Hz]');
ylabel('Imaginárna hodnota');
grid on;
set(gcf, 'Color', 'none'); set(gca, 'Color', 'none');
% === Najdenie špičiek len v prvej polovici spektra ===
halfN1 = floor(N1/2);
halfN2 = floor(N2/2);
magX1 = abs(X1(1:halfN1));
magX2 = abs(X2(1:halfN2));
realX2 = real(X2(1:halfN2));
imagX2 = imag(X2(1:halfN2));
freq1 = (0:halfN1-1)*(Fs1/N1);
freq2 = (0:halfN2-1)*(Fs2/N2);
% ---- flac.wav (10 peaks from magnitude) ----
[pks1, locs1] = findpeaks(magX1, 'NPeaks', 10, 'SortStr', 'descend');
f0_1 = freq1(locs1);
f0_1(f0_1 < 2) = []; % ignore DC and very low freq
% ---- flac2.wav (4 peaks from real, 6 peaks from imag) ----
[pks2r, locs2r] = findpeaks(abs(realX2), 'NPeaks', 4, 'SortStr', 'descend');
f0_2r = freq2(locs2r);
f0_2r(f0_2r < 2) = [];
[pks2i, locs2i] = findpeaks(abs(imagX2), 'NPeaks', 6, 'SortStr', 'descend');
f0_2i = freq2(locs2i);
f0_2i(f0_2i < 2) = [];
% ---- Výpis výsledkov ----
disp('Najvýraznejšie frekvenčné zložky flac.wav (10, len 1/2 spektra):');
disp(f0_1');
disp('Najvýraznejšie frekvenčné zložky flac2.wav - reálna časť (4, len 1/2 spektra):');
disp(f0_2r');
disp('Najvýraznejšie frekvenčné zložky flac2.wav - imaginárna časť (6, len 1/2 spektra):');
disp(f0_2i');
% // NOTCH FILTER