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