【发布时间】:2018-11-15 08:01:24
【问题描述】:
我在下面编写了一个简单的 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)
【问题讨论】:
-
如果您使用一些标签更新您的帖子来解释您正在使用哪种语言,并使用您为该语言使用的框架/库/API 更新您的帖子,这将会很有帮助。在没有这些知识的情况下:您需要一个缓冲区来执行任何 DSP,一种常见的方法是将样本存储在长度为 X 的缓冲区中,完成您的工作,将其清空并用新样本填充它。一些库会为您完成缓冲区工作,您所需要做的就是编写必须在每个时间片上运行的代码。
-
MPK - 我根据您的建议更新了我的帖子。谢谢。 JF
标签: matlab filtering signal-processing audio-streaming