forked from yueyuzhao/gyrophone
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Yan Michalevsky
committed
Sep 15, 2013
1 parent
a2e3699
commit d1c9ddc
Showing
5 changed files
with
38 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
function match(audio_file, gyro_rec, gyro_fs) | ||
% gyro_fs - Gyro sampling frequency | ||
|
||
% plot_spectrums(gyro_rec, GYRO_FS); | ||
|
||
[audio_samples, audio_fs] = audioread(audio_file); | ||
[gyro_timestamps, gyro_samples] = read_samples_file(gyro_rec); | ||
|
||
match_samples(audio_samples, audio_fs, gyro_samples, gyro_fs); | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
function match_samples(audio_samples, audio_fs, gyro_samples, gyro_fs) | ||
display(length(gyro_samples)); | ||
|
||
display(audio_fs); | ||
display(length(audio_samples)); | ||
|
||
audio_resampled = resample(audio_samples, gyro_fs, audio_fs); | ||
display(length(audio_resampled)); | ||
|
||
plot( conv(gyro_samples(:,1), fliplr(audio_resampled)) ); | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,8 @@ | ||
function [merged_timestamps, merged_signal] = merge_samples(timestamps1, samples1, timestamps2, samples2) | ||
merged_timestamps = sort([timestamps1; timestamps2]); | ||
merged_signal = zeros(length(timestamps1) + length(timestamps2), size(samples1, 2)); | ||
function [merged_timestamps, merged_signal] = ... | ||
merge_samples(timestamps1, samples1, timestamps2, samples2) | ||
% Merge samples given their timestamps | ||
|
||
pos1 = 1; | ||
pos2 = 1; | ||
for pos = 1:length(merged_timestamps) | ||
if pos1 <= length(timestamps1) && pos2 <= length(timestamps2) | ||
if timestamps1(pos1) < timestamps2(pos2) | ||
merged_signal(pos, :) = samples1(pos1, :); | ||
pos1 = pos1 + 1; | ||
else | ||
merged_signal(pos, :) = samples2(pos2, :); | ||
pos2 = pos2 + 1; | ||
end; | ||
else | ||
if pos1 <= length(timestamps1) | ||
merged_signal(pos, :) = samples1(pos1, :); | ||
pos1 = pos1 + 1; | ||
end; | ||
|
||
if pos2 <= length(timestamps2) | ||
merged_signal(pos, :) = samples2(pos2, :); | ||
pos2 = pos2 + 1; | ||
end; | ||
end; | ||
end; | ||
[merged_timestamps, ix] = sort([timestamps1(:); timestamps2(:)]); | ||
merged_signal = [samples1(:); samples2(:)]; | ||
merged_signal = merged_signal(ix); | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
function [merged_signals] = merge_signals(sig1, sig2, offset1, offset2, n) | ||
% Merge two signals sample-by-sample given the samples and offsets | ||
|
||
timestamps1 = offset1:n:offset1+length(sig1)*n - 1; | ||
timestamps2 = offset2:n:offset2+length(sig2)*n - 1; | ||
[~, merged_signals] = merge_samples(timestamps1, sig1, ... | ||
timestamps2, sig2); | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
function plot_spectrums(filename, fs) | ||
nfft = 256; | ||
[~, samples] = read_samples_file(filename); | ||
for k = 1:3 | ||
figure; | ||
spectrogram(samples(:, k), 128, 120, fs); | ||
% specgram(samples(:, k), 128, 120); | ||
spectrogram(samples(:, k), hanning(nfft), round(nfft * 0.9), nfft, fs); | ||
end; | ||
end |