-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfftpoint_cpx3.m
48 lines (48 loc) · 1.93 KB
/
fftpoint_cpx3.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
function [output] = fftpoint_cpx3(timedomainsignal,samplingrate,frequency)
%[RESPONSE,PHASE] = fftpoint(TIMEDOMAINSIGNAL,SAMPLINGRATE,FREQUENCY)
% Magnitude and phase from FFT of time domain waveform (sinusoid) at
% particular Frequency. Returns frequency domain
% content of a sampled TIMEDOMAINSIGNAL at the specified
% FREQUENCY. Only positive frequencies are returned. Voltages are
% preserved. If TIMEDOMAINSIGNAL is a matrix, then each column must
% represent a different waveform.
%
% RESPONSE is a vector whose whose values are the zero to peak values
% that correspond with the frequency. Each column represents a different
% waveform.
%
% PHASE is a vector whose value correspond to phase of the signal in
% radians for the frequency in FREQUENCY. Each column represents a
% different waveform.
%
%freqresponse.m
%Created by Brian Miller. Documented 8/8/2003 by Brian Miller
freqdomainsignal = fft(timedomainsignal);
[len, col] = size(freqdomainsignal);
% Multiply by 2 and divide by the number of points in the vector to get the
% magnitude
mag = (2*freqdomainsignal)/len;
mag = mag(1:length(mag)/2,:);
spacing = (samplingrate)./len; % Frequency bin spacing
index = (frequency./spacing)+1; % Index that corresponds to correct frequency bin.
if index ~= round(index)
%if abs(index - round(index)) > 0.00001
fprintf('WARNING! Frequency rounded from %f to %f match an FFT bin.\n',...
frequency,(round(index)-1)*spacing);
index = round(index);
end
index = int32(index);
for count = 1:col
output(count) = freqdomainsignal(index,count);
% imageinerry(count) = imag(freqdomainsignal(index,count));
% f = daqfft(timedomainsignal(:,count),samplingrate);
% hold on;
% plot(frequencies(count),response(count),'ro');
end
% keyboard;
% freqresponse = semilogx(frequencies,response);
% set(freqresponse,'LineWidth',3);
% xlabel('Frequency(Hz)');
% ylabel('Peak Voltage');
% title('Frequency Response');
% grid on;