How do i extract a few seconds from a given audio file?

P
Prashant Ram S · Dec 16, 2022 · 2K views
Question
I want to extract the first 0.5 seconds of an audio file and make that portion of the signal as 0. I read the audio file and plotted it successfully but I'm having trouble figuring out how to extract the first 0.5 seconds. Should I use a loop? My code so far, is given below.   [x,fs]= audioread('C:\Users\prashantram.s\Desktop\hello.wav'); [m,n]=size(x); dt=1/fs; t=dt*(0:m-1); figure(1); plot(t,x);  
Expert Answer
Profile picture of Kshitij Singh
Kshitij Singh PhD Expert
Answered Aug 12, 2026
idx = t<0.5 ;
x = x(idx) ;

 

100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!