How can I generate a sine wave with different frequencies using matlab?

给你一囗甜甜゛ 提交于 2019-12-04 17:43:14
ederwander

OK another example: to generate 5 randon frequencies :-)

%range of possibles frequencies
FrequenciesRandon = [200:1:500];

%number of randon frequencies ??
nf = 5;

EndSignal=[];

for j = 1 : nf
    t  = [ 0 : 1 : 10000];           % Time Samples
    f=randsample(FrequenciesRandon,1); % get the randon frequencie
    Fs = 44100;                     % Sampling Frequency
    data = sin(2*pi*f/Fs*t)';        % Generate Sine Wave
    EndSignal= [data;EndSignal];    
end

wavplay(EndSignal,Fs) 

Hello I know of no ready function to do this in matlab, but do it in matlab is quite simple, a simple example of how to generate 10 000 samples in 450Hz

t  = [ 0 : 1 : 10000];           % Time Samples
f  = 450;                       % Input Signal Frequency
Fs = 44100;                     % Sampling Frequency
data = sin(2*pi*f/Fs*t)';        % Generate Sine Wave
wavplay(data,Fs)                 %to Listen
Kyung Seo Ki

Here is an example for different sequential frequencies.

% Generate a sequencial sinusoid
fs = 8000;                                        % sampling rate
amp = 1;                                          % amplitude
freqs = [262, 294, 330, 350, 392, 440, 494, 523]; % frequency in Hz
T = 1/fs;                                         % sampling period
dur = 0.5;                                        % duration in seconds
phi = 0;                                          % phase in radian
y = [];

for k = 1:size(freqs,2)
    x = amp*sin(2*pi*freqs(k)*[0:T:dur-T]+phi);
    y = horzcat(y,x);
end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!