-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdz1_deo1_2_2016_0202.m
121 lines (93 loc) · 3.11 KB
/
dz1_deo1_2_2016_0202.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
close all
clear all
clc
%% 1.6
Fs = 8000;
Ts = 1/Fs;
t = 0:Ts:5;
xc = chirp(t,0,5,4000,'linear');
%chirp u vremenu
figure(5)
plot(t(1:length(t)/10),xc(1:length(t)/10))
xlabel('time');
fig5 = gca; fig5.XAxis.TickLabelFormat = '%.2f s';
print('Chirp vremenski','-dsvg','-r0')
signal = audioplayer(xc,Fs);
%chirp spektrogram
figure(1)
subplot(3,1,1)
pspectrum(xc,Fs,'spectrogram')
%title('Spektogram signala x_{chirp}[n], x_{chirp,d2}[n] i x_{chirp,d5}[n]')
title ('')
%% 1.7 i 1.8
t2 = 0:2*Ts:5;
xc_d2 = chirp(t2,0,5,4000,'linear');
signal2 = audioplayer(xc_d2,Fs/2);
subplot(3,1,2)
pspectrum(xc_d2,Fs/2,'spectrogram')
title('')
t5 = 0:5*Ts:5;
xc_d5 = chirp(t5,0,5,4000,'linear');
signal5 = audioplayer(xc_d5,Fs/5);
subplot(3,1,3)
pspectrum(xc_d5,Fs/5,'spectrogram')
title('')
%savefig('Spektogram signala x_{chirp}[n], x_{chirp,d2}[n] i x_{chirp,d5}[n]')
%print('Spektogram signala x_{chirp}[n], x_{chirp,d2}[n] i x_{chirp,d5}[n]','-dpng','-r0')
%% 1.9
[song,Fs_song]=audioread('dz1_signali\chopin.wav');
nocturno=audioplayer(song,Fs_song);
nfft = 2^12;
overlap = 3/4*nfft;
window = kaiser(nfft, 7); %kajzerova prozorska funkcija je najpogodnija za spektrogram jer se na
%optimalan nacin ostvaruje kompromis izmedju
%duzine sekvence, frekvencijske rezolucije i
%curenja spektra **beta [4,10] pa je 7 sredina** :))))
[s,f,t] = spectrogram(song, window, overlap, nfft, Fs_song);
s_dB = 20*log10(abs(s));
figure(2)
imagesc(t, f(1:end/3), s_dB(1:end/3,:)), title('Spektogram signala');
axis('xy');
xlabel('Time');
ylabel('Frequency');
fig2 = gca; fig2.XAxis.TickLabelFormat = '%i s';
fig2.XMinorTick = 'on';
fig2.YAxis.TickLabelFormat = '%i Hz';
fig2.YMinorTick = 'on';
% savefig('Spektogram signala')
% print('Spektogram signala','-dpng','-r0')
%nedegradirani signal sa smanjenom frekvencijom odabiranja
fx=4;
song_new=song(1:1*fx:end);
new=audioplayer(song_new,Fs_song/fx);
[s_new,f_new,t_new] = spectrogram(song_new, window, overlap, nfft, Fs_song/fx);
s_new_dB = 20*log10(abs(s_new));
figure(3)
imagesc(t_new, f_new, s_new_dB), title('Spektogram nedegradiranog signala sa smanjenom frekvencijom odabiranja');
axis('xy');
xlabel('Time');
ylabel('Frequency');
fig3 = gca; fig3.XAxis.TickLabelFormat = '%i s';
fig3.XMinorTick = 'on';
fig3.YAxis.TickLabelFormat = '%i Hz';
fig3.YMinorTick = 'on';
% savefig('Spektogram nedegradiranog')
% print('Spektogram nedegradiranog','-dpng','-r0')
%% 1.10
%degradirani signal
fx=10;
song_new=song(1:1*fx:end);
new=audioplayer(song_new,Fs_song/fx);
[s_new,f_new,t_new] = spectrogram(song_new, window, overlap, nfft, Fs_song/fx);
s_new_dB = 20*log10(abs(s_new));
figure(4)
imagesc(t_new, f_new, s_new_dB), title('Spektogram degradiranog signala');
axis('xy');
xlabel('Time');
ylabel('Frequency');
fig4 = gca; fig4.XAxis.TickLabelFormat = '%i s';
fig4.XMinorTick = 'on';
fig4.YAxis.TickLabelFormat = '%i Hz';
fig4.YMinorTick = 'on';
% savefig('Spektogram degradiranog')
% print('Spektogram degradiranog','-dpng','-r0')