我在下面写了一个简单的MATLAB程序,用于解调之前用载波频率为10000 Hz进行频率调制的音频信号。程序记录频率调制信号,将其存储在光盘上(以备后续使用),然后检索并解调。现在,我希望能够在信号流入时连续解调(和显示)信号,而无需先存储信号。有关如何修改下面的MATLAB代码的任何建议?
% FM Demodulate an Audio File June 5, 2018
%% Record the previously frequency-modulated signal for a few seconds.
Fs = 44100; % Sample frequency of the sound wave
duration = 5; % Duration of recording in seconds
recObj = audiorecorder(Fs,16,1); % Sets up the recording conditions
pause(4) % Pause before recording
disp('Start recording.')
recordblocking(recObj,duration);
disp('End of recording.');
%% Store data in double-precision array.
filename = 'RecordedWave.wav';
myRecording = getaudiodata(recObj);
Fs = get(recObj, 'SampleRate');
audiowrite(filename,myRecording,Fs) % Writes the y and Fs as a .wav file
%% Read it back into memory
[y,Fs] = audioread(filename);
% The above statement reads the stored .wav file and loads the y vector
% as well as the stored value of Fs for that .wav file.
%% Demodulate the recorded high-frequency FM sound signal
z = demod(y,10000,44100,'fm');
%% Make and then apply a bandpass filter
filterOrder = 2;
fcutlow = 2;
fcuthigh= 10;
[b,a] = butter(filterOrder,[fcutlow,fcuthigh]/(Fs/2),'bandpass');
z_filtered = filter(b,a,z); % Apply the bandpass filter
%% Plot the demodulated and filtered signal
figure
t_sec = (0:1/Fs:duration-1/Fs); % here is the vector of time
plot(t_sec,z_filtered)
答案 0 :(得分:0)
您需要使用audioDeviceReader和audioDeviceWriter对象,这些对象使您可以分块获取数据和回放数据。这样,如果您的算法足够快,您就可以实时进行处理。