how to redefine function as imported audio when plotting a frequency spectrum
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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
- 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);
0 Commenti
Risposte (1)
Sai Kiran
il 23 Dic 2022
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!
0 Commenti
Vedere anche
Categorie
Scopri di più su Audio and Video Data in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!