我有一个程序,它使用 surf 函数将在 NI USB DAQ 中获得的数据实时绘制到频谱图上。我想使用某种窗口函数来改善绘图的外观。我的问题是:哪个窗口函数最适合用于此?以及如何实施?这是我当前代码的示例:
fprintf('Initializing DAQ\n');
s = daq.createSession ('ni');
addAnalogInputChannel(s, 'Dev1','ai1', 'Voltage');
s.NumberOfScans = Fs*Record_Time;
s.Rate = Fs;
s.Channels.Range = [-1 1];
s.DurationInSeconds = 5;
Spect_nFFT = 2^8;
num_overlap = 19*round(Spect_nFFT/20);
start_sample = 1;
DataRdy = true;
% Run in background session
Lh = s.addlistener('DataAvailable', @(src,event) CaptureData(event.TimeStamps, event.Data));
s.NotifyWhenDataAvailableExceeds = 100000*.1;
s.IsContinuous = true;
s.startBackground();
NFFT = 2^nextpow2(L);
P = zeros(8193,50);
F = Fs/2*linspace(0,1,NFFT/2+1);
g=0;
while g==0
while DataRdy == 0
pause(.01)
end
pause(.5)
Min_Threshold = 10^12;
start_sample = 1;
NFFT = 2^nextpow2(L); % Next power of 2 from length of myRecording
FFT_Out = fft(myRecording(start_sample:end),NFFT)/size(myRecording(start_sample:end),1);
FFT_Out = FFT_Out(1:NFFT/2+1);
A = sqrt(FFT_Out.*conj(FFT_Out));
P = [P(:,2:end), sqrt(FFT_Out.*conj(FFT_Out))];
P(P<=max(max(P))/Min_Threshold)=max(max(P))/Min_Threshold;
surf(1:size(P,2),F,10*log10(P),'edgecolor','none'); axis tight;
% Create updating spectrogram
view(0,90);
xlabel('Time');
ylabel('Hz');
drawnow;
DataRdy = 0;
uicontrol('Style', 'pushbutton', 'String', 'Exit',...
'Position', [20 20 50 20],...
'Callback', 'g=g+1');
end
delete(Lh);
stop(s);
谢谢你的帮助!
