-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfir_filter.m
91 lines (67 loc) · 1.91 KB
/
fir_filter.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
load pds_fir.mp3
[y,Fs] = audioread('pds_fir.mp3');
s=length(y);
%frequencias normalizadas (w)
fs1=1700/(Fs/2);
fp1=1850/(Fs/2);
fp2=2150/(Fs/2);
fs2=2300/(Fs/2);
f0=Fs/s;
f1=f0:f0:Fs/2;
f2=-Fs/2:f0:-f0;
f=[f2,f1];
t0=1/Fs;
t= t0:t0:s/Fs;
white = randn(s,1);
white = max(y)*white/max(white);
b = firpm(1000,[0 fs1 fp1 fp2 fs2 1],[0 0 1 1 0 0]);
colornoise = filter(b,1,white);
sujo = colornoise+y;
M = ceil(32/(2.285*pi*100/(Fs/2)));
M=M+mod(M,2);
w = kaiser(M+1,3.329);
n=[1:M+1];
fc1=(fp1+fs1)/2;
fc2=(fp2+fs2)/2;
hd = ((sinc((fc1)*(n-M/2))*fc1)-(sinc(fc2*(n-M/2))*fc2));
hd(M/2)=hd(M/2)+1;
h=(hd'.*w);
out = filter(h,1,sujo);
%OUT = fftshift(fft(out));
%out = ifft(OUT1);
%plot(freq,abs(SfUJO));
figure
fig1=plot(f,abs(fftshift(fft(y)))), title("sinal de audio na frequencia"), xlabel("frequencia (Hz)");
saveas(fig1,"audio_freq","jpeg");
figure
fig2=plot(f,abs(fftshift(fft(sujo)))), title("sinal corrompido na frequencia");
xlabel("frequencia (Hz)");
saveas(fig2,"corromp_freq","jpeg");
figure
fig3=plot(t,sujo), title("sinal corrompido no tempo");xlabel("tempo (s)");
saveas(fig3,"corromp_time","jpeg");
figure
fig4=plot(abs(fftshift(fft(out)))), title("saida do sinal na frequencia");xlabel("frequencia (Hz)");
saveas(fig4,"out_freq","jpeg");
figure
fig5=plot(f,abs(fftshift(fft(colornoise)))), title("ruido na frequencia");
xlabel("frequencia (Hz)");
saveas(fig5,"colorido_freq","jpeg");
figure
fig6=plot(t,colornoise), title("ruido no tempo");
xlabel("tempo(s)");
saveas(fig6,"color_time","jpeg");
figure
fig7=plot(abs(fftshift(fft(h)))), title("filtro com janela de kaiser na frequencia");
xlabel("frequencia (Hz)");
saveas(fig7,"kaiser_freq","jpeg");
%sound(out,Fs)
figure
fig8=plot(t,y), title("sinal de audio no tempo");
xlabel("audio (s)");
saveas(fig8,"audio_time","jpeg");
%plot(n,sujo);
figure
plot(t,out), title("saida do sinal no tempo");
xlabel("tempo (s)");
saveas(fig7,"out_time","jpeg");