-
Notifications
You must be signed in to change notification settings - Fork 1
/
MPD1.m
155 lines (118 loc) · 4.65 KB
/
MPD1.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
clear
clear sound
clc
close all
%Sampling frequency [Hz]
fs = 44100;
%Directory to a sound file - for best results it is recommended that it's
%free of drums, hiss or any kind of noise
dir = 'MANOID - SYNESTEZJA EP - 02 AWAY ft. Pola Rise.flac';
%-------------------------------------------------------------------------------------------%
% Czytanie audio
%-------------------------------------------------------------------------------------------%
%Załadowanie z pliku
sound_toprocess = audioread(dir);
%Zamiana na mono
sound_toprocess = (sound_toprocess(:,1) + sound_toprocess(:,2))/2;
%Odwrócenie wektora na poziomy ze względu na przyjętą konwencję
sound_toprocess = sound_toprocess';
sound_toprocess2 = sound_toprocess(fs*48:fs*62);
%-------------------------------------------------------------------------------------------%
%% Odtworzenie dźwięku
sound(sound_toprocess2, fs);
%% Zatrzymanie dźwięku
clear sound
%% Pokaz 1 - widmo amplitudowe
%Przesunięcie w bloku
shift = 1;
figure('units','normalized', 'position', [0 0 1 1]);
for i = 1:35
%Zamknięcie poprzedniego okna
%close all;
%Pobranie 16384 próbek z odpowiednim przesunięciem
sound_toFFT = sound_toprocess2(shift : shift+16384);
%Odtworzenie dźwięku
sound(sound_toFFT, fs);
%Pokazanie widma amplitudowego
widmo_amplitudowe = 20*log10(abs(fftshift(fft(sound_toFFT.*hann(size(sound_toFFT,2))'))));
widmo_amplitudowe = widmo_amplitudowe(floor(size(widmo_amplitudowe,2)./2):end);
subplot(2,1,2);
plot(log2(1:size(widmo_amplitudowe,2)),widmo_amplitudowe);
axis([0 inf -20 70]); %Ustawienia osi
grid on %Włączenie siatki
tytul = sprintf('Widmo amplitudowe dla próbek od %d do %d', shift-1, shift+16384-1);
title(tytul);
xlabel('Częstotliwość'); ylabel('Amplituda [dB]');
set(gca,'XTick',[]);
subplot(2,1,1);
plot(sound_toFFT);
axis([0 inf -1 1]); %Ustawienia osi
grid on;
tytul = sprintf('Przebieg sygnału dla próbek od %d do %d', shift-1, shift+16384-1);
title(tytul);
xlabel('Czas');
%Przesunięcie bloku audio
shift = shift + 1764;
%Naciśnięcie dowolnego klawisza spowoduje kontynuację pętli
pause
end
%% Pokaz 2 - widmo amplitudowe + widmo fazowe
% Wstęp do widma fazowego, potem gif
%Przesunięcie w bloku
figure('units','normalized', 'position', [0 0 1 1]);
for i = 1:20
%Zamknięcie poprzedniego okna
%close all;
%Pobranie 16384 próbek z odpowiednim przesunięciem
sound_toFFT = sound_toprocess2(shift : shift+16384);
%Odtworzenie dźwięku
sound(sound_toFFT, fs);
%Pokazanie widma amplitudowego
widmo_amplitudowe = 20*log10(abs(fftshift(fft(sound_toFFT.*hann(size(sound_toFFT,2))'))));
widmo_amplitudowe = widmo_amplitudowe(floor(size(widmo_amplitudowe,2)./2):end);
subplot(2,1,1)
plot(log2(1:size(widmo_amplitudowe,2)),widmo_amplitudowe);
axis([0 inf -20 70]); %Ustawienia osi
grid on %Włączenie siatki
tytul = sprintf('Widmo amplitudowe dla próbek od %d do %d', shift-1, shift+16384-1);
title(tytul);
xlabel('Częstotliwość'); ylabel('Amplituda [dB]');
set(gca,'XTick',[]);
%Pokazanie widma fazowego
widmo_fazowe = angle(fftshift(fft(sound_toFFT.*hann(size(sound_toFFT,2))')));
widmo_fazowe = widmo_fazowe(floor(size(widmo_fazowe,2)./2):end);
subplot(2,1,2)
plot(log2(1:size(widmo_fazowe,2)),widmo_fazowe);
axis([0 inf -pi pi]); %Ustawienia osi
grid on %Włączenie siatki
title('Widmo fazowe');
xlabel('Częstotliwość'); ylabel('Faza [rad]');
set(gca,'XTick',[]);
%Przesunięcie bloku audio
shift = shift + 3000;
%Naciśnięcie dowolnego klawisza spowoduje kontynuację pętli
pause
end
%%
%% Widmo CAŁEGO utworu
%Widmo można pobrać z całego utworu!
figure('units','normalized', 'position', [0 0 1 1]);
%Pokazanie widma amplitudowego
widmo_amplitudowe = 20*log10(abs(fftshift(fft(sound_toprocess.*hann(size(sound_toprocess,2))'))));
widmo_amplitudowe = widmo_amplitudowe(floor(size(widmo_amplitudowe,2)./2):end);
subplot(2,1,1)
plot(log2(1:size(widmo_amplitudowe,2)),widmo_amplitudowe);
axis([0 inf -40 110]); %Ustawienia osi
grid on %Włączenie siatki
title('Widmo amplitudowe całego utworu');
xlabel('Częstotliwość'); ylabel('Amplituda [dB]');
set(gca,'XTick',[]);
widmo_fazowe = angle(fftshift(fft(sound_toprocess.*hann(size(sound_toprocess,2))')));
widmo_fazowe = widmo_fazowe(floor(size(widmo_fazowe,2)./2):end);
subplot(2,1,2)
plot(log2(1:size(widmo_fazowe,2)),widmo_fazowe);
axis([0 inf -pi pi]); %Ustawienia osi
grid on %Włączenie siatki
title('Widmo fazowe');
xlabel('Częstotliwość'); ylabel('Faza [rad]');
set(gca,'XTick',[]);