Search code examples
matlabaudioringtone

generating diffrent tone in a time interval in matlab


how to generate continuous tone with below conditions as i only able to create the tone from time 0 to 1. Ho to continuous generate it? Create a 3 second signal containing three tones; Tone 220 Hz for 0 < t < 1 Tone 300 Hz for 1 < t < 2 Tone 440 Hz for 2 < t < 3 using s=sin(2*pi*t) and sampling frequency of 8192 Hz

Fs = 8192;
T = 1/Fs;                                             

t = 0:T:1;
t1=1:T:2;
t2=2:T:3;
y = sin(2*pi*200*t); 
hold on;
y = sin(2*pi*300*t1);
hold on;
y = sin(2*pi*440*t2); 
hold on;                         
plot(t,y);           
xlabel('t');                              
ylabel('Amplitude');                       

Thanks


Solution

  • do you mean this?

    Fs = 8192;
    T = 1/Fs;                                             
    
    t1 = 0:T:1;
    t2=1:T:2;
    t3=2:T:3;
    y1 = sin(2*pi*200*t); 
    y2 = sin(2*pi*300*t1);
    y3 = sin(2*pi*440*t2);                          
    plot(t1,y1,t2,y2,t3,y3);           
    xlabel('t');                              
    ylabel('Amplitude'); 
    

    If so, and you want the data to be in two arrays do the next also

    t=horzcat(t1,t2,t3);
    y=horzcat(y1,y2,y3);
    

    I am not 100% sure if this is what you want, if not, please correct me