Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions SpectrVisWF.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function SpectrVisWF(Fsig,t,f)
%{
������������ ������� � ������� "waterfall"
%}

figure,
title('Spectrogram')
ylabel('time [s]')
xlabel('frequency [Hz]')
axis([0, Inf,min(t), Inf ])
hold on
for ind = 1:size(Fsig,2)
plot(f, abs(Fsig(:,ind)) + t(ind),'k')
hold on
end
hold off
65 changes: 65 additions & 0 deletions Test1.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
clear, clc, close all

Fs = 8000; % ������� �����������
f1 = 400; % ������� ���������� ������ �� ���������
f2 = 1200; % ������� ���������� ������� ��������
tau = 0.02; % ������������ ���������
t1 = 0.02; % ����� ������� ������� ��������
t2 = 0.06; % ����� ������� ������� ��������
dt = 1/Fs; % ������ �����������
t = 0:dt:0.1; % �����
N = length(t); % ���������� ��������
% ������ �������, ��������� �� ���� ���������
% ������� ���������� ���, ��� �������� � ������ ��������
% �������� � ������ �������
x1 = (t>=t1 & t<t1+tau).*sin(2*pi*f1*t)+ ...
(t>=t2 & t<t2+tau).*sin(2*pi*f2*t);
x2 = (t>=t1 & t<t1+tau).*sin(2*pi*f2*t)+ ...
(t>=t2 & t<t2+tau).*sin(2*pi*f1*t);

% ������ ������� ��������
figure
subplot(2,1,1), plot(t,x1,'k'), xlabel('t'), ylabel('x_1(t)')
subplot(2,1,2), plot(t,x2,'k'), xlabel('t'), ylabel('x_2(t)')

X1 = fft(x1); % ���������� �������������� ����� �������
X2 = fft(x2); % ���������� �������������� ����� �������
% �������, ��������������� ����������
f = (ceil(N/2)-N:ceil(N/2)-1)*Fs/N;
% ������ ������� ����������� �������� ��������
figure
subplot(2,1,1), stem(f, abs(fftshift(X1))/N, 'k.')
xlabel('f'), ylabel('|X_1|'), axis([0 1600 0 0.12])
subplot(2,1,2), stem(f, abs(fftshift(X2))/N, 'k.')
xlabel('f'), ylabel('|X_2|'), axis([0 1600 0 0.12])
% ��������� ������� ���������� �������������� �����
[Xw1,F,T] = spectrogram(x1,triang(128),64,128,Fs);
Xw2 = spectrogram(x2,triang(128),64,128,Fs);

c=(1:-0.05:0)'*[1 1 1]; % ������� ������ ��� ����������

% ������ ��������� ������� ������ �������� ��������������

figure
subplot(2,1,1), contourf(T,F,abs(Xw1))
colormap(c), colorbar, grid on, axis([min(T) max(T) 0 1600])
xlabel('t'), ylabel('f'), title('|Xw_1(t,f)|')
subplot(2,1,2), contourf(T,F,abs(Xw2))
colormap(c), colorbar, grid on, axis([min(T) max(T) 0 1600])
xlabel('t'), ylabel('f'), title('|Xw_2(t,f)|')

% ��������� ������� ���������� �������������� �����
% ��������� ������ ���� � 4 ����
[Xw1,F,T] = spectrogram(x1,triang(32),16,32,Fs);
Xw2 = spectrogram(x2,triang(32),16,32,Fs);

% ������ ��������� ������� ������ �������� ��������������

% ������������ � ����� ������� �������
figure
subplot(2,1,1), contourf(T,F,abs(Xw1))
colormap(c), colorbar, grid on, axis([min(T) max(T) 0 1600])
xlabel('t'), ylabel('f'), title('|Xw_1(t,f)|')
subplot(2,1,2), contourf(T,F,abs(Xw2))
colormap(c), colorbar, grid on, axis([min(T) max(T) 0 1600])
xlabel('t'), ylabel('f'), title('|Xw_2(t,f)|')
26 changes: 26 additions & 0 deletions Test2.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
clear all

Fs = 8000; % ������� �����������
f1 = 400; % ������� ���������� ������ �� ���������
f2 = 1200; % ������� ���������� ������� ��������
tau = 0.02; % ������������ ���������
t1 = 0.02; % ����� ������� ������� ��������
t2 = 0.06; % ����� ������� ������� ��������
dt = 1/Fs; % ������ �����������
t = 0:dt:0.1; % �����
N = length(t); % ���������� ��������
% ������ �������, ��������� �� ���� ���������
% ������� ���������� ���, ��� �������� � ������ ��������
% �������� � ������ �������
x1 = (t>=t1 & t<t1+tau).*sin(2*pi*f1*t)+ ...
(t>=t2 & t<t2+tau).*sin(2*pi*f2*t);
x2 = (t>=t1 & t<t1+tau).*sin(2*pi*f2*t)+ ...
(t>=t2 & t<t2+tau).*sin(2*pi*f1*t);

% ������ ������� ��������
figure
subplot(2,1,1), plot(t,x1,'k'), xlabel('t'), ylabel('x_1(t)')
subplot(2,1,2), plot(t,x2,'k'), xlabel('t'), ylabel('x_2(t)')

[t,f,Fsig] = WinFFT(x1,triang(128), 64, Fs);
SpectrVisWF(Fsig,t,f)
37 changes: 37 additions & 0 deletions WinFFT.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
function [t,f,Fsig] = WinFFT(sig, wtype, woverlap, Fs)
%{
WindowFFT ���������� ������� ��� � �����������:
sig - �������� ������;
wtype - ��� ����, �������� � ���� ������� (������������� �������� ���
����, ������ ������� ������);
woverlap - ���������� ���� � �������� �������;
Fs - ������� ������������� �������

�������� ���������:
t - ����� [c];
f - ������� [��];
Fsig - ������� �����-�������������� ������� sig.
%}

%{
�������� ����� ������� �� ��������� ����� ����������. ���� ����� �������
�� ������ ����� ����������, �� ��������� ������ ������ ������
%}
if mod(length(sig), woverlap) ~= 0
sig = [sig, zeros(1, woverlap * (fix(length(sig)/woverlap) + 1) - length(sig))];
end

N = length(wtype); % ���������� ��������
f = (0:ceil(N/2) - 1) * Fs /N; % �������, ��������������� ����������
dt = 1/Fs; % ������ �����������
k = floor((length(sig) - woverlap)/(N - woverlap)); % ����� �������� �� ������� � ������ �������� ���
t = (N - woverlap).*dt.*(1:k); % �����

for ind = 1:k
winsig(:,ind) = wtype.*(sig(woverlap * (ind - 1) + 1:woverlap * (ind - 1) + N))';
end

%% ��� - ������� �� ��������
Fsig = fft(winsig);
Fsig = Fsig(1:ceil(N/2),:);