I am looking to analyze sounds from a machine with a microphone connected to a DAQ board to collect data. The data is stored in an excel file and then I want to read that data in MATLAB and perform a FFT to see what frequencies are causing the greatest amplitude of noise. To test my system I fed some known frequencies into the DAQ through a function generator. However, when I feed a 400Hz signal from the function generator to the DAQ, collect the data, upload it into MATLAB and plot it, I do not see any tones at 400 Hz, only some at higher frequencies. Is this a problem with my code?
y = xlsread('TrialExcel400HzOscilloscope.xlsx');
y = detrend(y);
n = length(y);
Fs = 48000;
nfft = 4096;
Ts = 1/Fs;
t = 0:Ts:(n*Ts)-Ts;
numUniq = ceil((nfft+1)/2);
f = (0:numUniq-1)'*Fs/nfft;
figure(1)
hAx(1) = subplot(211);
hLine(1) = line('XData',t,'YData',nan(size(t)), 'Color','b', 'Parent', hAx(1));
xlim([0 0.05]);
ylim([-10 10]);
xlabel('Time (s)');
ylabel('Amplitude (Volts)');
title('Time Domain');
hAx(2) = subplot(212);
hLine(2) = line('XData', f, 'YData', nan(size(f)), 'Color', 'b', 'Parent', hAx(2));
grid
xlim([0 25000]);
ylim([0 80]);
xlabel('Frequency (Hz)');
ylabel('Magnitude (dB)');
title('Frequency Domain');
a = 20*log10(abs(fft(y,nfft)));
set(hLine(1), 'YData',y);
set(hLine(2), 'YData', a(1:numUniq));
n
? Is itlength(y)
? How does that compare tonfft
? Because what you are doing here is computing the DFT of the firstnfft
samples in your signal, not the firstnfft
frequencies in your signal. I would recommend settingnfft=length(y)
instead. – Cris Luengo