Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6130925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:54:53+00:00 2026-05-23T16:54:53+00:00

i am trying to make a spectrogram in matlab, here is my code: %

  • 0

i am trying to make a spectrogram in matlab,
here is my code:

% Record your voice for 100 seconds.
recObj = audiorecorder;
disp('Start speaking.')
recordblocking(recObj, 100);

% Store data in double-precision array.
my= getaudiodata(recObj);
figure;
specgram(my,512);

problem is that while i am speaking i want the spectrogram to be shown, so it should be updating as i speak. How can i plot the spectrogram while the audio is coming from microphone? so i should be able to see spectrogram in real time

I also tried this

% Record your voice for 100 seconds.
recObj = audiorecorder;
disp('Start speaking.')
a=0;
figure;
while a<60
    recordblocking(recObj, 100);

    % Store data in double-precision array.
    my= getaudiodata(recObj);

    specgram(my,512);
    a=a+1;
end

but it will only display the spectrogram when the while loop fishes (so after running 60 times)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:54:54+00:00Added an answer on May 23, 2026 at 4:54 pm

    Here is one possible implementation. The main problem was that you forget to call DRAWNOW at the end of each loop:

    Fs = 8000;                    %# sampling frequency in Hz
    T = 1;                        %# length of one interval signal in sec
    t = 0:1/Fs:T-1/Fs;            %# time vector
    nfft = 2^nextpow2(Fs);        %# n-point DFT
    numUniq = ceil((nfft+1)/2);   %# half point
    f = (0:numUniq-1)'*Fs/nfft;   %'# frequency vector (one sided)
    
    %# prepare plots
    figure
    hAx(1) = subplot(211);
    hLine(1) = line('XData',t, 'YData',nan(size(t)), 'Color','b', 'Parent',hAx(1));
    xlabel('Time (s)'), ylabel('Amplitude')
    hAx(2) = subplot(212);
    hLine(2) = line('XData',f, 'YData',nan(size(f)), 'Color','b', 'Parent',hAx(2));
    xlabel('Frequency (Hz)'), ylabel('Magnitude (dB)')
    set(hAx, 'Box','on', 'XGrid','on', 'YGrid','on')
    %#specgram(sig, nfft, Fs);
    
    %# prepare audio recording
    recObj = audiorecorder(Fs,8,1);
    
    %# Record for 10 intervals of 1sec each
    disp('Start speaking...')
    for i=1:10
        recordblocking(recObj, T);
    
        %# get data and compute FFT
        sig = getaudiodata(recObj);
        fftMag = 20*log10( abs(fft(sig,nfft)) );
    
        %# update plots
        set(hLine(1), 'YData',sig)
        set(hLine(2), 'YData',fftMag(1:numUniq))
        title(hAx(1), num2str(i,'Interval = %d'))
        drawnow                   %# force MATLAB to flush any queued displays
    end
    disp('Done.')
    

    screenshot

    I simply display the frequency components in each iteration. You should be able to modify that to show the spectrogram if you want…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to make a simple jquery drop down here, here's my code so far:
Trying to make some small changes to Apache's Velocity engine. Here's what I can
I´m trying to make something similar to the downloads panel of Transmission BT (here
I'm trying make Ethos framework on Mac OS Lion. git://git.dronelabs.com/ethos Here result of ./configure:
I am trying make long screen to vertical direction. So, I need a screen
Trying to make a make generic select control that I can dynamically add elements
Trying to make a MySQL-based application support MS SQL, I ran into the following
Trying to make a generic PL/SQL procedure to export data in specific XML format,
Trying to make a web service call to an HTTPS endpoint in my Silverlight
Trying to make a custom :confirm message for a rails form that returns data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.