-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCondensorMicDataAnalysis.m
More file actions
60 lines (59 loc) · 2.61 KB
/
CondensorMicDataAnalysis.m
File metadata and controls
60 lines (59 loc) · 2.61 KB
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
%________________________________________________________________________________________________________________________
% Written by Kevin L. Turner
% The Pennsylvania State University, Dept. of Biomedical Engineering
% https://github.com/KL-Turner
%________________________________________________________________________________________________________________________
%
% Purpose: Analyze voltage data from the condensor microphone to identify the relative strength of the hearing range
% frequencies. This is important as many laboratory animals can hear high-frequencies that we cannot.
%________________________________________________________________________________________________________________________
%
% Inputs: Run the code by hitting play. You will be prompted to select a single TDMS file, and then type in the
% the sampling rate to the command window.
%
% Outputs: One figure with three subplots. Raw data, Power spectrum of the entire signal, and the spectrogram of the
% power in each sound frequency as a function of time.
%
% Last Revised: April 24th, 2019
%________________________________________________________________________________________________________________________
clear; clc
audioFile = uigetfile('*.tdms','Multiselect','off');
% samplingRate = input('Input the sampling rate: '); disp(' ')
samplingRate = 300000;
[convertedData, ~] = ConvertTDMS_CM(0,audioFile);
audioData = detrend(convertedData.Data.MeasuredData.Data,'constant');
%% Parameters for spectral analysis
params.Fs = samplingRate;
params.tapers = [1,1]; % Tapers [n, 2n - 1]
params.pad = 1;
params.fpass = [2000,(samplingRate/2)]; % Pass band [0, nyquist] - mic isn't sensitive below 10 kHz
params.trialave = 1;
params.err = [2,0.05];
movingwin = [1,0.1];
disp('Running spectral analysis - This may take a moment.'); disp(' ')
[S_ps, f_ps, ~] = mtspectrumc_CM(audioData,params);
[S,t,f,~] = mtspecgramc_CM(audioData,movingwin,params);
% scaling for spectrogram - limits of caxis are mean of top/bottom 5% of points in spectrogram
cortBaseline = mean(S(1:30*10,:)',2);
normCortS = ((S' - cortBaseline)./cortBaseline).*100;
%% Summary figure(s)
figure('NumberTitle','off','Name','Condensor Microphone Audio');
subplot(2,1,1)
plot((1:length(audioData))/samplingRate,audioData,'k');
title('Raw audio (voltage) data')
xlabel('Time (sec)')
ylabel('Volts (v)')
subplot(2,1,2)
loglog(f_ps,S_ps,'k')
title('Power Spectrum')
xlabel('Frequency (Hz)')
xlim([2000,(samplingRate/2)])
ylabel('Power')
figure;
imagesc(t,f,normCortS)
title('Audio Spectrogram')
xlabel('Time (sec)')
ylabel('Frequency (Hz)')
axis xy
caxis([-100,100])
colorbar