Hi, I wrote this code to obtain plot of frequency spectrum of my signals:
clc; clear all; close all;%%Reading & plotting normal.wav file
normal = audioread('normal.wav');figure(1)plot(normal);xlabel('Number of data','fontsize',12,'fontweight','b');ylabel('Amplitude','fontsize',12,'fontweight','b');title('Normal Heart Sound Signal','fontsize',14,'fontweight','b');%%Reading & plotting murmur.wav file
murmur = audioread('murmur.wav');figure(2)plot(murmur);xlabel('Number of data','fontsize',12,'fontweight','b');ylabel('Amplitude','fontsize',12,'fontweight','b');title('Murmur Heart Sound Signal','fontsize',14,'fontweight','b');%%Fourier transform
fft_nor = fft(normal);fft_mur = fft(murmur);%%Calculating fs
% fs_normal
t_nor = 6; % s
N_nor = length(normal);fs_nor = N_nor / t_nor; % Hz
% fs_murmur
t_mur = 8; % s
N_mur = length(murmur);fs_mur = N_mur / t_mur; % Hz%%Calculate the frequency axis
f_nor = fs_nor / 2 * linspace(-1,1,fs_nor);f_mur = fs_mur / 2 * linspace(-1,1,fs_mur);%%Plotting frequency spectrum
% Normal sound
figure(3)plot(f_nor, abs(fft_nor));xlabel('Frequency (Hz)','fontsize',12,'fontweight','b');ylabel('Magnitude','fontsize',12,'fontweight','b');title('Magnitude FFT Of Normal Signal','fontsize',14,'fontweight','b'); % Murmur sound
figure(4)plot(f_mur, abs(fft_mur));xlabel('Frequency (Hz)','fontsize',12,'fontweight','b');ylabel('Magnitude','fontsize',12,'fontweight','b');title('Magnitude FFT Of Murmur Signal','fontsize',14,'fontweight','b');
but after running it I have this error:
Error using plot Vectors must be the same lengths.
Error in Q5b (line 40) plot(f_nor, abs(fft_nor));
would anyone help me to fix it?
Best Answer