Creating Frequency Modulated WAV File

Hi guys, I'm fairly new to matlab and I'm trying to create a wav file for an experiment I'm running. I want a 4KHz carrier frequency with a10 Hz modulator frequency which plays for 12 seconds. Based on what I've found online, this is the code i've been using:
clc
close all
clear
%set frequency
f=4000;
%create carrier tone
fs=44100; %sampling rate
d=12; %duration 12 seconds
n=fs*d; %total number of samples
t=(1:n)/fs; %total number of points
y=cos(2*pi*f*t); %function equation
%create modulator tone
fc=10; %rate of modulation
freqdev=40000; %frequency deviation
x=fmmod(y,fc,fs,freqdev);
%generate sound
sound(x,fs);
filename='AStim_4KHz_10Hz.wav';
audiowrite(filename,x,fs)
At the moment the output is just a chirp noise, doesn't sound correct at all. If anyone could point out where I'm going wrong that would be very much appreciated!

回答 (1 件)

Star Strider
Star Strider 2023 年 7 月 7 日

0 投票

I’m not certain what you want the result to be.
In situations like this, I plot it (using various methods) to see what the result is, soI know if the code is doing what I want.
That apporoach with your signal produces these results —
% clc
% close all
% clear
%set frequency
f=4000;
%create carrier tone
fs=44100; %sampling rate
d=12; %duration 12 seconds
n=fs*d; %total number of samples
t=(1:n).'/fs; %total number of points
y=cos(2*pi*f*t); %function equation
%create modulator tone
fc=10; %rate of modulation
freqdev=40000; %frequency deviation
x=fmmod(y,fc,fs,freqdev);
figure
plot(t, x)
grid
figure
pspectrum(x, fs)
figure
pspectrum(x, fs, 'spectrogram')
colormap(turbo)
% %generate sound
% sound(x,fs);
% filename='AStim_4KHz_10Hz.wav';
% audiowrite(filename,x,fs)
These require the Signal Processing Toolbox, that also has the modulate function that you can use to cross-check the Communications Toolbox results. (I don’t have the Commmunications Toolbox.)
.

カテゴリ

質問済み:

2023 年 7 月 7 日

回答済み:

2023 年 7 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by