필터 지우기
필터 지우기

how to redefine function as imported audio when plotting a frequency spectrum

조회 수: 1 (최근 30일)
carly
carly 2022년 12월 4일
답변: Sai Kiran 2022년 12월 23일
im making a function where the user inputs an audio vector and the frequency spectrum gets plotted.
input1 = an array consisting of the signal that will be plotted, or the filename of an audio file.
sampleRate = asks user to input a sampleRate
input3 = makes a plot
  1. if the user inputs the filename of an audio file, how can i redefine input1 as the audio from the file and instead not a given array?
this is what i have
function [output] = mainfreq(input1, sampleRate, input3)
if strcmpi(input1, '.wav')
input1 = audioread(input1);

답변 (1개)

Sai Kiran
Sai Kiran 2022년 12월 23일
Hi,
To read the audio data from a file and assign it to the 'input1' variable, you can use the 'audioread' function. This function takes the filename of the audio file as input and returns the audio data and the sample rate as output.
Here is how you can modify your code to read the audio data from a file and assign it to the 'input1' variable
function [output] = mainfreq(input1, sampleRate, input3)
if ischar(input1)
[input1, sampleRate] = audioread(input1);
end
This code checks if the 'input1' variable is a string (i.e., if it is the filename of an audio file). If it is a string, it reads the audio data from the file using audioread and assigns it to the input1 variable. The sample rate is also read from the file and assigned to the 'sampleRate' variable.
I hope this helps!

카테고리

Help CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by