%Michael Battaglia
%Acoustics Project 2 Part 1a
%Modified from "tappered_onedimensionalpiston.m"

% You are required to set up a one-dimensional piston and plot its 
% beam pattern and particle displacement in the far field. 
% Select the piston parameters so that for frequencies between 
% 1 kHz and 5 kHz it produces a main lobe with maximum width equal 
% to 20o. Clearly state the selected piston parameters. 

clear all, close all
b=-1/2:(1/200):1/2;
bpi=b*pi;
l=1;
c=354;
f=1500;
lambda=c./f;
i=1;
    for j=1:length(bpi)
    p0(i,j)=sin(pi*(l/lambda(i))*sin(bpi(j)))/(pi*(l/lambda(i))*sin(bpi(j)));
    p1(i,j)=0.5*sin(pi*((l/lambda(i))*sin(bpi(j))+1))/(pi*((l/lambda(i))*sin(bpi(j))+1));
    p2(i,j)=0.5*sin(pi*((l/lambda(i))*sin(bpi(j))-1))/(pi*((l/lambda(i))*sin(bpi(j))-1));
    p=p0;
    q(i,j)=p0(i,j)+p1(i,j)+p2(i,j);
    end
    F=c./lambda(i);
    polar(bpi,abs(q(i,:)));
    title(['1-D piston beam pattern, f = ',num2str(F),' Hz, piston size = 1m'])
    % 
    figure(gcf)