can anybody help me turn this into real-time (max 1 second delay) continuous stream of input process output?
Show older comments
fs = 40000; % sampling rate fnyquist = fs/2; % Nyquist frequency duration = 256/40000 % time length of audio signal
recObj = audiorecorder(fs, 16, 1); % recObj is an audiorecorder with fs sampling rate, 16-bit depth and 1 (mono) channel % Record your voice for duration seconds disp('Start speaking.'); recordblocking(recObj, duration); disp('End of Recording.'); % play(recObj); % Recording playback y = getaudiodata(recObj); % Store data in double-precision array, y
% Frequency modulation fc = 10010; % Carrier frequency y = y(:); % ??? integratedy = cumsum( y ) / fs; % calculating integral of part of input signal Am = max(y); % calculating input max min amplitude t = ( 0 : numel( y ) - 1 )' / fs; % declare input's time axis dev = 9990; % Frequency deviation in modulated signal mody = Am*cos( 2 * pi * ( fc * t + dev * integratedy )); % Modulate. demody = fmdemod(mody,fc,fs,dev); % MATLAB built-in FM demodulation feature.
%% PLOTTING SECTION
subplot(3,2,1); % Plot the input audio samples (show time-domain demodulated signal) plot(y); xlabel('time by sample'); ylabel('Magnitude'); title('Time-domain input signal plot'); axis tight;
% Input signal frequency spectrum plotting: N = length(y); Y = abs(fft(y)); bin_vals = [0 : N-1]; fax_Hz = bin_vals*fs/N; N_2 = ceil(N/2); subplot(3,2,2); plot(fax_Hz(1:N_2), Y(1:N_2)); xlabel('Frequency (Hz)'); ylabel('Magnitude'); title('Single-sided Input signal magnitude spectrum (Hertz)'); axis tight;
subplot(3,2,3); % Show time-domain modulated signal plot(mody); xlabel('time by sample'); ylabel('Magnitude'); title('Time-domain modulated signal plot'); % axis tight;
% Modulated signal frequency spectrum plotting: N = length(mody); modY = abs(fft(mody)); bin_vals = [0 : N-1]; fax_Hz = bin_vals*fs/N; N_2 = ceil(N/2); subplot(3,2,4); plot(fax_Hz(1:N_2), modY(1:N_2)); xlabel('Frequency (Hz)'); ylabel('Magnitude'); title('Single-sided Frequency modulated input magnitude spectrum (Hertz)'); axis tight;
subplot(3,2,5); % Show time-domain demodulated signal plot(demody); xlabel('time by sample'); ylabel('Magnitude'); title('Time-domain demodulated signal plot'); axis tight;
% Demodulated signal frequency spectrum plotting: N = length(demody); demodY = abs(fft(demody)); bin_vals = [0 : N-1]; fax_Hz = bin_vals*fs/N; N_2 = ceil(N/2); subplot(3,2,6); plot(fax_Hz(1:N_2), demodY(1:N_2)); xlabel('Frequency (Hz)'); ylabel('Magnitude'); title('Single-sided Frequency demodulated input magnitude spectrum (Hertz)'); axis tight;
so when i run this, i can give input and hear the output in real-time, there is no much demand in the delay as long as this is done entirely in *.m files (no simulink or other).
Answers (0)
Categories
Find more on PHY Components in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!