Lab Report 5sound

download Lab Report 5sound

of 5

Transcript of Lab Report 5sound

  • 8/17/2019 Lab Report 5sound

    1/5

    SOUND

    1

    MATLAB CODE

    clc[soundsig,fs]=audioread('C:\Users\Awais\Documents\MATLAB\road.wav');

    left=soundsig(:,1);right=soundsig(:,2);L=length(left);reverse=flipud(left);sound(soundsig,fs);% Plot the waveform. subplot(211)plot(soundsig),grid;xlabel('time','fontsize',16)ylabel('amplitude','fontsize',16)title('sound signal')

    subplot(212)plot(reverse),grid;xlabel('time','fontsize',16)ylabel('amplitude','fontsize',16)title('sound signal in reverse')

  • 8/17/2019 Lab Report 5sound

    2/5

    SOUND

    2

    GRAPH

    Down Sampling

    MATLAB CODE

    clc[soundsig,fs]=audioread('C:\Users\Awais\Documents\MATLAB\road.wav');

    left=soundsig(:,1);right=soundsig(:,2);L=length(left);reverse=flipud(left);sound(soundsig,0.5*fs);

  • 8/17/2019 Lab Report 5sound

    3/5

    SOUND

    3

    Up Sampling

    MATLAB CODE

    clc[soundsig,fs]=audioread('C:\Users\Awais\Documents\MATLAB\road.wav');left=soundsig(:,1);right=soundsig(:,2);L=length(left);reverse=flipud(left);sound(soundsig,2*fs);

    Echo

    MATLAB CODE

    clcattn=0.9;td=1;[signal,fs]=audioread('C:\Users\Awais\Documents\MATLAB\road.wav');

    [signal,echo,ref]=echo11(signal,fs,td,attn);sound(signal,fs);sound(echo,fs);

    % Plot the waveform. subplot(211)plot(signal),grid;xlabel('time','fontsize',16)ylabel('amplitude','fontsize',16)title('sound signal')

    subplot(212)plot(echo),grid;

    xlabel('time','fontsize',16)ylabel('amplitude','fontsize',16)title('echo sound')

    %Function file function[sigx,echosig,reflectedsig]=echo11(sig,fs,td,attn)zer=zeros(td*fs,2);sigx=[sig;zer];

  • 8/17/2019 Lab Report 5sound

    4/5

    SOUND

    4

    reflectedsig=[zer;sig*attn];echosig=sigx+reflectedsig;

    GRAPH

  • 8/17/2019 Lab Report 5sound

    5/5

    SOUND

    5

    MATLAB CODE

    clc% Create WAV file in current folder. load handel.mat 

    hfile = 'handel.wav';wavwrite(y, Fs, hfile)clear y Fs 

    % Read the data back into MATLAB, and listen to audio. [y, Fs, nbits, readinfo] = wavread(hfile);sound(y, Fs);

    % Pause before next read and playback operation. duration = numel(y) / Fs;

    pause(duration + 2)

    % Read and play only the first 2 seconds. nsamples = 2 * Fs;[y2, Fs] = wavread(hfile, nsamples);sound(y2, Fs);pause(4)

    % Read and play the middle third of the file. sizeinfo = wavread(hfile, 'size');

    tot_samples = sizeinfo(1);startpos = tot_samples / 3;endpos = 2 * startpos;

    [y3, Fs] = wavread(hfile, [startpos endpos]);sound(y3, Fs);