简体   繁体   中英

Playing a varying frequency in Hertz in matlab?

I have some matlab code which produces frequency (in hertz) of a sound over 5 seconds. The code as it stands outputs 100 samples per second, and I want to play the 5 second block to see what this sounds like, but I'm having issues with sampling rate and sound / soundsc commands.

My frequency oscillates (data here ) and I'd be very grateful if someone could help me convert this data into some kind of real-time approximation of what it should sound like.

在此处输入图片说明

Something like this may be helpful

Fs=2000; %sample rate, Hz
t=0:1/Fs:5; %time vector
F=298+sin(2*pi*t);  %put your own F here

S=sin(2*pi*F.*t);  %here is the sound vector

%visual check
figure(1);
plot(t,S)
figure(2);
plot(t,F)

%listen
wavplay(S,Fs)

This is like FM modulation, but different. If you have an Fold vector with a different sample rate, you can convert it with the command

F=interp1(told,Fold,t);  %told and Fold are F at a different sample rate 
%check it
plot(told,Fold,t,F)

First, your sampling rate should be at least twice the maximum frequency according the Nyquist–Shannon sampling theorem.

Next, you need to generate a sinusoid:

Signal = sin(2*pi*Phi);

where Phi is the phase corresponding to the desired frequency pattern, which is simply an integral of the frequency (which you can do numerically or analytically).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM