-1

The following Matlab code generate a sound but it contain tak tak like sound which can be easily heard.Can someone removes this noise by using envelope function.

  Fs=44100;
  T=1/Fs;
  M=zeros(1,88);
  for I=7:88
    M(I)=round(36.8*(2^(1/12))^(I-6));
    end
    signal=[];
    FrTm=[50,3;50,3;52,3;54,3;50,3;54,3;52,3;45,3;50,3;50,3;52,3;54,3;50,6;
    49,3;1,3;50,3;50,3;52,3;54,3;55,3;54,3;52,3;50,3;49,3;45,3;47,3;49,3;50,6;
    50,3;1,3;47,5;49,1;47,3;45,3;47,3;49,3;50,3;1,3;45,5;47,1;45,3;43,3;42,6;
    45,3;1,3;47,5;49,1;47,3;45,3;47,3;49,3;50,3;47,3;45,3;50,3;49,3;52,3;50,6;
    50,6];
    for i=1:length(FrTm)
      x=FrTm(i,1);
      y=FrTm(i,2);
      F=M(x);
      time=0:1/Fs:y/18;
      sinewave=*sin(2*pi*10*F*time);

      signal=[signal sinewave];

     end

     stem(signal)
     sound(signal,Fs)

1 Answers1

1

Here are two possible solutions. They are not perfect since the tak-tak is still here but it is much lower.

  1. Applying a high-pass filter to remove the annoying sound which seems to be low frequency

    Fs=44100;
    T=1/Fs;
    M=zeros(1,88);
    for I=7:88
        M(I)=round(36.8*(2^(1/12))^(I-6));
    end
    signal=[];
    FrTm=[50,3;50,3;52,3;54,3;50,3;54,3;52,3;45,3;50,3;50,3;52,3;54,3;50,6;
    49,3;1,3;50,3;50,3;52,3;54,3;55,3;54,3;52,3;50,3;49,3;45,3;47,3;49,3;50,6;
    50,3;1,3;47,5;49,1;47,3;45,3;47,3;49,3;50,3;1,3;45,5;47,1;45,3;43,3;42,6;
    45,3;1,3;47,5;49,1;47,3;45,3;47,3;49,3;50,3;47,3;45,3;50,3;49,3;52,3;50,6;
    50,6];
    for i=1:length(FrTm)
        x=FrTm(i,1);
        y=FrTm(i,2);
        F=M(x)/4;
        time=0:1/Fs:y/18;
        sinewave=sin(2*pi*10*F*time);
    
        signal=[signal sinewave];
    
    end
    
    % Creating high-pass filter with passband frequency of 1000 Hz (may be too high)
    hpFilt = designfilt('highpassiir','FilterOrder',8, ...
        'PassbandFrequency',1000,'PassbandRipple',0.2, ...
    'SampleRate',Fs);
    % Filtering sound
    signal = filter(hpFilt,signal);
    
    sound(signal,Fs)
    
  2. Taking the last value from each generated sine wave and finding the corresponding phase for the next sine wave, to make the sinus as continuous as possible

     Fs=44100;
     T=1/Fs;
     M=zeros(1,88);
     for I=7:88
         M(I)=round(36.8*(2^(1/12))^(I-6));
     end
     signal=[];
     FrTm=[50,3;50,3;52,3;54,3;50,3;54,3;52,3;45,3;50,3;50,3;52,3;54,3;50,6;
       49,3;1,3;50,3;50,3;52,3;54,3;55,3;54,3;52,3;50,3;49,3;45,3;47,3;49,3;50,6;
    50,3;1,3;47,5;49,1;47,3;45,3;47,3;49,3;50,3;1,3;45,5;47,1;45,3;43,3;42,6;
    45,3;1,3;47,5;49,1;47,3;45,3;47,3;49,3;50,3;47,3;45,3;50,3;49,3;52,3;50,6;
    50,6];
     previous_end_val = 0;
     for i=1:length(FrTm)
         x=FrTm(i,1);
         y=FrTm(i,2);
         F=M(x)/4;
         time=0:1/Fs:y/18;
    
         % Calculating required phase to match the end of previous sinewave
         phi = asin(previous_end_val);
         % Generating sinewave with phase phi
         sinewave=sin(2*pi*10*F*time + phi);
         previous_end_val = sinewave(end);
    
         signal=[signal sinewave];
    
     end
    
     sound(signal,Fs)
    

The first solution is not perfect: if you take too high passband frequency you could not hear the lowest audible frequencies. The second solution is faster and more elegant. Please ask if there is a method you don't understand.

Benjamin Barrois
  • 2,566
  • 13
  • 30
  • And please don't forget to upvote and select this solution as answering the question. – Benjamin Barrois Jan 29 '18 at 18:11
  • Thank you so much the second solution is nearer.so what if i simply multiply 2*sin(2*pi*F*time) or add Pi+sin(2*pi*F*time)? actually applying these two completely remove tak tak or noise.By the way thank you so much i think it was problem of low frequencies. – Tayyab Khan Shinwari Jan 29 '18 at 18:41
  • You are right, actually I am reading that sound should take preferably integers. Don't multiply your signal, but simply run at the end: `sound(round((2^8)*signal),Fs,8)`. You will have a gameboy 8-bit sound with no tak-tak. – Benjamin Barrois Jan 29 '18 at 18:50
  • i am hearing no sound at all.It say error at column 1 – Tayyab Khan Shinwari Jan 30 '18 at 02:11
  • It works for me. If you just take my last script and replace only the sound function it works. What is your version of Matlab? – Benjamin Barrois Jan 30 '18 at 09:03