62 lines
1.2 KiB
Matlab
62 lines
1.2 KiB
Matlab
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');
|